@@ -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,38 @@ 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+ return generate_with_sassc_rails unless used_bootstrap_css?
5444
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
45+ if ENV [ 'CI' ]
46+ run "yarn add file:#{ Blacklight ::Engine . root } "
6047 else
61- gem "sassc-rails" , "~> 2.1"
48+ run "yarn add blacklight-frontend@#{ Blacklight ::VERSION } "
49+ end
50+
51+ append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
52+ <<~CONTENT
53+ @import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
54+ CONTENT
55+ end
56+ end
57+
58+ private
59+
60+ # Did they generate the rails app with `--css bootstrap' ?
61+ def used_bootstrap_css?
62+ File . exist? 'app/assets/stylesheets/application.bootstrap.scss'
63+ end
6264
63- create_file 'app/assets/stylesheets/blacklight.scss' do
64- <<~CONTENT
65- @import 'bootstrap';
66- @import 'blacklight/blacklight';
67- CONTENT
68- end
65+ def generate_with_sassc_rails
66+ gem "sassc-rails" , "~> 2.1"
67+ # This could be skipped if you want to use shakapacker or cssbunding-rails
68+ gem 'bootstrap' , options [ :'bootstrap-version' ] . presence
69+
70+ create_file 'app/assets/stylesheets/blacklight.scss' do
71+ <<~CONTENT
72+ @import 'bootstrap';
73+ @import 'blacklight/blacklight';
74+ CONTENT
6975 end
7076 end
7177 end
0 commit comments