papercraft 0.27 → 0.28
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/papercraft/html.rb +40 -0
- data/lib/papercraft/tags.rb +0 -1
- data/lib/papercraft/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eccca55a3b242b80413bad0c851619062d66c1b68eaa9f2e4a13ca9e4beefddf
|
4
|
+
data.tar.gz: a5cf234c36fe286a94d6607bc30e13a24568396f6fe78b2f0e22870618e97941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 003a30933c7d7557a346ce02bcc54169427389db2e488ee5516b68b9e99d74f2b5f0464db4e327c1c3064bc7cbfe0df9c4ef0df6322b61a467f14f30a83b415c
|
7
|
+
data.tar.gz: cc8d7e819fdefc04a5ffb1966d707d6fb7e533bc0c8f6d3fc39191749c4733593850a4cb046648c010c2ae4daae6fbaa6980b806a1ab61d9746481dc63fd8ecf
|
data/CHANGELOG.md
CHANGED
data/lib/papercraft/html.rb
CHANGED
@@ -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
|
data/lib/papercraft/tags.rb
CHANGED
data/lib/papercraft/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|