Class: Spotlight::Assets::ImportmapGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spotlight::Assets::ImportmapGenerator
- Includes:
- GeneratorCommonUtilities
- Defined in:
- lib/generators/spotlight/assets/importmap_generator.rb
Overview
Spotlight Importmap Generator
Instance Method Summary collapse
-
#add_frontend ⇒ Object
Needed for the stylesheets.
- #add_javascript ⇒ Object
- #add_stylesheet_dependencies ⇒ Object
- #add_stylesheets ⇒ Object
Methods included from GeneratorCommonUtilities
#blacklight_yarn_version, #bootstrap_version, #bootstrap_yarn_version, #package_yarn_version, #spotlight_yarn_version
Instance Method Details
#add_frontend ⇒ Object
Needed for the stylesheets
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/spotlight/assets/importmap_generator.rb', line 35 def add_frontend if ENV['CI'] run "yarn add file:#{Spotlight::Engine.root}" elsif [:test] run 'yarn link spotlight-frontend' # If a branch was specified (e.g. you are running a template.rb build # against a test branch), use the latest version available on npm elsif ENV['BRANCH'] run 'yarn add spotlight-frontend@latest' # Otherwise, pick the version from npm that matches the Spotlight # gem version else run "yarn add spotlight-frontend@#{spotlight_yarn_version}" end end |
#add_javascript ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/generators/spotlight/assets/importmap_generator.rb', line 53 def add_javascript # This may have been added from Blacklight, but it is a Spotlight dependency so ensure it is present. insert_into_file 'app/javascript/application.js', "import githubAutoCompleteElement from \"@github/auto-complete-element\"\n" append_to_file 'app/javascript/application.js' do <<~CONTENT import Spotlight from "spotlight" Blacklight.onLoad(function() { Spotlight.activate(); }); CONTENT end end |
#add_stylesheet_dependencies ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/spotlight/assets/importmap_generator.rb', line 28 def add_stylesheet_dependencies run "yarn add blacklight-frontend@#{blacklight_yarn_version}" run "yarn add bootstrap@\"^#{bootstrap_yarn_version}\"" run 'yarn add leaflet' end |
#add_stylesheets ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/generators/spotlight/assets/importmap_generator.rb', line 69 def add_stylesheets copy_file 'assets/spotlight.scss', 'app/assets/stylesheets/spotlight.scss' append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do <<~CONTENT @import "spotlight"; CONTENT end end |