pakyow-presenter 0.11.3 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{pakyow-presenter/CHANGELOG.md → CHANGELOG.md} +0 -5
- data/LICENSE +4 -0
- data/{pakyow-presenter/README.md → README.md} +1 -2
- data/lib/pakyow/generators/presenter/presenter_generator.rb +28 -0
- data/lib/pakyow/generators/presenter/templates/presenter.rb.tt +2 -0
- data/lib/pakyow/plugin/helpers/rendering.rb +19 -0
- data/lib/pakyow/presenter/actions/auto_render.rb +15 -0
- data/lib/pakyow/presenter/attributes/attribute.rb +22 -0
- data/lib/pakyow/presenter/attributes/boolean.rb +24 -0
- data/lib/pakyow/presenter/attributes/hash.rb +89 -0
- data/lib/pakyow/presenter/attributes/set.rb +61 -0
- data/lib/pakyow/presenter/attributes/string.rb +38 -0
- data/lib/pakyow/presenter/attributes.rb +126 -0
- data/lib/pakyow/presenter/behavior/config.rb +29 -0
- data/lib/pakyow/presenter/behavior/error_rendering.rb +124 -0
- data/lib/pakyow/presenter/behavior/exposures.rb +29 -0
- data/lib/pakyow/presenter/behavior/implicit_rendering.rb +21 -0
- data/lib/pakyow/presenter/behavior/initializing.rb +37 -0
- data/lib/pakyow/presenter/behavior/modes.rb +117 -0
- data/lib/pakyow/presenter/behavior/versions.rb +71 -0
- data/lib/pakyow/presenter/behavior/watching.rb +21 -0
- data/lib/pakyow/presenter/binder.rb +115 -0
- data/lib/pakyow/presenter/binding_parts.rb +64 -0
- data/lib/pakyow/presenter/component.rb +74 -0
- data/lib/pakyow/presenter/composers/component.rb +78 -0
- data/lib/pakyow/presenter/composers/view.rb +73 -0
- data/lib/pakyow/presenter/errors.rb +63 -0
- data/lib/pakyow/presenter/framework.rb +203 -0
- data/lib/pakyow/presenter/front_matter_parser.rb +42 -0
- data/lib/pakyow/presenter/helpers/rendering.rb +18 -0
- data/lib/pakyow/presenter/presentable.rb +28 -0
- data/lib/pakyow/presenter/presentable_error.rb +19 -0
- data/lib/pakyow/presenter/presenter.rb +766 -0
- data/lib/pakyow/presenter/presenters/endpoint.rb +158 -0
- data/lib/pakyow/presenter/presenters/form.rb +522 -0
- data/lib/pakyow/presenter/processor.rb +61 -0
- data/lib/pakyow/presenter/renderable.rb +28 -0
- data/lib/pakyow/presenter/renderer.rb +269 -0
- data/lib/pakyow/presenter/rendering/actions/cleanup_prototype_nodes.rb +21 -0
- data/lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb +35 -0
- data/lib/pakyow/presenter/rendering/actions/create_template_nodes.rb +27 -0
- data/lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb +101 -0
- data/lib/pakyow/presenter/rendering/actions/install_authenticity.rb +42 -0
- data/lib/pakyow/presenter/rendering/actions/place_in_mode.rb +56 -0
- data/lib/pakyow/presenter/rendering/actions/render_components.rb +279 -0
- data/lib/pakyow/presenter/rendering/actions/set_page_title.rb +35 -0
- data/lib/pakyow/presenter/rendering/actions/setup_endpoints.rb +62 -0
- data/lib/pakyow/presenter/rendering/actions/setup_forms.rb +174 -0
- data/lib/pakyow/presenter/significant_nodes.rb +309 -0
- data/lib/pakyow/presenter/templates.rb +229 -0
- data/lib/pakyow/presenter/versioned_view.rb +209 -0
- data/lib/pakyow/presenter/view.rb +586 -0
- data/lib/pakyow/presenter/views/form.rb +58 -0
- data/lib/pakyow/presenter/views/layout.rb +32 -0
- data/lib/pakyow/presenter/views/page.rb +72 -0
- data/lib/pakyow/presenter/views/partial.rb +28 -0
- data/lib/pakyow/presenter.rb +33 -0
- data/lib/pakyow/views/errors/layouts/development_error.html +102 -0
- data/lib/pakyow/views/errors/layouts/production_error.html +27 -0
- data/lib/pakyow/views/errors/pages/404.html +12 -0
- data/lib/pakyow/views/errors/pages/500.html +12 -0
- data/lib/pakyow/views/errors/pages/development/500.html +39 -0
- data/lib/string_doc/attributes.rb +109 -0
- data/lib/string_doc/meta_attributes.rb +48 -0
- data/lib/string_doc/meta_node.rb +328 -0
- data/lib/string_doc/node.rb +377 -0
- data/lib/string_doc.rb +642 -0
- metadata +95 -75
- data/pakyow-presenter/LICENSE +0 -20
- data/pakyow-presenter/lib/pakyow/presenter/attributes.rb +0 -228
- data/pakyow-presenter/lib/pakyow/presenter/base.rb +0 -38
- data/pakyow-presenter/lib/pakyow/presenter/binder.rb +0 -116
- data/pakyow-presenter/lib/pakyow/presenter/binder_set.rb +0 -94
- data/pakyow-presenter/lib/pakyow/presenter/binding_eval.rb +0 -37
- data/pakyow-presenter/lib/pakyow/presenter/config/presenter.rb +0 -42
- data/pakyow-presenter/lib/pakyow/presenter/container.rb +0 -6
- data/pakyow-presenter/lib/pakyow/presenter/doc_helpers.rb +0 -17
- data/pakyow-presenter/lib/pakyow/presenter/exceptions.rb +0 -11
- data/pakyow-presenter/lib/pakyow/presenter/ext/app.rb +0 -33
- data/pakyow-presenter/lib/pakyow/presenter/ext/call_context.rb +0 -28
- data/pakyow-presenter/lib/pakyow/presenter/helpers.rb +0 -46
- data/pakyow-presenter/lib/pakyow/presenter/page.rb +0 -110
- data/pakyow-presenter/lib/pakyow/presenter/partial.rb +0 -6
- data/pakyow-presenter/lib/pakyow/presenter/presenter.rb +0 -232
- data/pakyow-presenter/lib/pakyow/presenter/string_doc.rb +0 -380
- data/pakyow-presenter/lib/pakyow/presenter/string_doc_parser.rb +0 -144
- data/pakyow-presenter/lib/pakyow/presenter/string_doc_renderer.rb +0 -18
- data/pakyow-presenter/lib/pakyow/presenter/template.rb +0 -51
- data/pakyow-presenter/lib/pakyow/presenter/view.rb +0 -541
- data/pakyow-presenter/lib/pakyow/presenter/view_collection.rb +0 -330
- data/pakyow-presenter/lib/pakyow/presenter/view_composer.rb +0 -237
- data/pakyow-presenter/lib/pakyow/presenter/view_context.rb +0 -111
- data/pakyow-presenter/lib/pakyow/presenter/view_store.rb +0 -262
- data/pakyow-presenter/lib/pakyow/presenter/view_store_loader.rb +0 -43
- data/pakyow-presenter/lib/pakyow/presenter/view_version.rb +0 -113
- data/pakyow-presenter/lib/pakyow/presenter.rb +0 -8
- data/pakyow-presenter/lib/pakyow/views/errors/404.erb +0 -26
- data/pakyow-presenter/lib/pakyow/views/errors/500.erb +0 -23
- data/pakyow-presenter/lib/pakyow-presenter.rb +0 -1
@@ -0,0 +1,209 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
4
|
+
|
5
|
+
module Pakyow
|
6
|
+
module Presenter
|
7
|
+
# Wraps one or more versioned view objects. Provides an interface for manipulating multiple
|
8
|
+
# view versions as if they were a single object, picking one to use for presentation.
|
9
|
+
#
|
10
|
+
class VersionedView < SimpleDelegator
|
11
|
+
DEFAULT_VERSION = :default
|
12
|
+
|
13
|
+
attr_reader :names
|
14
|
+
|
15
|
+
def initialize(versions)
|
16
|
+
@versions = versions
|
17
|
+
@names = self.versions.map { |versioned_view| versioned_view.label(:version) }
|
18
|
+
determine_working_version
|
19
|
+
@used = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize_dup(_)
|
23
|
+
super
|
24
|
+
|
25
|
+
@versions = @versions.map(&:dup)
|
26
|
+
@names = @names.map(&:dup)
|
27
|
+
determine_working_version
|
28
|
+
end
|
29
|
+
|
30
|
+
def soft_copy
|
31
|
+
instance = self.class.allocate
|
32
|
+
|
33
|
+
instance.instance_variable_set(:@versions, @versions.map { |version|
|
34
|
+
version.soft_copy
|
35
|
+
})
|
36
|
+
|
37
|
+
instance.instance_variable_set(:@names, @names)
|
38
|
+
instance.instance_variable_set(:@used, @used)
|
39
|
+
instance.send(:determine_working_version)
|
40
|
+
|
41
|
+
instance
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns true if +version+ exists.
|
45
|
+
#
|
46
|
+
def version?(version)
|
47
|
+
!!version_named(version.to_sym)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the view matching +version+.
|
51
|
+
#
|
52
|
+
def versioned(version)
|
53
|
+
if versioned = version_named(version.to_sym)
|
54
|
+
case versioned.object
|
55
|
+
when StringDoc::MetaNode
|
56
|
+
node = versioned.object.nodes.find { |n|
|
57
|
+
version == (n.label(:version) || DEFAULT_VERSION).to_sym
|
58
|
+
}
|
59
|
+
|
60
|
+
View.from_object(node)
|
61
|
+
else
|
62
|
+
versioned
|
63
|
+
end
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Uses the view matching +version+, removing all other versions.
|
70
|
+
#
|
71
|
+
def use(version)
|
72
|
+
version = version.to_sym
|
73
|
+
|
74
|
+
tap do
|
75
|
+
if view = version_named(version)
|
76
|
+
case view.object
|
77
|
+
when StringDoc::MetaNode
|
78
|
+
versioned_node = view.object.internal_nodes.find { |node|
|
79
|
+
version == (node.label(:version) || DEFAULT_VERSION).to_sym
|
80
|
+
}
|
81
|
+
|
82
|
+
versioned_node.set_label(:versioned, true)
|
83
|
+
else
|
84
|
+
view.object.set_label(:versioned, true)
|
85
|
+
end
|
86
|
+
|
87
|
+
self.versioned_view = view
|
88
|
+
|
89
|
+
cleanup
|
90
|
+
else
|
91
|
+
cleanup(all: true)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def transform(object)
|
97
|
+
@versions.each do |version|
|
98
|
+
version.transform(object)
|
99
|
+
end
|
100
|
+
|
101
|
+
yield self, object if block_given?
|
102
|
+
end
|
103
|
+
|
104
|
+
def bind(object)
|
105
|
+
@versions.each do |version|
|
106
|
+
version.bind(object)
|
107
|
+
end
|
108
|
+
|
109
|
+
yield self, object if block_given?
|
110
|
+
end
|
111
|
+
|
112
|
+
def used?
|
113
|
+
@versions.any? { |versioned_view|
|
114
|
+
case versioned_view.object
|
115
|
+
when StringDoc::MetaNode
|
116
|
+
versioned_view.object.nodes.any? { |node|
|
117
|
+
node.labeled?(:versioned)
|
118
|
+
}
|
119
|
+
else
|
120
|
+
versioned_view.object.labeled?(:versioned)
|
121
|
+
end
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
def versions
|
126
|
+
@versions.each_with_object([]) { |versioned_view, versions|
|
127
|
+
case versioned_view.object
|
128
|
+
when StringDoc::MetaNode
|
129
|
+
versioned_view.object.nodes.each do |node|
|
130
|
+
versions << View.from_object(node)
|
131
|
+
end
|
132
|
+
else
|
133
|
+
versions << versioned_view
|
134
|
+
end
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
# Fixes an issue using pp inside a delegator.
|
139
|
+
#
|
140
|
+
def pp(*args)
|
141
|
+
Kernel.pp(*args)
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def cleanup(all: false)
|
147
|
+
if all
|
148
|
+
while version = @versions.shift
|
149
|
+
version.remove
|
150
|
+
end
|
151
|
+
else
|
152
|
+
versions_to_remove = []
|
153
|
+
|
154
|
+
@versions.each do |versioned_view|
|
155
|
+
case versioned_view.object
|
156
|
+
when StringDoc::MetaNode
|
157
|
+
nodes_to_remove = []
|
158
|
+
|
159
|
+
versioned_view.object.internal_nodes.each do |node|
|
160
|
+
if !node.is_a?(StringDoc::MetaNode) && !node.labeled?(:versioned)
|
161
|
+
nodes_to_remove << node
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
nodes_to_remove.each(&:remove)
|
166
|
+
else
|
167
|
+
unless versioned_view.object.labeled?(:versioned)
|
168
|
+
versions_to_remove << versioned_view
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
versions_to_remove.each do |versioned_view|
|
174
|
+
versioned_view.remove; @versions.delete(versioned_view)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def determine_working_version
|
180
|
+
self.versioned_view = default_version
|
181
|
+
end
|
182
|
+
|
183
|
+
def versioned_view=(view)
|
184
|
+
__setobj__(view)
|
185
|
+
end
|
186
|
+
|
187
|
+
def default_version
|
188
|
+
version_named(DEFAULT_VERSION) || first_version
|
189
|
+
end
|
190
|
+
|
191
|
+
def version_named(version)
|
192
|
+
@versions.find { |view|
|
193
|
+
case view.object
|
194
|
+
when StringDoc::MetaNode
|
195
|
+
view.object.internal_nodes.any? { |node|
|
196
|
+
version == (node.label(:version) || DEFAULT_VERSION).to_sym
|
197
|
+
}
|
198
|
+
else
|
199
|
+
view.version == version
|
200
|
+
end
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
204
|
+
def first_version
|
205
|
+
@versions[0]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|