papercraft 0.27 → 0.28

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: bd2f4f4d1ebc2cfc5718079d68c9393b3d95def9c02b057107425ddd5b45eaf3
4
- data.tar.gz: f3f82f29227e22e5e31b0d685bcab211ebbef0ecf8a4433d251cb1f204875cf7
3
+ metadata.gz: eccca55a3b242b80413bad0c851619062d66c1b68eaa9f2e4a13ca9e4beefddf
4
+ data.tar.gz: a5cf234c36fe286a94d6607bc30e13a24568396f6fe78b2f0e22870618e97941
5
5
  SHA512:
6
- metadata.gz: 7389861bea04a92e06ce1a53a682ef3b4db1bf975bb7f5e63cef0ed6c1a4ebb4b92920a0bb4ea04eba24dc72b41c70ba8fac0d8aa605a2b5a720d7860198b7e0
7
- data.tar.gz: 2a617260deef291c56cd0c3fc1b275d47dd1dc95bdeeafc69289d630260480e49126c29f0ec77c177fd6c1032c633ba2568be1ffb767e13f91e51b5a9c298831
6
+ metadata.gz: 003a30933c7d7557a346ce02bcc54169427389db2e488ee5516b68b9e99d74f2b5f0464db4e327c1c3064bc7cbfe0df9c4ef0df6322b61a467f14f30a83b415c
7
+ data.tar.gz: cc8d7e819fdefc04a5ffb1966d707d6fb7e533bc0c8f6d3fc39191749c4733593850a4cb046648c010c2ae4daae6fbaa6980b806a1ab61d9746481dc63fd8ecf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.28 2023-03-11
2
+
3
+ - Add `HTML#import_map`, `HTML#js_module` methods
4
+
1
5
  ## 0.27 2023-01-19
2
6
 
3
7
  - Fix rendering of HTML void element tags
@@ -71,7 +71,47 @@ module Papercraft
71
71
  @buffer << '></script>'
72
72
  end
73
73
  end
74
+
75
+ # Returns a versioned URL for the given file spec.
76
+ #
77
+ # @param href [String] relative file path
78
+ # @param root_path [String] root path for file
79
+ # @param root_url [String] root URL
80
+ # @return [String] versioned URL
81
+ def versioned_file_href(href, root_path, root_url = '')
82
+ fn = File.join(root_path, href)
83
+ version = File.stat(fn).mtime.to_i rescue 0
84
+ "#{root_url}/#{href}?v=#{version}"
85
+ end
74
86
 
87
+ # Emits an import map scrit tag. If a hash is given, emits the hash as is.
88
+ # If a string is given, searches for all *.js files under the given path,
89
+ # and emits an import map including all found files, with versioned URLs.
90
+ #
91
+ # @param root_path [String, Hash] root path or hash
92
+ # @param root_url [String] root URL to construct URLs against
93
+ # @return [void]
94
+ def import_map(root_path, root_url = '')
95
+ if root_path.is_a?(Hash)
96
+ script(root_path.to_json, type: 'importmap')
97
+ else
98
+ map = Dir["#{root_path}/*.js"].sort.each_with_object({}) do |fn, h|
99
+ name = File.basename(fn)
100
+ m = fn.match(/\/([^\/]+)\.js$/)
101
+ h[m[1]] = versioned_file_href(name, root_path, root_url)
102
+ end
103
+ script(map.to_json, type: 'importmap')
104
+ end
105
+ end
106
+
107
+ # Emits a script tag with type attribute set to module.
108
+ #
109
+ # @param code [String] JS code
110
+ # @return [void]
111
+ def js_module(code)
112
+ script code, type: 'module'
113
+ end
114
+
75
115
  # Converts and emits the given markdown. Papercraft uses
76
116
  # [Kramdown](https://github.com/gettalong/kramdown/) to do the Markdown to
77
117
  # HTML conversion. Optional Kramdown settings can be provided in order to
@@ -198,7 +198,6 @@ module Papercraft
198
198
  tag = sym.to_s
199
199
  if tag =~ /^[A-Z]/ && (Object.const_defined?(tag))
200
200
  define_const_tag_method(tag)
201
- # return send(tag, *args, **opts)
202
201
  else
203
202
  define_tag_method(tag)
204
203
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Papercraft
4
- VERSION = '0.27'
4
+ VERSION = '0.28'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papercraft
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.27'
4
+ version: '0.28'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-19 00:00:00.000000000 Z
11
+ date: 2023-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils