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_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
31 32 33 34 35 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 31 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
61 62 63 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 61 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
51 52 53 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 51 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)
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 38 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/[email protected]/dist/leaflet.css"); @import url("https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.fullscreen.css"); @import url("https://cdn.skypack.dev/[email protected]/ol.css"); SCSS end end |
#build_styles ⇒ Object
Run the build so styles are available for the first load of the app
77 78 79 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 77 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_import ⇒ Object
Ensure import of Blacklight’s JS uses the name that importmap has pinned
56 57 58 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 56 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
66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/geoblacklight/assets/importmap_generator.rb', line 66 def update_importmap gsub_file "config/importmap.rb", "bootstrap.min.js", "https://cdn.skypack.dev/[email protected]" 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/[email protected]/dist/umd/popper.min.js" CONTENT end end |