Class: Geoblacklight::Assets::ImportmapGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Geoblacklight::Assets::ImportmapGenerator
- Defined in:
- lib/generators/geoblacklight/assets/importmap_generator.rb
Instance Method Summary collapse
-
#add_customizations ⇒ Object
Add the customization overrides and insert before bootstrap import.
-
#add_geoblacklight_js ⇒ Object
Import Geoblacklight’s JS using the name that importmap has pinned.
-
#add_geoblacklight_styles ⇒ Object
Add an import for Geoblacklight’s stylesheet.
-
#add_leaflet_ol_css_cdn ⇒ Object
Add CDN imports for CSS files used by Geoblacklight (leaflet, openlayers).
-
#build_styles ⇒ Object
Run the build so styles are available for the first load of the app.
-
#link_frontend ⇒ Object
If this is a local dev/test build, symlink the frontend package so we can reference its stylesheets in development.
-
#update_blacklight_frontend ⇒ Object
Workaround for github.com/projectblacklight/blacklight/pull/3285.
-
#update_blacklight_import ⇒ Object
Ensure import of Blacklight’s JS uses the name that importmap has pinned.
-
#update_importmap ⇒ Object
Add pins for application dependencies to the importmap.
Instance Method Details
#add_customizations ⇒ Object
Add the customization overrides and insert before bootstrap import
36 37 38 39 40 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 36 def add_customizations copy_file "assets/_customizations.scss", "app/assets/stylesheets/_customizations.scss" gsub_file "app/assets/stylesheets/_customizations.scss", "@geoblacklight/frontend/app/assets/", "" insert_into_file "app/assets/stylesheets/application.bootstrap.scss", "@import 'customizations';\n", before: "@import 'bootstrap/scss/bootstrap';" end |
#add_geoblacklight_js ⇒ Object
Import Geoblacklight’s JS using the name that importmap has pinned
66 67 68 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 66 def add_geoblacklight_js append_to_file "app/javascript/application.js", "import Geoblacklight from \"geoblacklight\";" end |
#add_geoblacklight_styles ⇒ Object
Add an import for Geoblacklight’s stylesheet
56 57 58 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 56 def add_geoblacklight_styles append_to_file "app/assets/stylesheets/application.bootstrap.scss", "@import '@geoblacklight/frontend/app/assets/stylesheets/geoblacklight/geoblacklight';" end |
#add_leaflet_ol_css_cdn ⇒ Object
Add CDN imports for CSS files used by Geoblacklight (leaflet, openlayers)
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 43 def add_leaflet_ol_css_cdn insert_into_file "app/assets/stylesheets/application.bootstrap.scss", before: "@import 'customizations';\n" do <<~SCSS /* GeoBlacklight dependencies CSS */ @import url("https://cdn.skypack.dev/leaflet@1.9.4/dist/leaflet.css"); @import url("https://cdn.jsdelivr.net/npm/leaflet-fullscreen@1.0.2/dist/leaflet.fullscreen.css"); @import url("https://cdn.skypack.dev/ol@8.1.0/ol.css"); SCSS end end |
#build_styles ⇒ Object
Run the build so styles are available for the first load of the app
82 83 84 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 82 def build_styles run "yarn build:css" end |
#link_frontend ⇒ Object
If this is a local dev/test build, symlink the frontend package so we can reference its stylesheets in development
26 27 28 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 26 def link_frontend run "yarn link @geoblacklight/frontend" if [:test] end |
#update_blacklight_frontend ⇒ Object
Workaround for github.com/projectblacklight/blacklight/pull/3285
31 32 33 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 31 def update_blacklight_frontend run "yarn add blacklight-frontend@8.3" end |
#update_blacklight_import ⇒ Object
Ensure import of Blacklight’s JS uses the name that importmap has pinned
61 62 63 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 61 def update_blacklight_import gsub_file "app/javascript/application.js", "blacklight-frontend", "blacklight" end |
#update_importmap ⇒ Object
Add pins for application dependencies to the importmap
71 72 73 74 75 76 77 78 79 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 71 def update_importmap gsub_file "config/importmap.rb", "bootstrap.min.js", "https://cdn.skypack.dev/bootstrap@5.3.3" append_to_file "config/importmap.rb" do <<~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/core@2.11.8/dist/umd/popper.min.js" CONTENT end end |