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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pakyow/{presenter/actions → actions/presenter}/auto_render.rb +2 -2
  3. data/lib/pakyow/plugin/helpers/rendering.rb +15 -2
  4. data/lib/pakyow/presenter.rb +1 -1
  5. data/lib/pakyow/presenter/attributes.rb +8 -0
  6. data/lib/pakyow/presenter/attributes/attribute.rb +0 -1
  7. data/lib/pakyow/presenter/attributes/boolean.rb +0 -1
  8. data/lib/pakyow/presenter/behavior/error_rendering.rb +1 -0
  9. data/lib/pakyow/presenter/behavior/initializing.rb +1 -1
  10. data/lib/pakyow/presenter/behavior/modes.rb +1 -0
  11. data/lib/pakyow/presenter/binder.rb +2 -0
  12. data/lib/pakyow/presenter/binding_parts.rb +1 -0
  13. data/lib/pakyow/presenter/component.rb +1 -4
  14. data/lib/pakyow/presenter/composers/component.rb +1 -0
  15. data/lib/pakyow/presenter/composers/view.rb +1 -0
  16. data/lib/pakyow/presenter/errors.rb +2 -2
  17. data/lib/pakyow/presenter/framework.rb +22 -25
  18. data/lib/pakyow/presenter/presenter.rb +5 -0
  19. data/lib/pakyow/presenter/presenters/endpoint.rb +3 -3
  20. data/lib/pakyow/presenter/presenters/form.rb +5 -5
  21. data/lib/pakyow/presenter/processor.rb +42 -38
  22. data/lib/pakyow/presenter/renderer.rb +6 -1
  23. data/lib/pakyow/presenter/renderer/behavior/cleanup_prototype_nodes.rb +23 -0
  24. data/lib/pakyow/presenter/renderer/behavior/cleanup_unbound_bindings.rb +37 -0
  25. data/lib/pakyow/presenter/renderer/behavior/create_template_nodes.rb +29 -0
  26. data/lib/pakyow/presenter/renderer/behavior/insert_prototype_bar.rb +103 -0
  27. data/lib/pakyow/presenter/renderer/behavior/install_authenticity.rb +44 -0
  28. data/lib/pakyow/presenter/renderer/behavior/place_in_mode.rb +58 -0
  29. data/lib/pakyow/presenter/renderer/behavior/render_components.rb +281 -0
  30. data/lib/pakyow/presenter/renderer/behavior/set_page_title.rb +37 -0
  31. data/lib/pakyow/presenter/renderer/behavior/setup_endpoints.rb +64 -0
  32. data/lib/pakyow/presenter/renderer/behavior/setup_forms.rb +176 -0
  33. data/lib/pakyow/presenter/significant_nodes.rb +2 -2
  34. data/lib/pakyow/presenter/templates.rb +24 -15
  35. data/lib/pakyow/presenter/versioned_view.rb +1 -0
  36. data/lib/pakyow/presenter/view.rb +11 -9
  37. data/lib/pakyow/presenter/views/form.rb +39 -35
  38. data/lib/pakyow/presenter/views/layout.rb +20 -18
  39. data/lib/pakyow/presenter/views/page.rb +47 -45
  40. data/lib/pakyow/presenter/views/partial.rb +17 -15
  41. data/lib/string_doc.rb +3 -1
  42. data/lib/string_doc/attributes.rb +1 -0
  43. data/lib/string_doc/meta_attributes.rb +1 -0
  44. data/lib/string_doc/meta_node.rb +1 -0
  45. data/lib/string_doc/node.rb +1 -0
  46. metadata +19 -20
  47. data/lib/pakyow/presenter/presentable_error.rb +0 -19
  48. data/lib/pakyow/presenter/rendering/actions/cleanup_prototype_nodes.rb +0 -21
  49. data/lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb +0 -35
  50. data/lib/pakyow/presenter/rendering/actions/create_template_nodes.rb +0 -27
  51. data/lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb +0 -101
  52. data/lib/pakyow/presenter/rendering/actions/install_authenticity.rb +0 -42
  53. data/lib/pakyow/presenter/rendering/actions/place_in_mode.rb +0 -56
  54. data/lib/pakyow/presenter/rendering/actions/render_components.rb +0 -279
  55. data/lib/pakyow/presenter/rendering/actions/set_page_title.rb +0 -35
  56. data/lib/pakyow/presenter/rendering/actions/setup_endpoints.rb +0 -62
  57. data/lib/pakyow/presenter/rendering/actions/setup_forms.rb +0 -174
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Presenter
7
- module Actions
8
- module SetPageTitle
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- attach do |presenter|
13
- presenter.render node: -> {
14
- if title_value = info(:title)
15
- title.object.set_label(:title_template, title_value); title
16
- end
17
- } do
18
- self.html = html_safe(
19
- Support::StringBuilder.new(object.label(:title_template), html_safe: true) { |object_value|
20
- if respond_to?(object_value)
21
- send(object_value, :title) || send(object_value)
22
- elsif @presentables.key?(object_value)
23
- @presentables[object_value]
24
- else
25
- nil
26
- end
27
- }.build
28
- )
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/presenter/presenters/endpoint"
6
-
7
- module Pakyow
8
- module Presenter
9
- module Actions
10
- module SetupEndpoints
11
- extend Support::Extension
12
-
13
- apply_extension do
14
- build do |view, app:|
15
- view.object.find_significant_nodes(:endpoint, descend: true).each do |node|
16
- if endpoint = app.endpoints.find(name: node.label(:endpoint))
17
- node.set_label(:endpoint_object, endpoint)
18
- node.set_label(:endpoint_params, {})
19
- end
20
- end
21
- end
22
-
23
- attach do |presenter|
24
- if Pakyow.env?(:prototype)
25
- presenter.render node: -> {
26
- object.find_significant_nodes(:endpoint, descend: true).map { |node|
27
- View.from_object(node)
28
- }
29
- }, priority: :low do
30
- setup
31
- end
32
- else
33
- # Setup non-binding endpoints (binding endpoints are setup dynamically in presenter).
34
- #
35
- presenter.render node: -> {
36
- nodes = []
37
- nodes << object if object.is_a?(StringDoc::Node) && object.significant?(:endpoint)
38
- nodes.concat(object.find_significant_nodes(:endpoint))
39
- nodes.select { |node|
40
- node.labeled?(:endpoint_object)
41
- }.map { |node|
42
- View.from_object(node)
43
- }
44
- }, priority: :low do
45
- case self
46
- when Presenters::Form
47
- Presenters::Endpoint.new(__getobj__).setup
48
- when Presenters::Endpoint
49
- setup
50
- end
51
- end
52
- end
53
- end
54
-
55
- expose do |connection|
56
- connection.set(:__endpoint, connection.endpoint)
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,174 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
- require "pakyow/support/message_verifier"
5
- require "pakyow/support/safe_string"
6
-
7
- require "pakyow/presenter/presenters/form"
8
-
9
- module Pakyow
10
- module Presenter
11
- module Actions
12
- module SetupForms
13
- extend Support::Extension
14
-
15
- apply_extension do
16
- build do |view, app:|
17
- forms = view.forms
18
- if !view.object.is_a?(StringDoc) && view.object.significant?(:form)
19
- forms << view
20
- end
21
-
22
- forms.each do |form|
23
- # Allows app renders to set metadata values on forms.
24
- #
25
- form.object.set_label(:form, {})
26
-
27
- # Set the form id.
28
- #
29
- form_id = SecureRandom.hex(24)
30
- form.object.label(:form)[:id] = form_id
31
- form.object.set_label(Presenters::Form::ID_LABEL, form_id)
32
-
33
- # Set the form binding.
34
- #
35
- form.object.label(:form)[:binding] = form.object.label(:channeled_binding)
36
-
37
- # Setup field names.
38
- #
39
- form.object.children.each_significant_node(:binding) do |binding_node|
40
- if Pakyow::Presenter::Form::FIELD_TAGS.include?(binding_node.tagname)
41
- if binding_node.attributes[:name].to_s.empty?
42
- binding_node.attributes[:name] = "#{form.object.label(:binding)}[#{binding_node.label(:binding)}]"
43
- end
44
-
45
- if binding_node.tagname == "select" && binding_node.attributes[:multiple]
46
- Presenters::Form.pluralize_field_name(binding_node)
47
- end
48
- end
49
- end
50
-
51
- # Connect labels.
52
- #
53
- form.object.children.each_significant_node(:label) do |label_node|
54
- if label_node.attributes[:for] && input = form.find(*label_node.attributes[:for].to_s.split("."))
55
- Presenters::Form.connect_input_to_label(input, label_node)
56
- end
57
- end
58
-
59
- form.prepend(
60
- Support::SafeStringHelpers.html_safe(
61
- "<input type=\"hidden\" name=\"_method\">"
62
- )
63
- )
64
-
65
- form.prepend(
66
- Support::SafeStringHelpers.html_safe(
67
- "<input type=\"hidden\" name=\"_form\">"
68
- )
69
- )
70
-
71
- if app.config.presenter.embed_authenticity_token
72
- form.prepend(
73
- Support::SafeStringHelpers.html_safe(
74
- "<input type=\"hidden\" name=\"#{app.config.security.csrf.param}\">"
75
- )
76
- )
77
- end
78
- end
79
- end
80
-
81
- attach do |presenter, app:|
82
- presenter.render node: -> {
83
- forms = self.forms
84
- if !object.is_a?(StringDoc) && object.significant?(:form)
85
- forms << self
86
- end
87
-
88
- forms
89
- } do
90
- unless setup?
91
- if object = object_for_form
92
- if app.class.includes_framework?(:data) && object.is_a?(Data::Proxy)
93
- object = object.one
94
- end
95
- end
96
-
97
- if !object.nil?
98
- if labeled?(:endpoint)
99
- setup(object)
100
- else
101
- if object.key?(:id)
102
- update(object)
103
- else
104
- create(object)
105
- end
106
- end
107
- elsif labeled?(:binding)
108
- case presentables[:__endpoint_name]
109
- when :edit
110
- update(
111
- __endpoint.params.each_with_object({}) { |(key, _), passed_params|
112
- key = key.to_sym
113
- passed_params[key] = __params[key]
114
- }
115
- )
116
- else
117
- create
118
- end
119
- end
120
- end
121
-
122
- view.object.label(:form)[:origin] = presentables[:__origin]
123
-
124
- node = view.object.each_significant_node(:field).find { |field_node|
125
- field_node.attributes[:name] == "_form"
126
- }
127
-
128
- unless node.nil?
129
- node.attributes[:value] = presentables[:__verifier].sign(
130
- label(:form).to_json
131
- )
132
- end
133
- end
134
-
135
- presenter.render node: -> {
136
- stringified_param = app.config.security.csrf.param.to_s
137
- node = object.each_significant_node(:field, descend: true).find { |field_node|
138
- field_node.attributes[:name] == stringified_param
139
- }
140
-
141
- unless node.nil?
142
- View.from_object(node)
143
- end
144
- } do
145
- attributes[:value] = presentables[:__verifier].sign(Support::MessageVerifier.key)
146
- end
147
-
148
- presenter.render node: -> {
149
- object.each_significant_node(:method_override, descend: true).map { |node|
150
- View.from_object(node)
151
- }
152
- } do
153
- remove if attributes[:value].empty?
154
- end
155
- end
156
-
157
- expose do |connection|
158
- connection.set(:__params, connection.params)
159
- connection.set(:__endpoint, connection.endpoint)
160
- connection.set(:__verifier, connection.verifier)
161
-
162
- origin = if connection.set?(:__form)
163
- connection.get(:__form)[:origin]
164
- else
165
- connection.fullpath
166
- end
167
-
168
- connection.set(:__origin, origin)
169
- end
170
- end
171
- end
172
- end
173
- end
174
- end