Skip to content

Commit

Permalink
Update generators
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 21, 2024
1 parent c19aa18 commit 15293e9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
2 changes: 2 additions & 0 deletions app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<%= opensearch_description_tag application_name, opensearch_catalog_url(format: 'xml') %>
<%= favicon_link_tag %>
<%= stylesheet_link_tag "application", media: "all", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" unless defined? Propshaft %>

<% if defined? Importmap %>
<%= javascript_importmap_tags %>
<% elsif defined? Propshaft %>
Expand Down
48 changes: 13 additions & 35 deletions lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def import_javascript_assets
<<~CONTENT
pin "@github/auto-complete-element", to: "https://cdn.skypack.dev/@github/auto-complete-element"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/[email protected]/dist/umd/popper.min.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.3.2'}/dist/js/bootstrap.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.3.3'}/dist/js/bootstrap.js"
CONTENT
end

Expand Down Expand Up @@ -40,41 +40,19 @@ def append_blacklight_javascript
end

def add_stylesheet
unless used_bootstrap_css?
generate_with_sassc_rails
return
end

if ENV['CI']
run "yarn add file:#{Blacklight::Engine.root}"
if File.exist? 'app/assets/stylesheets/application.bootstrap.scss'
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import url("blacklight.css");
CONTENT
end
else
run "yarn add blacklight-frontend@#{Blacklight::VERSION}"
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
append_to_file 'app/assets/stylesheets/application.css' do
<<~CONTENT
@import url("blacklight.css");
@import stylesheet_path("blacklight.css");
CONTENT
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/blacklight/assets/propshaft_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def add_third_party_packages
def add_package_assets
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
@import url("blacklight.css");
CONTENT
end

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/blacklight/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
class AssetsGenerator < Rails::Generators::Base
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 5.3'), desc: "Set the generated app's bootstrap version"
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '5.3.3'), desc: "Set the generated app's bootstrap version"

def run_asset_pipeline_specific_generator
generated_options = "--bootstrap-version='#{options[:'bootstrap-version']}'" if options[:'bootstrap-version']
Expand Down

0 comments on commit 15293e9

Please sign in to comment.