pakyow-presenter 1.0.1 → 1.0.6

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: ff2206682c1ecea87b0f187e466980504acb26e8afd855563f50616a704c403c
4
- data.tar.gz: eb5f2a5ed2add51a1d8452e521b9b7398e1bf9fc73ad6c3c8b9464a332ba6bac
3
+ metadata.gz: 2cee34e4269fad79bc999263550f35f06338299e012a851dfee51690d8d68a87
4
+ data.tar.gz: 1a3285e8f63fc4e2dd52cdfb23c9dbc2ceca7022381f2bb78091be2d381eb882
5
5
  SHA512:
6
- metadata.gz: 9d36244aae51899cf62afd510c632865dfc2b846ed53766dfa49783046db0739fdeb4758fc83dddb2236c887700764971253352132221885a2ff88690dece453
7
- data.tar.gz: 8e1d1fc3be2214d4abb1333dc6dc29413653a87c256ac42d5e43511f200ee5990b44fba846a78c1e873311f08f780bc982db40bbc2bf571d60a18a2b71d7bfef
6
+ metadata.gz: 0cb31752c255af9efc5ecc93334be35598ded884943cccbdcd5d2e2272852a78cf62a35b95a500383e58e69c60d38c7b8a4117fe5b99be41156d0c379dfe42b8
7
+ data.tar.gz: 9131ed42e58ef78674fb94559f7f1c06fdc04bf6e721d2c0bc429888bc6dc419e39ed07538346e36fedb4228ba627c93d04c9dc39681527e133af94f36f89cc7
@@ -1,5 +1,18 @@
1
- # UNRELEASED
1
+ # v1.0.2
2
2
 
3
- # 1.0
3
+ * `fix` **Template store is more efficient for faster loading.**
4
+
5
+ *Related links:*
6
+ - [Pull Request #324][pr-324]
7
+
8
+ * `fix` **Now renders correctly when a collapsed string doc is transformed.**
9
+
10
+ *Related links:*
11
+ - [Commit 87b7a6c][87b7a6c]
12
+
13
+ [pr-324]: https://github.com/pakyow/pakyow/pull/324/commits
14
+ [87b7a6c]: https://github.com/pakyow/pakyow/commit/87b7a6c06a9524703dc1667b6a010930b682f6d7
15
+
16
+ # v1.0.0
4
17
 
5
18
  * Hello, Web
@@ -51,9 +51,12 @@ module Pakyow
51
51
  # mostly an optimization, since it lets us collapse some nodes into single strings and
52
52
  # reduce the number of operations needed for a render.
53
53
  #
54
- view.object.collapse(
55
- *(StringDoc.significant_types.keys - UNRETAINED_SIGNIFICANCE)
56
- )
54
+ # FIXME: This breaks when a collapsed string doc is transformed. Once that's fixed, we
55
+ # can enable this code again. It's pretty low-priority and not worth fixing right now.
56
+ #
57
+ # view.object.collapse(
58
+ # *(StringDoc.significant_types.keys - UNRETAINED_SIGNIFICANCE)
59
+ # )
57
60
 
58
61
  # Empty nodes are removed as another render-time optimization leading to fewer operations.
59
62
  #
@@ -53,7 +53,7 @@ module Pakyow
53
53
  end
54
54
  elsif view.object.labeled?(:endpoint_object)
55
55
  view.object.label(:endpoint_object).path(
56
- __endpoint.params.merge(view.object.label(:endpoint_params).to_h)
56
+ **__endpoint.params.merge(view.object.label(:endpoint_params).to_h)
57
57
  )
58
58
  else
59
59
  nil
@@ -257,7 +257,7 @@ module Pakyow
257
257
  endpoint_path << possible_endpoint_name
258
258
  endpoint_path.uniq!
259
259
 
260
- app.endpoints.path_to(*endpoint_path, action, params)
260
+ app.endpoints.path_to(*endpoint_path, action, **params)
261
261
  }.compact.first
262
262
  end
263
263
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module CleanupPrototypeNodes
10
11
  extend Support::Extension
11
12
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module CleanupUnboundBindings
10
11
  extend Support::Extension
11
12
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module CreateTemplateNodes
10
11
  extend Support::Extension
11
12
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module InsertPrototypeBar
10
11
  extend Support::Extension
11
12
 
@@ -8,6 +8,7 @@ module Pakyow
8
8
  module Presenter
9
9
  class Renderer
10
10
  module Behavior
11
+ # @api private
11
12
  module InstallAuthenticity
12
13
  extend Support::Extension
13
14
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module PlaceInMode
10
11
  extend Support::Extension
11
12
 
@@ -8,6 +8,7 @@ module Pakyow
8
8
  module Presenter
9
9
  class Renderer
10
10
  module Behavior
11
+ # @api private
11
12
  module RenderComponents
