middleman-importmap 0.3.0 → 0.6.0

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: 27d2cf6f5b1ec7a75c1d1804a59ddfe9317ca0bea4bada33a998affbda971b53
4
- data.tar.gz: cf66b660cc46ee27519c7ec312c8b638bc7ed5de75834caa091c6553e1a5b423
3
+ metadata.gz: 0f7ea7bfde0f17d3f72c92d067e68b5dcb52cd107c915143199e47b63e10ad3b
4
+ data.tar.gz: 6a18fc68762a8c2bc380484d21570ae1f55d8e2d3487507adda24c8429dac004
5
5
  SHA512:
6
- metadata.gz: 9e5c0575ee611a0c1ddcc87b5ac2f5811e9331226370757bbb5004be29d134a72620c3699208272ff346b192e89f2bcf0b4e4c9e5438aaa50e6f0b4f83023230
7
- data.tar.gz: 5695733d93e805c27357c894b852cd4ea90d129c1d02f3e3182d25ebe5f7549e43c0f1d36439aa892b40697e85e896c771e811e265a0113d15f9942e3a7700fb
6
+ metadata.gz: 1d6c40acd3b02ad10c296c2727d28343325b14b001317d078125bf52f579178b50874e0e31cbf5af2e502ab1f25acaf6c203e1eeac39ba49c10c3ad574f0117a
7
+ data.tar.gz: 2fdd84511385291c0db34be7c3b5902a78de648ede1768abcabead1d55ff41435155e9b6ddafa1917c9ec26c448ad4c79dc008a56f7ab2a38bb174f1dedf90c3
@@ -1,13 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "erb"
4
- require "yaml"
5
- require "middleman-core"
3
+ require 'erb'
4
+ require 'yaml'
5
+ require 'middleman-core'
6
6
 
7
7
  module Middleman
8
8
  class ImportmapExtension < Extension
9
- option :entrypoint, "site", "define js entrypoint file"
10
- option :use_shim, true, "use importmapdefine js entrypoint file"
9
+ option :entrypoint, 'site', 'define js entrypoint file'
10
+ option :importmap, 'importmap.yml', 'define importmap file'
11
+ option :use_shim, true, 'use ES module shim'
12
+ option :shim_src, 'https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js', 'define ES module shim source path'
13
+
14
+ expose_to_template :javascript_importmap_tags,
15
+ :javascript_importmap_shim_tag,
16
+ :javascript_inline_importmap_tag,
17
+ :javascript_inline_module_tag
11
18
 
12
19
  def initialize(app, options_hash = {}, &block)
13
20
  super
@@ -15,33 +22,51 @@ module Middleman
15
22
 
16
23
  def after_configuration; end
17
24
 
18
- helpers do
19
- def javascript_importmap_tags(entrypoint = "site", shim: true)
20
- [
21
- javascript_importmap_shim_tag,
22
- javascript_inline_importmap_tag,
23
- javascript_inline_module_tag(entrypoint),
24
- ].join
25
- end
25
+ def javascript_importmap_tags(entrypoint = options.entrypoint,
26
+ importmap: options.importmap,
27
+ shim: options.use_shim,
28
+ shim_src: options.shim_src)
29
+ [
30
+ (javascript_importmap_shim_tag(shim_src) if shim),
31
+ javascript_inline_importmap_tag(importmap, shim: shim),
32
+ javascript_inline_module_tag(entrypoint, shim: shim)
33
+ ].join
34
+ end
26
35
 
27
- def javascript_importmap_shim_tag
28
- template = File.join(File.dirname(__FILE__), "views/javascript_impotmap_shim_tag.html.erb")
29
- erb = ERB.new(File.read(template))
30
- erb.result
31
- end
36
+ def javascript_importmap_shim_tag(shim_src = options.shim_src)
37
+ template = File.join(File.dirname(__FILE__), 'views/javascript_importmap_shim_tag.html.erb')
38
+
39
+ erb = ERB.new(File.read(template))
40
+ erb.result_with_hash(src: shim_src)
41
+ end
32
42
 
33
- def javascript_inline_importmap_tag(importmap = "importmap.yml")
34
- template = File.join(File.dirname(__FILE__), "views/javascript_inline_impotmap_tag.html.erb")
35
- importmap_config = YAML.load_file(File.join(app.root_path, importmap), symbolize_names: true)
43
+ def javascript_inline_importmap_tag(importmap = options.importmap, shim: options.use_shim)
44
+ template = File.join(File.dirname(__FILE__), 'views/javascript_inline_importmap_tag.html.erb')
45
+ importmap_config = load_importmap(File.join(app.root_path, importmap))
36
46
 
