pakyow-presenter 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pakyow/{presenter/actions → actions/presenter}/auto_render.rb +2 -2
- data/lib/pakyow/plugin/helpers/rendering.rb +15 -2
- data/lib/pakyow/presenter.rb +1 -1
- data/lib/pakyow/presenter/attributes.rb +8 -0
- data/lib/pakyow/presenter/attributes/attribute.rb +0 -1
- data/lib/pakyow/presenter/attributes/boolean.rb +0 -1
- data/lib/pakyow/presenter/behavior/error_rendering.rb +1 -0
- data/lib/pakyow/presenter/behavior/initializing.rb +1 -1
- data/lib/pakyow/presenter/behavior/modes.rb +1 -0
- data/lib/pakyow/presenter/binder.rb +2 -0
- data/lib/pakyow/presenter/binding_parts.rb +1 -0
- data/lib/pakyow/presenter/component.rb +1 -4
- data/lib/pakyow/presenter/composers/component.rb +1 -0
- data/lib/pakyow/presenter/composers/view.rb +1 -0
- data/lib/pakyow/presenter/errors.rb +2 -2
- data/lib/pakyow/presenter/framework.rb +22 -25
- data/lib/pakyow/presenter/presenter.rb +5 -0
- data/lib/pakyow/presenter/presenters/endpoint.rb +3 -3
- data/lib/pakyow/presenter/presenters/form.rb +5 -5
- data/lib/pakyow/presenter/processor.rb +42 -38
- data/lib/pakyow/presenter/renderer.rb +6 -1
- data/lib/pakyow/presenter/renderer/behavior/cleanup_prototype_nodes.rb +23 -0
- data/lib/pakyow/presenter/renderer/behavior/cleanup_unbound_bindings.rb +37 -0
- data/lib/pakyow/presenter/renderer/behavior/create_template_nodes.rb +29 -0
- data/lib/pakyow/presenter/renderer/behavior/insert_prototype_bar.rb +103 -0
- data/lib/pakyow/presenter/renderer/behavior/install_authenticity.rb +44 -0
- data/lib/pakyow/presenter/renderer/behavior/place_in_mode.rb +58 -0
- data/lib/pakyow/presenter/renderer/behavior/render_components.rb +281 -0
- data/lib/pakyow/presenter/renderer/behavior/set_page_title.rb +37 -0
- data/lib/pakyow/presenter/renderer/behavior/setup_endpoints.rb +64 -0
- data/lib/pakyow/presenter/renderer/behavior/setup_forms.rb +176 -0
- data/lib/pakyow/presenter/significant_nodes.rb +2 -2
- data/lib/pakyow/presenter/templates.rb +24 -15
- data/lib/pakyow/presenter/versioned_view.rb +1 -0
- data/lib/pakyow/presenter/view.rb +11 -9
- data/lib/pakyow/presenter/views/form.rb +39 -35
- data/lib/pakyow/presenter/views/layout.rb +20 -18
- data/lib/pakyow/presenter/views/page.rb +47 -45
- data/lib/pakyow/presenter/views/partial.rb +17 -15
- data/lib/string_doc.rb +3 -1
- data/lib/string_doc/attributes.rb +1 -0
- data/lib/string_doc/meta_attributes.rb +1 -0
- data/lib/string_doc/meta_node.rb +1 -0
- data/lib/string_doc/node.rb +1 -0
- metadata +19 -20
- data/lib/pakyow/presenter/presentable_error.rb +0 -19
- data/lib/pakyow/presenter/rendering/actions/cleanup_prototype_nodes.rb +0 -21
- data/lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb +0 -35
- data/lib/pakyow/presenter/rendering/actions/create_template_nodes.rb +0 -27
- data/lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb +0 -101
- data/lib/pakyow/presenter/rendering/actions/install_authenticity.rb +0 -42
- data/lib/pakyow/presenter/rendering/actions/place_in_mode.rb +0 -56
- data/lib/pakyow/presenter/rendering/actions/render_components.rb +0 -279
- data/lib/pakyow/presenter/rendering/actions/set_page_title.rb +0 -35
- data/lib/pakyow/presenter/rendering/actions/setup_endpoints.rb +0 -62
- data/lib/pakyow/presenter/rendering/actions/setup_forms.rb +0 -174
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2edbafe8464ab22539cb0006e33b7e621f469aea71f65f936f53ad7043e098b8
|
4
|
+
data.tar.gz: e4bbf5824d079520da80228a16a450d5e8b8591f604771d37f11ac85274a9401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3009754a80da03f010543e5dbea35e747fd09d0ede2bdfac525ed321418938853d64941c1b88442d65d5aeacdc9c67195e9e4b5377e3b0e0e4c9c181dd102d2
|
7
|
+
data.tar.gz: 0f8d79a0256297763b366307d97ca1b0aa57a6995c86bffec0c00d3ae14829ebb69c38310cba26562118d5687b593175ac36170b926a9f2299d04d8eb67cf9a3
|
@@ -9,8 +9,21 @@ module Pakyow
|
|
9
9
|
extend Support::Extension
|
10
10
|
|
11
11
|
prepend_methods do
|
12
|
-
def render(
|
13
|
-
super(File.join(@connection.app.class.mount_path,
|
12
|
+
def render(view_path = nil, as: nil, modes: [:default])
|
13
|
+
super(File.join(@connection.app.class.mount_path, view_path), as: as, modes: modes)
|
14
|
+
rescue Presenter::UnknownPage
|
15
|
+
# Try rendering the view from the app.
|
16
|
+
#
|
17
|
+
connection = @connection.app.parent.isolated(:Connection).from_connection(
|
18
|
+
@connection, :@app => @connection.app.parent
|
19
|
+
)
|
20
|
+
|
21
|
+
connection.app.isolated(:Renderer).render(
|
22
|
+
connection,
|
23
|
+
view_path: view_path,
|
24
|
+
presenter_path: as,
|
25
|
+
modes: modes
|
26
|
+
)
|
14
27
|
end
|
15
28
|
end
|
16
29
|
end
|
data/lib/pakyow/presenter.rb
CHANGED
@@ -42,15 +42,23 @@ module Pakyow
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Object for hash attributes
|
45
|
+
#
|
45
46
|
ATTRIBUTE_TYPE_HASH = Attributes::Hash
|
47
|
+
|
46
48
|
# Object for set attributes
|
49
|
+
#
|
47
50
|
ATTRIBUTE_TYPE_SET = Attributes::Set
|
51
|
+
|
48
52
|
# Object for boolean attributes
|
53
|
+
#
|
49
54
|
ATTRIBUTE_TYPE_BOOLEAN = Attributes::Boolean
|
55
|
+
|
50
56
|
# Default attribute object
|
57
|
+
#
|
51
58
|
ATTRIBUTE_TYPE_DEFAULT = Attributes::String
|
52
59
|
|
53
60
|
# Maps non-default attributes to their type
|
61
|
+
#
|
54
62
|
ATTRIBUTE_TYPES = {
|
55
63
|
class: ATTRIBUTE_TYPE_SET,
|
56
64
|
style: ATTRIBUTE_TYPE_HASH,
|
@@ -51,7 +51,7 @@ module Pakyow
|
|
51
51
|
}
|
52
52
|
|
53
53
|
if component_classes.count > 1
|
54
|
-
state(:presenter) <<
|
54
|
+
state(:presenter) << Renderer::Behavior::RenderComponents.find_or_build_compound_presenter(
|
55
55
|
self, component_classes
|
56
56
|
)
|
57
57
|
end
|
@@ -41,6 +41,7 @@ module Pakyow
|
|
41
41
|
|
42
42
|
# Returns the value for a key (including parts).
|
43
43
|
#
|
44
|
+
# @api private
|
44
45
|
def __value(key)
|
45
46
|
if @memoized.include?(key)
|
46
47
|
@memoized[key]
|
@@ -67,6 +68,7 @@ module Pakyow
|
|
67
68
|
|
68
69
|
# Returns only the content value for a key.
|
69
70
|
#
|
71
|
+
# @api private
|
70
72
|
def __content(key, view)
|
71
73
|
return_value = __value(key)
|
72
74
|
if return_value.is_a?(BindingParts)
|
@@ -7,7 +7,7 @@ require "pakyow/support/makeable/object_maker"
|
|
7
7
|
|
8
8
|
module Pakyow
|
9
9
|
module Presenter
|
10
|
-
# Reusable functionality for a component
|
10
|
+
# Reusable functionality for a view component.
|
11
11
|
#
|
12
12
|
class Component
|
13
13
|
extend Support::Makeable
|
@@ -18,7 +18,6 @@ module Pakyow
|
|
18
18
|
include Support::Hookable
|
19
19
|
events :render
|
20
20
|
|
21
|
-
# @api private
|
22
21
|
attr_reader :connection
|
23
22
|
|
24
23
|
def initialize(connection:, config: {})
|
@@ -29,8 +28,6 @@ module Pakyow
|
|
29
28
|
# intentionally empty
|
30
29
|
end
|
31
30
|
|
32
|
-
private
|
33
|
-
|
34
31
|
class << self
|
35
32
|
def presenter(&block)
|
36
33
|
@__presenter_class = Class.new(@__presenter_class) do
|
@@ -19,7 +19,7 @@ module Pakyow
|
|
19
19
|
<<~MESSAGE
|
20
20
|
Pakyow couldn't render a view for `#{String.normalize_path(@context)}`. Try creating a view template for this path:
|
21
21
|
|
22
|
-
frontend/pages#{
|
22
|
+
frontend/pages#{view_path}.html
|
23
23
|
|
24
24
|
* [Learn about view templates →](https://pakyow.com/docs/frontend/composition/)
|
25
25
|
MESSAGE
|
@@ -27,7 +27,7 @@ module Pakyow
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
30
|
+
def view_path
|
31
31
|
if @context.to_s.empty? || @context.to_s == "/"
|
32
32
|
"/index"
|
33
33
|
else
|
@@ -19,17 +19,16 @@ require "pakyow/presenter/helpers/rendering"
|
|
19
19
|
require "pakyow/presenter/renderable"
|
20
20
|
|
21
21
|
require "pakyow/presenter/renderer"
|
22
|
-
|
23
|
-
require "pakyow/presenter/
|
24
|
-
require "pakyow/presenter/
|
25
|
-
require "pakyow/presenter/
|
26
|
-
require "pakyow/presenter/
|
27
|
-
require "pakyow/presenter/
|
28
|
-
require "pakyow/presenter/
|
29
|
-
require "pakyow/presenter/
|
30
|
-
require "pakyow/presenter/
|
31
|
-
require "pakyow/presenter/
|
32
|
-
require "pakyow/presenter/rendering/actions/setup_forms"
|
22
|
+
require "pakyow/presenter/renderer/behavior/cleanup_prototype_nodes"
|
23
|
+
require "pakyow/presenter/renderer/behavior/cleanup_unbound_bindings"
|
24
|
+
require "pakyow/presenter/renderer/behavior/create_template_nodes"
|
25
|
+
require "pakyow/presenter/renderer/behavior/insert_prototype_bar"
|
26
|
+
require "pakyow/presenter/renderer/behavior/install_authenticity"
|
27
|
+
require "pakyow/presenter/renderer/behavior/place_in_mode"
|
28
|
+
require "pakyow/presenter/renderer/behavior/render_components"
|
29
|
+
require "pakyow/presenter/renderer/behavior/set_page_title"
|
30
|
+
require "pakyow/presenter/renderer/behavior/setup_endpoints"
|
31
|
+
require "pakyow/presenter/renderer/behavior/setup_forms"
|
33
32
|
|
34
33
|
module Pakyow
|
35
34
|
module Presenter
|
@@ -38,8 +37,6 @@ module Pakyow
|
|
38
37
|
using Support::Refinements::String::Normalization
|
39
38
|
|
40
39
|
def boot
|
41
|
-
require "pakyow/presenter/presentable_error"
|
42
|
-
|
43
40
|
object.class_eval do
|
44
41
|
isolate Binder
|
45
42
|
isolate Presenter
|
@@ -52,20 +49,20 @@ module Pakyow
|
|
52
49
|
end
|
53
50
|
|
54
51
|
isolate Renderer do
|
55
|
-
include
|
56
|
-
include
|
57
|
-
include
|
58
|
-
include
|
59
|
-
include
|
60
|
-
include
|
61
|
-
include
|
62
|
-
include
|
63
|
-
include
|
52
|
+
include Renderer::Behavior::CleanupPrototypeNodes
|
53
|
+
include Renderer::Behavior::CleanupUnboundBindings
|
54
|
+
include Renderer::Behavior::InsertPrototypeBar
|
55
|
+
include Renderer::Behavior::InstallAuthenticity
|
56
|
+
include Renderer::Behavior::PlaceInMode
|
57
|
+
include Renderer::Behavior::CreateTemplateNodes
|
58
|
+
include Renderer::Behavior::SetupEndpoints
|
59
|
+
include Renderer::Behavior::SetupForms
|
60
|
+
include Renderer::Behavior::SetPageTitle
|
64
61
|
end
|
65
62
|
|
66
63
|
after "load" do
|
67
64
|
isolated(:Renderer) do
|
68
|
-
include
|
65
|
+
include Renderer::Behavior::RenderComponents
|
69
66
|
end
|
70
67
|
end
|
71
68
|
|
@@ -96,7 +93,7 @@ module Pakyow
|
|
96
93
|
include Behavior::ImplicitRendering
|
97
94
|
|
98
95
|
action :verify_form_metadata do
|
99
|
-
if metadata = params[:
|
96
|
+
if metadata = params[:"pw-form"]
|
100
97
|
connection.set(
|
101
98
|
:__form,
|
102
99
|
JSON.parse(
|
@@ -104,7 +101,7 @@ module Pakyow
|
|
104
101
|
).indifferentize
|
105
102
|
)
|
106
103
|
|
107
|
-
params.delete(:
|
104
|
+
params.delete(:"pw-form")
|
108
105
|
end
|
109
106
|
end
|
110
107
|
end
|
@@ -48,6 +48,7 @@ module Pakyow
|
|
48
48
|
|
49
49
|
# The app object.
|
50
50
|
#
|
51
|
+
# @api private
|
51
52
|
attr_reader :app
|
52
53
|
|
53
54
|
def initialize(view, app:, presentables: {})
|
@@ -76,6 +77,7 @@ module Pakyow
|
|
76
77
|
# Returns an array of presenters, one for each view binding.
|
77
78
|
#
|
78
79
|
# @see View#find_all
|
80
|
+
# @api private
|
79
81
|
def find_all(*names)
|
80
82
|
@view.find_all(*names).map { |view|
|
81
83
|
presenter_for(view)
|
@@ -94,6 +96,7 @@ module Pakyow
|
|
94
96
|
|
95
97
|
# Returns all forms.
|
96
98
|
#
|
99
|
+
# @api private
|
97
100
|
def forms
|
98
101
|
@view.forms.map { |form|
|
99
102
|
presenter_for(form)
|
@@ -112,6 +115,7 @@ module Pakyow
|
|
112
115
|
|
113
116
|
# Returns all components.
|
114
117
|
#
|
118
|
+
# @api private
|
115
119
|
def components(renderable: false)
|
116
120
|
@view.components(renderable: renderable).map { |component|
|
117
121
|
presenter_for(component)
|
@@ -583,6 +587,7 @@ module Pakyow
|
|
583
587
|
|
584
588
|
attr_reader :path
|
585
589
|
|
590
|
+
# @api private
|
586
591
|
def make(path, **kwargs, &block)
|
587
592
|
path = String.normalize_path(path)
|
588
593
|
super(path, path: path, **kwargs, &block)
|
@@ -76,9 +76,9 @@ module Pakyow
|
|
76
76
|
if endpoint_action_presenter.attributes.has?(:href)
|
77
77
|
endpoint_path = __endpoint[:path].to_s
|
78
78
|
if endpoint_path == endpoint_action_presenter.attributes[:href]
|
79
|
-
attributes[:class].add(:current)
|
79
|
+
attributes[:class].add(:"ui-current")
|
80
80
|
elsif endpoint_path.start_with?(endpoint_action_presenter.attributes[:href])
|
81
|
-
attributes[:class].add(:active)
|
81
|
+
attributes[:class].add(:"ui-active")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
when "form"
|
@@ -99,7 +99,7 @@ module Pakyow
|
|
99
99
|
View.new(
|
100
100
|
<<~HTML
|
101
101
|
<form action="#{path}" method="post" data-ui="confirmable">
|
102
|
-
<input type="hidden" name="
|
102
|
+
<input type="hidden" name="pw-http-method" value="delete">
|
103
103
|
#{view.object.render}
|
104
104
|
</form>
|
105
105
|
HTML
|
@@ -70,7 +70,7 @@ module Pakyow
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# Sets the form method. Automatically handles method overrides by prepending a hidden field
|
73
|
-
# named `
|
73
|
+
# named `pw-http-method` when +method+ is not get or post, setting the form method to +post+.
|
74
74
|
#
|
75
75
|
def method=(method)
|
76
76
|
method = method.to_s.downcase
|
@@ -212,7 +212,7 @@ module Pakyow
|
|
212
212
|
def use_binding_nodes
|
213
213
|
view.object.set_label(:bound, true)
|
214
214
|
view.object.children.each_significant_node(:binding, descend: true) do |object|
|
215
|
-
if Pakyow::Presenter::Form::FIELD_TAGS.include?(object.tagname)
|
215
|
+
if Pakyow::Presenter::Views::Form::FIELD_TAGS.include?(object.tagname)
|
216
216
|
object.set_label(:bound, true)
|
217
217
|
end
|
218
218
|
end
|
@@ -269,7 +269,7 @@ module Pakyow
|
|
269
269
|
end
|
270
270
|
|
271
271
|
def method_override_input
|
272
|
-
html_safe("<input type=\"hidden\" name=\"
|
272
|
+
html_safe("<input type=\"hidden\" name=\"pw-http-method\">")
|
273
273
|
end
|
274
274
|
|
275
275
|
def find_or_create_method_override_input
|
@@ -337,7 +337,7 @@ module Pakyow
|
|
337
337
|
values = Array.ensure(values).compact
|
338
338
|
|
339
339
|
if values.any?
|
340
|
-
field_view = Pakyow::Presenter::Form.from_object(field_presenter.view.object)
|
340
|
+
field_view = Pakyow::Presenter::Views::Form.from_object(field_presenter.view.object)
|
341
341
|
field_template = field_view.dup
|
342
342
|
insertable_field = field_view
|
343
343
|
current_field = field_view
|
@@ -361,7 +361,7 @@ module Pakyow
|
|
361
361
|
values = Array.ensure(original_values).compact
|
362
362
|
|
363
363
|
if values.any?
|
364
|
-
field_view = Pakyow::Presenter::Form.from_object(field_presenter.view.object)
|
364
|
+
field_view = Pakyow::Presenter::Views::Form.from_object(field_presenter.view.object)
|
365
365
|
template = field_view.dup
|
366
366
|
insertable = field_view
|
367
367
|
current = field_view
|
@@ -4,44 +4,6 @@ require "pakyow/support/class_state"
|
|
4
4
|
|
5
5
|
module Pakyow
|
6
6
|
module Presenter
|
7
|
-
class ProcessorCaller
|
8
|
-
def initialize(instances)
|
9
|
-
@processors = normalize(instances)
|
10
|
-
end
|
11
|
-
|
12
|
-
def process(content, extension)
|
13
|
-
processors_for_extension(extension).each do |processor|
|
14
|
-
content = processor.call(content)
|
15
|
-
end
|
16
|
-
|
17
|
-
unless extension == :html
|
18
|
-
processors_for_extension(:html).each do |processor|
|
19
|
-
content = processor.call(content)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
content
|
24
|
-
end
|
25
|
-
|
26
|
-
def process?(extension)
|
27
|
-
@processors.key?(extension.tr(".", "").to_sym)
|
28
|
-
end
|
29
|
-
|
30
|
-
protected
|
31
|
-
|
32
|
-
def processors_for_extension(extension)
|
33
|
-
@processors[extension] || []
|
34
|
-
end
|
35
|
-
|
36
|
-
def normalize(instances)
|
37
|
-
instances.each_with_object({}) { |instance, processors|
|
38
|
-
instance.class.extensions.each do |extension|
|
39
|
-
(processors[extension] ||= []) << instance
|
40
|
-
end
|
41
|
-
}
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
7
|
class Processor
|
46
8
|
extend Support::ClassState
|
47
9
|
class_state :name
|
@@ -59,6 +21,7 @@ module Pakyow
|
|
59
21
|
end
|
60
22
|
|
61
23
|
class << self
|
24
|
+
# @api private
|
62
25
|
def make(name, *extensions, **kwargs, &block)
|
63
26
|
# Name is expected to also be an extension.
|
64
27
|
#
|
@@ -81,5 +44,46 @@ module Pakyow
|
|
81
44
|
end
|
82
45
|
end
|
83
46
|
end
|
47
|
+
|
48
|
+
# @api private
|
49
|
+
class ProcessorCaller
|
50
|
+
def initialize(instances)
|
51
|
+
@processors = normalize(instances)
|
52
|
+
end
|
53
|
+
|
54
|
+
def process(content, extension)
|
55
|
+
content = content.to_s
|
56
|
+
|
57
|
+
processors_for_extension(extension).each do |processor|
|
58
|
+
content = processor.call(content)
|
59
|
+
end
|
60
|
+
|
61
|
+
unless extension == :html
|
62
|
+
processors_for_extension(:html).each do |processor|
|
63
|
+
content = processor.call(content)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
content
|
68
|
+
end
|
69
|
+
|
70
|
+
def process?(extension)
|
71
|
+
@processors.key?(extension.tr(".", "").to_sym)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def processors_for_extension(extension)
|
77
|
+
@processors[extension] || []
|
78
|
+
end
|
79
|
+
|
80
|
+
def normalize(instances)
|
81
|
+
instances.each_with_object({}) { |instance, processors|
|
82
|
+
instance.class.extensions.each do |extension|
|
83
|
+
(processors[extension] ||= []) << instance
|
84
|
+
end
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
84
88
|
end
|
85
89
|
end
|