12
13
  extend Support::Extension
13
14
 
@@ -6,6 +6,7 @@ module Pakyow
6
6
  module Presenter
7
7
  class Renderer
8
8
  module Behavior
9
+ # @api private
9
10
  module SetPageTitle
10
11
  extend Support::Extension
11
12
 
@@ -8,6 +8,7 @@ module Pakyow
8
8
  module Presenter
9
9
  class Renderer
10
10
  module Behavior
11
+ # @api private
11
12
  module SetupEndpoints
12
13
  extend Support::Extension
13
14
 
@@ -10,6 +10,7 @@ module Pakyow
10
10
  module Presenter
11
11
  class Renderer
12
12
  module Behavior
13
+ # @api private
13
14
  module SetupForms
14
15
  extend Support::Extension
15
16
 
@@ -17,6 +17,7 @@ module Pakyow
17
17
 
18
18
  def initialize(name, path, processor: nil, config: {})
19
19
  @name, @path, @processor = name, Pathname(path), processor
20
+ @layouts, @includes, @info = {}, {}, {}
20
21
  build_config(config)
21
22
  load_templates
22
23
  end
@@ -99,6 +100,10 @@ module Pakyow
99
100
  }
100
101
  end
101
102
 
103
+ def layout_with_name(name)
104
+ @layouts[name.to_sym]
105
+ end
106
+
102
107
  def load_templates
103
108
  load_layouts
104
109
  load_partials
@@ -106,62 +111,63 @@ module Pakyow
106
111
  end
107
112
 
108
113
  def load_layouts
109
- @layouts = if File.exist?(layouts_path)
110
- layouts_path.children.each_with_object({}) { |file, layouts|
111
- next unless template?(file)
112
- if layout = load_view_of_type_at_path(Views::Layout, file)
113
- layouts[layout.name] = layout
114
- end
115
- }
116
- else
117
- {}
118
- end
119
- end
114
+ return unless layouts_path.exist?
120
115
 
121
- def load_partials
122
- @includes = if File.exist?(partials_path)
123
- partials_path.children.each_with_object({}) { |file, partials|
124
- next unless template?(file)
125
- if partial = load_view_of_type_at_path(Views::Partial, file, normalize_path(file))
126
- partials[partial.name] = partial
127
- end
128
- }
129
- else
130
- {}
131
- end
132
- end
116
+ layouts_path.children.each_with_object(@layouts) { |file, layouts|
117
+ next unless template?(file)
133
118
 
134
- def load_path_info
135
- @info = {}
119
+ if layout = load_view_of_type_at_path(Views::Layout, file)
120
+ layouts[layout.name] = layout
121
+ end
122
+ }
123
+ end
136
124
 
137
- Pathname.glob(File.join(pages_path, "**/*")) do |path|
138
- # TODO: better way to skip partials?
139
- next if path.basename.to_s.start_with?("_")
125
+ def load_partials
126
+ return unless partials_path.exist?
140
127
 
141
- next unless template?(path)
128
+ partials_path.children.each_with_object(@includes) { |file, partials|
129
+ next unless template?(file)
142
130
 
143
- begin
144
- if page = page_at_path(path)
145
- @info[String.normalize_path(File.join(@config[:prefix], normalize_path(path, pages_path)))] = {
146
- page: page,
147
- layout: layout_with_name(page.info(:layout)),
148
- partials: @includes.merge(partials_at_path(path))
149
- }
150
- end
151
- rescue FrontMatterParsingError => e
152
- message = "Could not parse front matter for #{path}:\n\n#{e.context}"
131
+ if partial = load_view_of_type_at_path(Views::Partial, file, normalize_path(file))
132
+ partials[partial.name] = partial
133
+ end
134
+ }
135
+ end
153
136
 
154
- if e.wrapped_exception
155
- message << "\n#{e.wrapped_exception.problem} at line #{e.wrapped_exception.line} column #{e.wrapped_exception.column}"
156
- end
137
+ def load_path_info
138
+ pages_path.glob("**/*").select { |path|
139
+ template?(path)
140
+ }.reject { |path|
141
+ path.basename.to_s.start_with?("_")
142
+ }.each do |path|
143
+ if page = page_at_path(path)
144
+ path_to_page = String.normalize_path(
145
+ File.join(
146
+ @config[:prefix], normalize_path(path, pages_path)
147
+ )
148
+ )
149
+
150
+ @info[path_to_page] = {
151
+ page: page,
152
+
153
+ layout: layout_with_name(
154
+ page.info(:layout)
155
+ ),
156
+
157
+ partials: @includes.merge(
158
+ partials_at_path(path)
159
+ )
160
+ }
161
+ end
162
+ rescue FrontMatterParsingError => e
163
+ message = "Could not parse front matter for #{path}:\n\n#{e.context}"
157
164
 