37
- erb = ERB.new(File.read(template))
38
- erb.result_with_hash(importmap: importmap_config)
39
- end
47
+ erb = ERB.new(File.read(template))
48
+ erb.result_with_hash(importmap: importmap_config,
49
+ type: shim ? "importmap-shim" : "importmap")
50
+ end
51
+
52
+ def javascript_inline_module_tag(entrypoint = options.entrypoint, shim: options.use_shim)
53
+ template = File.join(File.dirname(__FILE__), 'views/javascript_inline_module_tag.html.erb')
54
+
55
+ erb = ERB.new(File.read(template))
56
+ erb.result_with_hash(entrypoint: entrypoint,
57
+ type: shim ? "module-shim" : "module")
58
+ end
59
+
60
+ private
40
61
 
41
- def javascript_inline_module_tag(entrypoint)
42
- template = File.join(File.dirname(__FILE__), "views/javascript_inline_module_tag.html.erb")
43
- erb = ERB.new(File.read(template))
44
- erb.result_with_hash(entrypoint: entrypoint)
62
+ def load_importmap(path)
63
+ if path.end_with?('.yml', '.yaml')
64
+ importmap = YAML.load_file(path, symbolize_names: true)
65
+ JSON.pretty_generate(importmap)
66
+ elsif path.end_with?('.json')
67
+ File.read(path)
68
+ else
69
+ raise "Importmap format must be YAML or JSON"
45
70
  end
46
71
  end
47
72
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Middleman
4
4
  module Importmap
5
- VERSION = "0.3.0"
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -1,7 +1,6 @@
1
-
2
1
  <script
3
2
  async
4
3
  data-turbo-track="reload"
5
- src="https://ga.jspm.io/npm:es-module-shims@1.5.4/dist/es-module-shims.js"
4
+ src="<%= src %>"
6
5
  crossorigin="anonymous"
7
6
  ></script>
@@ -0,0 +1,3 @@
1
+ <script type="<%= type %>">
2
+ <%= importmap %>
3
+ </script>
@@ -1,4 +1,4 @@
1
1
  <script
2
- type="module-shim"
2
+ type="<%= type %>"
3
3
  src="/javascripts/<%= entrypoint %>.js"
4
4
  ></script>
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "middleman-core"
3
+ require 'middleman-core'
4
4
 
5
5
  Middleman::Extensions.register(:importmap) do
6
- require "middleman-importmap/extension"
7
- ::Middleman::ImportmapExtension
6
+ require 'middleman-importmap/extension'
7
+ Middleman::ImportmapExtension
8
8
  end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "middleman-importmap"
3
+ require 'middleman-importmap'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-importmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -34,13 +34,14 @@ files:
34
34
  - lib/middleman-importmap.rb
35
35
  - lib/middleman-importmap/extension.rb
36
36
  - lib/middleman-importmap/version.rb
37
- - lib/middleman-importmap/views/javascript_impotmap_shim_tag.html.erb
38
- - lib/middleman-importmap/views/javascript_inline_impotmap_tag.html.erb
37
+ - lib/middleman-importmap/views/javascript_importmap_shim_tag.html.erb
38
+ - lib/middleman-importmap/views/javascript_inline_importmap_tag.html.erb
39
39
  - lib/middleman-importmap/views/javascript_inline_module_tag.html.erb
40
40
  - lib/middleman_extension.rb
41
41
  homepage: https://github.com/dvinciguerra/middleman-importmap
42
42
  licenses: []
43
- metadata: {}
43
+ metadata:
44
+ rubygems_mfa_required: 'true'
44
45
  post_install_message:
45
46
  rdoc_options: []
46
47
  require_paths:
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  - !ruby/object:Gem::Version
57
58
  version: '0'
58
59
  requirements: []
59
- rubygems_version: 3.3.7
60
+ rubygems_version: 3.4.22
60
61
  signing_key:
61
62
  specification_version: 4
62
63
  summary: Middleman Importmap extension
@@ -1,3 +0,0 @@
1
- <script type="importmap-shim">
2
- <%= JSON.pretty_generate(importmap) %>
3
- </script>