importmap-rails 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 271785dcc1a13f77093f95d79b7463f615754ea02129d6b7a8ff1d0fb32caf83
4
- data.tar.gz: af98f4e072978fd478ae00bc80d34a9357fd2375fde1bb246125852dbd65f92b
3
+ metadata.gz: d76219ce916f51a755ec35408f60b5258cf63b8d8d5b5252ab04b351348cfebb
4
+ data.tar.gz: 9467508f9d692ce701ccf1943adf146b776be046e1eac06f60541209fe26ace7
5
5
  SHA512:
6
- metadata.gz: 5775f5dd5149baa20c4cc4a9dde8caee59caffcddb2eb4c8ae65c20b5b90a7f8299957760cc6accffd192c250f37e0ec09f871a7b8354301aecf679f4a02ef8a
7
- data.tar.gz: baa9e8cd92f9d5d315d65924aa4e289d3dda8a920619fc202fcbd9e797df68ea1da80cab5569ec41ed6f21c9dd1c5d3cac5c17ac2a4975c84161590d99d6b36f
6
+ metadata.gz: c013fde57b613a62f6f228e6ceb5f106dbbe77af14d3737e2206bcdd38e78d1a8bbdf2c21d5e292b155b03ea6069918c4083c9f913595c925dc626d91286f1ca
7
+ data.tar.gz: dce28047300891ecdea4b5165dd99163066676fbf3145789ac094f74a2ef2aeb5f4f5a99d6b576da66ea70cb502ba3be61d8517e6ab9e0e8d62e40269d85f06d
@@ -2,8 +2,8 @@ module Importmap::ImportmapTagsHelper
2
2
  # Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3
3
  def javascript_importmap_tags(entry_point = "application")
4
4
  safe_join [
5
- javascript_importmap_module_preload_tags,
6
5
  javascript_inline_importmap_tag,
6
+ javascript_importmap_module_preload_tags,
7
7
  javascript_importmap_shim_tag,
8
8
  javascript_import_module_tag(entry_point)
9
9
  ], "\n"
data/lib/importmap/map.rb CHANGED
@@ -10,12 +10,12 @@ class Importmap::Map
10
10
  instance_eval(&block)
11
11
  end
12
12
 
13
- def pin(name, to: nil, preload: false)
13
+ def pin(name, to: nil, preload: true)
14
14
  @files[name] = MappedFile.new(name: name, path: to || "#{name}.js", preload: preload)
15
15
  end
16
16
 
17
- def pin_all_from(path, under: nil, preload: false)
18
- @directories[path] = MappedDir.new(path: path, under: under, preload: preload)
17
+ def pin_all_from(dir, under: nil, to: nil, preload: true)
18
+ @directories[dir] = MappedDir.new(dir: dir, under: under, path: to, preload: preload)
19
19
  end
20
20
 
21
21
  def preloaded_module_paths(resolver:)
@@ -32,7 +32,7 @@ class Importmap::Map
32
32
 
33
33
  private
34
34
  MappedFile = Struct.new(:name, :path, :preload, keyword_init: true)
35
- MappedDir = Struct.new(:path, :under, :preload, keyword_init: true)
35
+ MappedDir = Struct.new(:dir, :path, :under, :preload, keyword_init: true)
36
36
 
37
37
  def cache_as(name)
38
38
  if (cached && result = instance_variable_get("@cached_#{name}"))
@@ -63,11 +63,11 @@ class Importmap::Map
63
63
 
64
64
  def expand_directories_into(paths)
65
65
  @directories.values.each do |mapping|
66
- if (absolute_path = absolute_root_of(mapping.path)).exist?
66
+ if (absolute_path = absolute_root_of(mapping.dir)).exist?
67
67
  find_javascript_files_in_tree(absolute_path).each do |filename|
68
68
  module_filename = filename.relative_path_from(absolute_path)
69
- module_name = module_name_from(module_filename, mapping.under)
70
- module_path = mapping.under ? absolute_path.basename.join(module_filename).to_s : module_filename.to_s
69
+ module_name = module_name_from(module_filename, mapping)
70
+ module_path = module_path_from(module_filename, mapping)
71
71
 
72
72
  paths[module_name] = MappedFile.new(name: module_name, path: module_path, preload: mapping.preload)
73
73
  end
@@ -75,18 +75,23 @@ class Importmap::Map
75
75
  end
76
76
  end
77
77
 
78
- # Strip off the extension, /index, or any versioning data for an absolute module name.
79
- def module_name_from(filename, under)
80
- filename_without_ext = filename.to_s.remove(filename.extname)
78
+ def module_name_from(filename, mapping)
79
+ filename_without_ext_and_version = filename.to_s.remove(filename.extname).split("@").first
81
80
 
82
- if filename_without_ext == "index" && under
83
- under
81
+ case
82
+ when filename_without_ext_and_version == "index" && mapping.under
83
+ mapping.under
84
+ when mapping.under
85
+ "#{mapping.under}/#{filename_without_ext_and_version}"
84
86
  else
85
- module_name = filename_without_ext.split("@").first
86
- under ? "#{under}/#{module_name}" : module_name
87
+ module_name
87
88
  end
88
89
  end
89
90
 
91
+ def module_path_from(filename, mapping)
92
+ [ mapping.path || mapping.under, filename.to_s ].join("/")
93
+ end
94
+
90
95
  def find_javascript_files_in_tree(path)
91
96
  Dir[path.join("**/*.js{,m}")].collect { |file| Pathname.new(file) }.select(&:file?)
92
97
  end
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
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.2.6
4
+ version: 0.2.7
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-08-16 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails