Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ module Assets
class ImportmapGenerator < Rails::Generators::Base
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 5.3'), desc: "Set the generated app's bootstrap version"

# This could be skipped if you want to use webpacker
def add_javascript_dependencies
gem 'bootstrap', options[:'bootstrap-version'].presence # in rails 7, only for stylesheets
end

def import_javascript_assets
append_to_file 'config/importmap.rb' do
<<~CONTENT
Expand Down Expand Up @@ -45,27 +40,41 @@ def append_blacklight_javascript
end

def add_stylesheet
if File.exist? 'app/assets/stylesheets/application.bootstrap.scss'
if ENV['CI']
run "yarn add file:#{Blacklight::Engine.root}"
else
run "yarn add blacklight-frontend@#{Blacklight::VERSION}"
end
unless used_bootstrap_css?
generate_with_sassc_rails
return
end

append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
CONTENT
end
if ENV['CI']
run "yarn add file:#{Blacklight::Engine.root}"
else
gem "sassc-rails", "~> 2.1"
run "yarn add blacklight-frontend@#{Blacklight::VERSION}"
end

create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
end
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
CONTENT
end
end

private

# Did they generate the rails app with `--css bootstrap' ?
def used_bootstrap_css?
File.exist? 'app/assets/stylesheets/application.bootstrap.scss'
end

def generate_with_sassc_rails
gem "sassc-rails", "~> 2.1"
# This could be skipped if you want to use shakapacker or cssbunding-rails
gem 'bootstrap', options[:'bootstrap-version'].presence

create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
end
end
end
Expand Down