158
- raise FrontMatterParsingError.new(message)
165
+ if e.wrapped_exception
166
+ message << "\n#{e.wrapped_exception.problem} at line #{e.wrapped_exception.line} column #{e.wrapped_exception.column}"
159
167
  end
160
- end
161
- end
162
168
 
163
- def layout_with_name(name)
164
- @layouts[name.to_sym]
169
+ raise FrontMatterParsingError.new(message)
170
+ end
165
171
  end
166
172
 
167
173
  def page_at_path(path)
@@ -175,38 +181,15 @@ module Pakyow
175
181
  end
176
182
 
177
183
  def index_page_at_path(path)
178
- # TODO: don't ascend above store path
179
- path.ascend do |parent_path|
184
+ ascend(path) do |parent_path|
180
185
  next unless info = info(normalize_path(parent_path))
181
186
  next unless page = info[:page]
182
187
  return page
183
188
  end
184
189
  end
185
190
 
186
- # TODO: do we always need to make it relative, etc here?
187
- # maybe break up these responsibilities to the bare minimum required
188
- def normalize_path(path, relative_from = @path)
189
- path = path.expand_path
190
- relative_from = relative_from.expand_path
191
-
192
- # make it relative
193
- path = path.relative_path_from(relative_from)
194
- # we can short-circuit here
195
- return "/" if path.to_s == "."
196
-
197
- # remove the extension
198
- path = path.sub_ext("")
199
-
200
- # remove index from the end
201
- path = path.sub("index", "")
202
-
203
- # actually normalize it
204
- String.normalize_path(path.to_s)
205
- end
206
-
207
191
  def partials_at_path(path)
208
- # FIXME: don't ascend above store path
209
- path.ascend.select(&:directory?).each_with_object({}) { |parent_path, partials|
192
+ ascend(path).select(&:directory?).each_with_object({}) { |parent_path, partials|
210
193
  parent_path.children.select { |child|
211
194
  child.basename.to_s.start_with?("_")
212
195
  }.each_with_object(partials) { |child, child_partials|
@@ -233,6 +216,35 @@ module Pakyow
233
216
  nil
234
217
  end
235
218
  end
219
+
220
+ def ascend(path)
221
+ return enum_for(:ascend, path) unless block_given?
222
+
223
+ path.ascend.each do |path|
224
+ yield path
225
+
226
+ if path == @path
227
+ break
228
+ end
229
+ end
230
+ end
231
+
232
+ def normalize_path(path, relative_from = @path)
233
+ # make it relative
234
+ path = path.expand_path.relative_path_from(relative_from.expand_path)
235
+
236
+ # we can short-circuit here
237
+ return "/" if path.to_s == "."
238
+
239
+ # remove the extension
240
+ path = path.sub_ext("")
241
+
242
+ # remove index from the end
243
+ path = path.sub("index", "")
244
+
245
+ # actually normalize it
246
+ String.normalize_path(path.to_s)
247
+ end
236
248
  end
237
249
  end
238
250
  end
@@ -444,8 +444,12 @@ class StringDoc
444
444
  # Returns the node as an xml string, without transforming.
445
445
  #
446
446
  def to_s
447
- @nodes.each_with_object(String.new) do |node, string|
448
- string << node.to_s
447
+ if collapsed && empty?
448
+ collapsed
449
+ else
450
+ @nodes.each_with_object(String.new) do |node, string|
451
+ string << node.to_s
452
+ end
449
453
  end
450
454
  end
451
455
 
@@ -459,7 +463,7 @@ class StringDoc
459
463
  node.children.collapse(*significance)
460
464
  end
461
465
  else
462
- @collapsed = to_xml
466
+ @collapsed = render
463
467
  @nodes = []
464
468
  end
465
469
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pakyow-core
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.1
19
+ version: 1.0.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.1
26
+ version: 1.0.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pakyow-routing
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.1
33
+ version: 1.0.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.1
40
+ version: 1.0.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pakyow-support
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.1
47
+ version: 1.0.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.1
54
+ version: 1.0.6
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: oga
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.4'
75
+ version: '3.5'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.4'
82
+ version: '3.5'
83
83
  description: Views and presentation for Pakyow
84
84
  email: bryan@bryanp.org
85
85
  executables: []
@@ -156,7 +156,7 @@ homepage: https://pakyow.com
156
156
  licenses:
157
157
  - LGPL-3.0
158
158
  metadata: {}
159
- post_install_message:
159
+ post_install_message:
160
160
  rdoc_options: []
161
161
  require_paths:
162
162
  - lib
@@ -171,8 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.0.3
175
- signing_key:
174
+ rubygems_version: 3.1.2
175
+ signing_key:
176
176
  specification_version: 4
177
177
  summary: Pakyow Presenter
178
178
  test_files: []