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 +4 -4
- data/lib/middleman-importmap/extension.rb +53 -28
- data/lib/middleman-importmap/version.rb +1 -1
- data/lib/middleman-importmap/views/{javascript_impotmap_shim_tag.html.erb → javascript_importmap_shim_tag.html.erb} +1 -2
- data/lib/middleman-importmap/views/javascript_inline_importmap_tag.html.erb +3 -0
- data/lib/middleman-importmap/views/javascript_inline_module_tag.html.erb +1 -1
- data/lib/middleman-importmap.rb +3 -3
- data/lib/middleman_extension.rb +1 -1
- metadata +7 -6
- data/lib/middleman-importmap/views/javascript_inline_impotmap_tag.html.erb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f7ea7bfde0f17d3f72c92d067e68b5dcb52cd107c915143199e47b63e10ad3b
|
4
|
+
data.tar.gz: 6a18fc68762a8c2bc380484d21570ae1f55d8e2d3487507adda24c8429dac004
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d6c40acd3b02ad10c296c2727d28343325b14b001317d078125bf52f579178b50874e0e31cbf5af2e502ab1f25acaf6c203e1eeac39ba49c10c3ad574f0117a
|
7
|
+
data.tar.gz: 2fdd84511385291c0db34be7c3b5902a78de648ede1768abcabead1d55ff41435155e9b6ddafa1917c9ec26c448ad4c79dc008a56f7ab2a38bb174f1dedf90c3
|
@@ -1,13 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'erb'
|
4
|
+
require 'yaml'
|
5
|
+
require 'middleman-core'
|
6
6
|
|
7
7
|
module Middleman
|
8
8
|
class ImportmapExtension < Extension
|
9
|
-
option :entrypoint,
|
10
|
-
option :
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
data/lib/middleman-importmap.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'middleman-core'
|
4
4
|
|
5
5
|
Middleman::Extensions.register(:importmap) do
|
6
|
-
require
|
7
|
-
|
6
|
+
require 'middleman-importmap/extension'
|
7
|
+
Middleman::ImportmapExtension
|
8
8
|
end
|
data/lib/middleman_extension.rb
CHANGED
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.
|
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:
|
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/
|
38
|
-
- lib/middleman-importmap/views/
|
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.
|
60
|
+
rubygems_version: 3.4.22
|
60
61
|
signing_key:
|
61
62
|
specification_version: 4
|
62
63
|
summary: Middleman Importmap extension
|