Skip to content

Commit da60832

Browse files
authored
Merge pull request #3363 from projectblacklight/sass_bootstrap
Don't install the bootstrap gem unless they are using sassc
2 parents 5ba3108 + e436d71 commit da60832

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

lib/generators/blacklight/assets/importmap_generator.rb

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ module Assets
55
class ImportmapGenerator < Rails::Generators::Base
66
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 5.3'), desc: "Set the generated app's bootstrap version"
77

8-
# This could be skipped if you want to use webpacker
9-
def add_javascript_dependencies
10-
gem 'bootstrap', options[:'bootstrap-version'].presence # in rails 7, only for stylesheets
11-
end
12-
138
def import_javascript_assets
149
append_to_file 'config/importmap.rb' do
1510
<<~CONTENT
@@ -45,27 +40,41 @@ def append_blacklight_javascript
4540
end
4641

4742
def add_stylesheet
48-
if File.exist? 'app/assets/stylesheets/application.bootstrap.scss'
49-
if ENV['CI']
50-
run "yarn add file:#{Blacklight::Engine.root}"
51-
else
52-
run "yarn add blacklight-frontend@#{Blacklight::VERSION}"
53-
end
43+
unless used_bootstrap_css?
44+
generate_with_sassc_rails
45+
return
46+
end
5447

55-
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
56-
<<~CONTENT
57-
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
58-
CONTENT
59-
end
48+
if ENV['CI']
49+
run "yarn add file:#{Blacklight::Engine.root}"
6050
else
61-
gem "sassc-rails", "~> 2.1"
51+
run "yarn add blacklight-frontend@#{Blacklight::VERSION}"
52+
end
6253

63-
create_file 'app/assets/stylesheets/blacklight.scss' do
64-
<<~CONTENT
65-
@import 'bootstrap';
66-
@import 'blacklight/blacklight';
67-
CONTENT
68-
end
54+
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
55+
<<~CONTENT
56+
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
57+
CONTENT
58+
end
59+
end
60+
61+
private
62+
63+
# Did they generate the rails app with `--css bootstrap' ?
64+
def used_bootstrap_css?
65+
File.exist? 'app/assets/stylesheets/application.bootstrap.scss'
66+
end
67+
68+
def generate_with_sassc_rails
69+
gem "sassc-rails", "~> 2.1"
70+
# This could be skipped if you want to use shakapacker or cssbunding-rails
71+
gem 'bootstrap', options[:'bootstrap-version'].presence
72+
73+
create_file 'app/assets/stylesheets/blacklight.scss' do
74+
<<~CONTENT
75+
@import 'bootstrap';
76+
@import 'blacklight/blacklight';
77+
CONTENT
6978
end
7079
end
7180
end

0 commit comments

Comments
 (0)