importmap-rails 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80b9cda4f79989099769db06ef9eeb785a7f9906cfa9eacbd3d6bf1dcd437edd
4
- data.tar.gz: 77972151d15109c1ee373331fa71f42e3957afb97af470fb8683f2c7e027df73
3
+ metadata.gz: 19ceaae3202d5f82c6ef2b17bfc294b3330a792a809c575eb0f959bd0f57aba4
4
+ data.tar.gz: 136f545bb38d4076dd6314bb2d35cb706d64fe2903f552c0ce1bbbf977549794
5
5
  SHA512:
6
- metadata.gz: 5a1c26adbcb471b81dcd1504771f36ac73dfb542a41c379dd257f01a6ec633545030ea0a4d33d49ff40fe56f30c336a0cee8e990aa58f1a3088acf7f0738c46b
7
- data.tar.gz: d1c94f03f8c844303887d08af37028e78b667120ce7fa04cbf3c7d7c52b1f56bd10ba69ed9ce0de8ea8b6af234443f96c03c0a3da21d2e0ba301a7997b00ecd4
6
+ metadata.gz: 332685ead888c7ea3c0de2187a6c34fbb0966e0806f31d6fa953483508623bdaec66add67f1a176fc74411530c76c2e1cfb465d1a95a5ce9b6a9163d57d24ecc
7
+ data.tar.gz: 1a8c37e746483245f90d8f3e763c321dca4bf363fdcd1a44802af48582637abafe05ac3af90fbd53e1cae1a612334a3ce9e15b06d4c11be9cea838448475732d
data/README.md CHANGED
@@ -38,7 +38,7 @@ You can use the `./bin/importmap` command that's added as part of the install to
38
38
  It works like so:
39
39
 
40
40
  ```bash
41
- /bin/importmap pin react react-dom
41
+ ./bin/importmap pin react react-dom
42
42
  Pinning "react" to https://ga.jspm.io/npm:react@17.0.2/index.js
43
43
  Pinning "react-dom" to https://ga.jspm.io/npm:react-dom@17.0.2/index.js
44
44
  Pinning "object-assign" to https://ga.jspm.io/npm:object-assign@4.1.1/index.js
@@ -141,6 +141,32 @@ pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js", preload: false
141
141
  ...
142
142
  ```
143
143
 
144
+ ## Composing import maps
145
+
146
+ By default, Rails loads import map definition from the application's `config/importmap.rb` to the `Importmap::Map` object available at `Rails.application.config.importmap`.
147
+
148
+ You can combine multiple import maps by drawing their definitions onto the `Rails.application.config.importmap`. For example, appending import maps defined in Rails engines:
149
+
150
+ ```ruby
151
+ # my_engine/lib/my_engine/engine.rb
152
+
153
+ module MyEngine
154
+ class Engine < ::Rails::Engine
155
+ # ...
156
+ initializer "my-engine.importmap" do |app|
157
+ app.config.importmap.draw(Engine.root.join("config/importmap.rb"))
158
+ end
159
+ end
160
+ end
161
+ ```
162
+
163
+ And pinning JavaScript modules from the engine:
164
+
165
+ ```ruby
166
+ # my_engine/config/importmap.rb
167
+
168
+ pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
169
+ ```
144
170
 
145
171
  ## Caching the import map and preload modules
146
172
 
@@ -12,7 +12,8 @@ module Importmap::ImportmapTagsHelper
12
12
  # Generate an inline importmap tag using the passed `importmap_json` JSON string.
13
13
  # By default, `Rails.application.config.importmap.to_json(resolver: self)` is used.
14
14
  def javascript_inline_importmap_tag(importmap_json = Rails.application.config.importmap.to_json(resolver: self))
15
- tag.script(importmap_json.html_safe, type: "importmap", "data-turbo-track": "reload")
15
+ tag.script importmap_json.html_safe,
16
+ type: "importmap", "data-turbo-track": "reload", nonce: content_security_policy_nonce
16
17
  end
17
18
 
18
19
  # Include the es-module-shim needed to make importmaps work in browsers without native support (like Firefox + Safari).
@@ -20,9 +21,11 @@ module Importmap::ImportmapTagsHelper
20
21
  javascript_include_tag "es-module-shims", async: true, "data-turbo-track": "reload"
21
22
  end
22
23
 
23
- # Import a named JavaScript module using a script-module tag.
24
- def javascript_import_module_tag(module_name)
25
- tag.script %(import "#{module_name}").html_safe, type: "module"
24
+ # Import a named JavaScript module(s) using a script-module tag.
25
+ def javascript_import_module_tag(*module_names)
26
+ imports = Array(module_names).collect { |m| %(import "#{m}") }.join("\n")
27
+ tag.script imports.html_safe,
28
+ type: "module", nonce: content_security_policy_nonce
26
29
  end
27
30
 
28
31
  # Link tags for preloading all modules marked as preload: true in the `importmap`
data/lib/importmap/map.rb CHANGED
@@ -11,7 +11,7 @@ class Importmap::Map
11
11
  def draw(path = nil, &block)
12
12
  if path && File.exist?(path)
13
13
  begin
14
- instance_eval(File.read(path))
14
+ instance_eval(File.read(path), path.to_s)
15
15
  rescue Exception => e
16
16
  Rails.logger.error "Unable to parse import map from #{path}: #{e.message}"
17
17
  raise "Unable to parse import map from #{path}: #{e.message}"
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importmap-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-06 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails