impression 0.6 → 0.7

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: 79fca9e0a9d2a2e782bd3168384e752009776b82d50c285f14f7a2951dae0e5c
4
- data.tar.gz: 9d2d433216ca25fcd23b66e7f545520b8433abc076efde2c919d4e0dc8fd980c
3
+ metadata.gz: 871b003a25f9dd74ea137c483c2c208bdad9cf505d544c085f1f84eff394a278
4
+ data.tar.gz: 55623ee42bbc7213ef37c6632b1d4807b882301d133bc324607878857b7110c4
5
5
  SHA512:
6
- metadata.gz: 84105ef65c86fefc2babdb7d44e3c89f9b6562d8c1bd4e3bdffa62b279e6e3b236841c5574de57fba4e7fe870f7a183659c636834af93b6d93df3d60f1818fcc
7
- data.tar.gz: df125e64c903affa9946704e0c559d45848c89879621d764aa98b66fecaa1fcf27ff899ddb36c11e489f816792345252fe4e08df85c2796773affc88b0f95e9a
6
+ metadata.gz: 29437cfb294efff3d90c7bcfa82bf05bba184b0ea4f68f13097650c2af17440e2d1294d95e06c17b981a4066c58dde70ac77fd3b8fbacb9ca7a676d08dfc71be
7
+ data.tar.gz: a787832534b192c37bc936f96a0c7b92c97b516dc2857b49fbefedab3a152c73301b6ce09e6b1bf581a77dd14bd8a2fa455c84e693b1ac29d5eb74208058bf33
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.7 2022-01-23
2
+
3
+ - Update Papercraft, Refactor Jamstack resource
4
+
1
5
  # 0.6 2022-01-22
2
6
 
3
7
  - Unify page_list entries and page_info cache entries (#10)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- impression (0.5)
4
+ impression (0.7)
5
5
  modulation (~> 1.1)
6
- papercraft (~> 0.15)
6
+ papercraft (~> 0.17)
7
7
  polyphony (~> 0.73.1)
8
8
  qeweney (~> 0.16)
9
9
  tipi (~> 0.45)
@@ -52,7 +52,7 @@ GEM
52
52
  modulation (1.1)
53
53
  msgpack (1.4.4)
54
54
  multipart-post (2.1.1)
55
- papercraft (0.15)
55
+ papercraft (0.17)
56
56
  escape_utils (~> 1.2.1)
57
57
  kramdown (~> 2.3.1)
58
58
  kramdown-parser-gfm (~> 1.1.0)
data/impression.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_runtime_dependency 'qeweney', '~>0.16'
28
28
 
29
29
  # s.add_runtime_dependency 'rb-inotify', '~>0.10.1'
30
- s.add_runtime_dependency 'papercraft', '~>0.15'
30
+ s.add_runtime_dependency 'papercraft', '~>0.17'
31
31
  s.add_runtime_dependency 'modulation', '~>1.1'
32
32
 
33
33
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'fileutils'
4
- require 'yaml'
5
4
  require 'date'
5
+ require 'yaml'
6
6
  require 'modulation'
7
7
  require 'papercraft'
8
8
 
@@ -36,10 +36,13 @@ module Impression
36
36
  private
37
37
 
38
38
  DATE_REGEXP = /(\d{4}\-\d{2}\-\d{2})/.freeze
39
- MARKDOWN_PAGE_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
39
+ FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
40
40
  MD_EXT_REGEXP = /\.md$/.freeze
41
41
  PAGE_EXT_REGEXP = /^(.+)\.(md|html|rb)$/.freeze
42
42
  INDEX_PAGE_REGEXP = /^(.+)?\/index$/.freeze
43
+ YAML_OPTS = {
44
+ permitted_classes: [Date]
45
+ }.freeze
43
46
 
44
47
  # Returns the path info for the given file path.
45
48
  #
@@ -51,7 +54,7 @@ module Impression
51
54
  when '.md'
52
55
  atts, content = parse_markdown_file(path)
53
56
  info = info.merge(atts)
54
- info[:markdown_content] = content
57
+ info[:html_content] = Papercraft.markdown(content)
55
58
  when '.rb'
56
59
  info[:module] = import(path)
57
60
  end
@@ -99,8 +102,9 @@ module Impression
99
102
  # @param path_info [Hash] path info
100
103
  # @return [void]
101
104
  def render_papercraft_module(req, path_info)
102
- html = H(path_info[:module]).render(request: req, resource: self)
103
- req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
105
+ template = Papercraft.html(path_info[:module])
106
+ body = template.render(request: req, resource: self)
107
+ req.respond(body, 'Content-Type' => template.mime_type)
104
108
  end
105
109
 
106
110
  # Renders a markdown file using a layout.
@@ -112,7 +116,7 @@ module Impression
112
116
  layout = get_layout(path_info[:layout])
113
117
 
114
118
  html = layout.render(request: req, resource: self, **path_info) {
115
- emit_markdown path_info[:markdown_content]
119
+ emit path_info[:html_content]
116
120
  }
117
121
  req.respond(html, 'Content-Type' => Qeweney::MimeTypes[:html])
118
122
  end
@@ -135,7 +139,7 @@ module Impression
135
139
  # @param path [String] file path
136
140
  # @return [Array] an tuple containing properties<Hash>, contents<String>
137
141
  def parse_markdown_file(path)
138
- data = IO.read(path) || ''
142
+ content = IO.read(path) || ''
139
143
  atts = {}
140
144
 
141
145
  # Parse date from file name
@@ -143,16 +147,17 @@ module Impression
143
147
  atts[:date] ||= Date.parse(m[1])
144
148
  end
145
149
 
146
- if (m = data.match(MARKDOWN_PAGE_REGEXP))
150
+ if (m = content.match(FRONT_MATTER_REGEXP))
147
151
  front_matter = m[1]
148
- data = m.post_match
152
+ content = m.post_match
149
153
 
150
- YAML.load(front_matter).each_with_object(atts) do |(k, v), h|
154
+ yaml = YAML.load(front_matter, **YAML_OPTS)
155
+ yaml.each_with_object(atts) do |(k, v), h|
151
156
  h[k.to_sym] = v
152
157
  end
153
158
  end
154
159
 
155
- [atts, data]
160
+ [atts, content]
156
161
  end
157
162
 
158
163
  # Returns the supported path extensions used for searching for files based
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Impression
4
- VERSION = '0.6'
4
+ VERSION = '0.7'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  require 'papercraft'
2
2
 
3
- export_default H { |**props|
3
+ export_default Papercraft.html { |**props|
4
4
  html5 {
5
5
  head {
6
6
  title props[:title]
@@ -48,7 +48,7 @@ class JamstackTest < MiniTest::Test
48
48
  req = mock_req(':method' => 'GET', ':path' => '/foo')
49
49
  @jamstack.route_and_call(req)
50
50
 
51
- foo = H {
51
+ foo = Papercraft.html {
52
52
  html5 {
53
53
  head {
54
54
  title 'Foo title'
@@ -63,7 +63,7 @@ class JamstackTest < MiniTest::Test
63
63
  req = mock_req(':method' => 'GET', ':path' => '/index')
64
64
  @jamstack.route_and_call(req)
65
65
 
66
- index = H {
66
+ index = Papercraft.html {
67
67
  html5 {
68
68
  head {
69
69
  title 'Hello'
@@ -86,7 +86,7 @@ class JamstackTest < MiniTest::Test
86
86
  req = mock_req(':method' => 'GET', ':path' => '/baz')
87
87
  @jamstack.route_and_call(req)
88
88
 
89
- baz_index = H {
89
+ baz_index = Papercraft.html {
90
90
  html5 {
91
91
  head {
92
92
  title 'BarBar'
@@ -101,7 +101,7 @@ class JamstackTest < MiniTest::Test
101
101
  req = mock_req(':method' => 'GET', ':path' => '/articles/a')
102
102
  @jamstack.route_and_call(req)
103
103
 
104
- a = H {
104
+ a = Papercraft.html {
105
105
  html5 {
106
106
  head {
107
107
  title 'AAA'
@@ -138,7 +138,7 @@ class JamstackTest < MiniTest::Test
138
138
  req = mock_req(':method' => 'GET', ':path' => '/app/foo')
139
139
  @jamstack.route_and_call(req)
140
140
 
141
- foo = H {
141
+ foo = Papercraft.html {
142
142
  html5 {
143
143
  head {
144
144
  title 'Foo title'
@@ -153,7 +153,7 @@ class JamstackTest < MiniTest::Test
153
153
  req = mock_req(':method' => 'GET', ':path' => '/app/index')
154
154
  @jamstack.route_and_call(req)
155
155
 
156
- index = H {
156
+ index = Papercraft.html {
157
157
  html5 {
158
158
  head {
159
159
  title 'Hello'
@@ -176,7 +176,7 @@ class JamstackTest < MiniTest::Test
176
176
  req = mock_req(':method' => 'GET', ':path' => '/app/baz')
177
177
  @jamstack.route_and_call(req)
178
178
 
179
- baz_index = H {
179
+ baz_index = Papercraft.html {
180
180
  html5 {
181
181
  head {
182
182
  title 'BarBar'
@@ -191,7 +191,7 @@ class JamstackTest < MiniTest::Test
191
191
  req = mock_req(':method' => 'GET', ':path' => '/app/articles/a')
192
192
  @jamstack.route_and_call(req)
193
193
 
194
- a = H {
194
+ a = Papercraft.html {
195
195
  html5 {
196
196
  head {
197
197
  title 'AAA'
@@ -213,7 +213,7 @@ class JamstackTest < MiniTest::Test
213
213
  assert_equal [
214
214
  { kind: :file, path: File.join(JAMSTACK_PATH, 'bar.html'), ext: '.html', url: '/app/bar' },
215
215
  { kind: :file, path: File.join(JAMSTACK_PATH, 'index.md'), ext: '.md', url: '/app',
216
- title: 'Hello', foo: 'BarBar', markdown_content: '<h1>Index</h1>' },
216
+ title: 'Hello', foo: 'BarBar', html_content: "<h1>Index</h1>\n" },
217
217
  ], list
218
218
 
219
219
 
@@ -227,7 +227,7 @@ class JamstackTest < MiniTest::Test
227
227
  ext: '.md',
228
228
  title: 'MMM',
229
229
  layout: 'article',
230
- markdown_content: "## BBB\n",
230
+ html_content: "<h2 id=\"bbb\">BBB</h2>\n",
231
231
  date: Date.new(2008, 06, 14)
232
232
  },
233
233
  {
@@ -237,7 +237,7 @@ class JamstackTest < MiniTest::Test
237
237
  ext: '.md',
238
238
  title: 'NNN',
239
239
  layout: 'article',
240
- markdown_content: "## CCC\n",
240
+ html_content: "<h2 id=\"ccc\">CCC</h2>\n",
241
241
  date: Date.new(2009, 06, 12)
242
242
  },
243
243
  {
@@ -247,7 +247,7 @@ class JamstackTest < MiniTest::Test
247
247
  ext: '.md',
248
248
  title: 'AAA',
249
249
  layout: 'article',
250
- markdown_content: "## ZZZ\n"
250
+ html_content: "<h2 id=\"zzz\">ZZZ</h2>\n",
251
251
  },
252
252
  ], list
253
253
  end
@@ -256,7 +256,7 @@ class JamstackTest < MiniTest::Test
256
256
  req = mock_req(':method' => 'GET', ':path' => '/foobar?q=42')
257
257
  @jamstack.route_and_call(req)
258
258
 
259
- foo = H {
259
+ foo = Papercraft.html {
260
260
  html5 {
261
261
  head {
262
262
  title 'Foobar'
@@ -284,7 +284,7 @@ class JamstackTest < MiniTest::Test
284
284
  url: '/',
285
285
  title: 'Hello',
286
286
  foo: 'BarBar',
287
- markdown_content: '<h1>Index</h1>'
287
+ html_content: "<h1>Index</h1>\n"
288
288
  }, path_info('/index'))
289
289
 
290
290
  assert_equal({
@@ -294,7 +294,7 @@ class JamstackTest < MiniTest::Test
294
294
  url: '/',
295
295
  title: 'Hello',
296
296
  foo: 'BarBar',
297
- markdown_content: '<h1>Index</h1>'
297
+ html_content: "<h1>Index</h1>\n"
298
298
  }, path_info('/'))
299
299
 
300
300
  assert_equal({
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impression
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-22 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polyphony
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.15'
61
+ version: '0.17'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.15'
68
+ version: '0.17'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: modulation
71
71
  requirement: !ruby/object:Gem::Requirement