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
@@ -2,55 +2,59 @@
|
|
2
2
|
|
3
3
|
require "pakyow/support/core_refinements/array/ensurable"
|
4
4
|
|
5
|
+
require "pakyow/presenter/view"
|
6
|
+
|
5
7
|
module Pakyow
|
6
8
|
module Presenter
|
7
|
-
|
8
|
-
|
9
|
+
module Views
|
10
|
+
class Form < View
|
11
|
+
using Support::Refinements::Array::Ensurable
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
INPUT_TAG = "input"
|
14
|
+
SELECT_TAG = "select"
|
15
|
+
TEXTAREA_TAG = "textarea"
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
FIELD_TAGS = [
|
18
|
+
INPUT_TAG,
|
19
|
+
SELECT_TAG,
|
20
|
+
TEXTAREA_TAG
|
21
|
+
].freeze
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
CHECKBOX_TYPE = "checkbox"
|
24
|
+
RADIO_TYPE = "radio"
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
CHECKED_TYPES = [
|
27
|
+
CHECKBOX_TYPE, RADIO_TYPE
|
28
|
+
].freeze
|
26
29
|
|
27
|
-
|
30
|
+
private
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
def bind_value_to_node(value, node)
|
33
|
+
super
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
if node.tagname == SELECT_TAG
|
36
|
+
select_option_with_value(value, View.from_object(node))
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
39
|
+
if CHECKED_TYPES.include?(node.attributes[:type])
|
40
|
+
check_or_uncheck_value(value, View.from_object(node))
|
41
|
+
end
|
38
42
|
end
|
39
|
-
end
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def check_or_uncheck_value(value, view)
|
45
|
+
if view.attributes[:type] == "checkbox"
|
46
|
+
# There could be multiple values checked, so check for inclusion.
|
47
|
+
#
|
48
|
+
view.attributes[:checked] = Array.ensure(value).map(&:to_s).include?(view.attributes[:value])
|
49
|
+
else
|
50
|
+
view.attributes[:checked] = view.attributes[:value] == value.to_s
|
51
|
+
end
|
48
52
|
end
|
49
|
-
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
def select_option_with_value(value, view)
|
55
|
+
view.object.each_significant_node(:option) do |option|
|
56
|
+
View.from_object(option).attributes[:selected] = option.attributes[:value] == value
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -2,30 +2,32 @@
|
|
2
2
|
|
3
3
|
module Pakyow
|
4
4
|
module Presenter
|
5
|
-
|
6
|
-
|
5
|
+
module Views
|
6
|
+
class Layout < View
|
7
|
+
attr_accessor :name
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class << self
|
10
|
+
def load(path, content: nil, **args)
|
11
|
+
self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args)
|
12
|
+
end
|
11
13
|
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(name, html = "", **args)
|
15
|
-
@name = name
|
16
|
-
super(html, **args)
|
17
|
-
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def initialize(name, html = "", **args)
|
16
|
+
@name = name
|
17
|
+
super(html, **args)
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
container_node.replace(page.content(container_node.label(:container)))
|
20
|
+
def container(name = Views::Page::DEFAULT_CONTAINER)
|
21
|
+
@object.container(name.to_sym)
|
26
22
|
end
|
27
23
|
|
28
|
-
|
24
|
+
def build(page)
|
25
|
+
@object.each_significant_node(:container) do |container_node|
|
26
|
+
container_node.replace(page.content(container_node.label(:container)))
|
27
|
+
end
|
28
|
+
|
29
|
+
View.from_object(@object).add_info(info, page.info)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -4,68 +4,70 @@ require "yaml"
|
|
4
4
|
|
5
5
|
module Pakyow
|
6
6
|
module Presenter
|
7
|
-
|
8
|
-
|
7
|
+
module Views
|
8
|
+
class Page < View
|
9
|
+
DEFAULT_CONTAINER = :main
|
9
10
|
|
10
|
-
|
11
|
+
attr_reader :name, :path
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
class << self
|
14
|
+
def load(path, content: nil, **args)
|
15
|
+
self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args, path: path)
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
def initialize(name, html = "", path: nil, info: {}, **args)
|
20
|
+
@containers = {}
|
21
|
+
parse_content(html)
|
22
|
+
@name, @path = name, path
|
23
|
+
info[:layout] ||= :default
|
24
|
+
super(html, info: info, **args)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
def initialize_copy(_)
|
28
|
+
super
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
@containers = Hash[@containers.map { |key, value|
|
31
|
+
[key, value.dup]
|
32
|
+
}]
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
def content(container)
|
36
|
+
container = container.to_sym
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
if container == DEFAULT_CONTAINER
|
39
|
+
@object
|
40
|
+
elsif @containers.key?(container)
|
41
|
+
@containers[container].object
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
def mixin(partials)
|
48
|
+
super
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
@containers.values.each do |view|
|
51
|
+
view.mixin(partials)
|
52
|
+
end
|
51
53
|
end
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def container_views
|
56
|
+
[View.from_object(@object)].concat(@containers.values)
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
+
private
|
59
60
|
|
60
|
-
|
61
|
+
WITHIN_REGEX = /<!--\s*@within\s*([a-zA-Z0-9\-_]*)\s*-->(.*?)<!--\s*\/within\s*-->/m
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
def parse_content(html)
|
64
|
+
html.scan(WITHIN_REGEX) do |match|
|
65
|
+
container_name = match[0].to_sym
|
66
|
+
@containers[container_name] = View.from_object(StringDoc.new(match[1]))
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
+
html.gsub!(WITHIN_REGEX, "")
|
70
|
+
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
@@ -2,26 +2,28 @@
|
|
2
2
|
|
3
3
|
module Pakyow
|
4
4
|
module Presenter
|
5
|
-
|
6
|
-
|
5
|
+
module Views
|
6
|
+
class Partial < View
|
7
|
+
attr_accessor :name
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
class << self
|
10
|
+
def load(path, content: nil, **args)
|
11
|
+
name = File.basename(path, ".*")
|
12
|
+
name = name[1..-1] if name.start_with?("_")
|
13
|
+
self.new(name.to_sym, content || File.read(path), **args)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def from_object(name, object)
|
17
|
+
super(object).tap do |instance|
|
18
|
+
instance.instance_variable_set(:@name, name)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def initialize(name, html = "", **args)
|
24
|
+
@name = name
|
25
|
+
super(html, **args)
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/string_doc.rb
CHANGED
@@ -23,6 +23,8 @@ require "pakyow/support/silenceable"
|
|
23
23
|
# only when a longer parse time is acceptable and you only care about a handful of identifiable
|
24
24
|
# nodes in a document.
|
25
25
|
#
|
26
|
+
# @api private
|
27
|
+
#
|
26
28
|
class StringDoc
|
27
29
|
require "string_doc/attributes"
|
28
30
|
require "string_doc/node"
|
@@ -563,7 +565,7 @@ class StringDoc
|
|
563
565
|
labels = significance.each_with_object({}) { |significant_type, labels_hash|
|
564
566
|
# FIXME: remove this special case logic
|
565
567
|
labels_hash[significant_type] = if name.empty? && significant_type == :container
|
566
|
-
Pakyow::Presenter::Page::DEFAULT_CONTAINER
|
568
|
+
Pakyow::Presenter::Views::Page::DEFAULT_CONTAINER
|
567
569
|
else
|
568
570
|
name.to_sym
|
569
571
|
end
|
data/lib/string_doc/meta_node.rb
CHANGED
data/lib/string_doc/node.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakyow-presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-07-
|
12
|
+
date: 2019-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pakyow-core
|
@@ -17,42 +17,42 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.0.0.
|
20
|
+
version: 1.0.0.rc3
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.0.0.
|
27
|
+
version: 1.0.0.rc3
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: pakyow-routing
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '='
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.0.0.
|
34
|
+
version: 1.0.0.rc3
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - '='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.0.0.
|
41
|
+
version: 1.0.0.rc3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: pakyow-support
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.0.0.
|
48
|
+
version: 1.0.0.rc3
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - '='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.0.0.
|
55
|
+
version: 1.0.0.rc3
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: oga
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,11 +90,11 @@ files:
|
|
90
90
|
- CHANGELOG.md
|
91
91
|
- LICENSE
|
92
92
|
- README.md
|
93
|
+
- lib/pakyow/actions/presenter/auto_render.rb
|
93
94
|
- lib/pakyow/generators/presenter/presenter_generator.rb
|
94
95
|
- lib/pakyow/generators/presenter/templates/presenter.rb.tt
|
95
96
|
- lib/pakyow/plugin/helpers/rendering.rb
|
96
97
|
- lib/pakyow/presenter.rb
|
97
|
-
- lib/pakyow/presenter/actions/auto_render.rb
|
98
98
|
- lib/pakyow/presenter/attributes.rb
|
99
99
|
- lib/pakyow/presenter/attributes/attribute.rb
|
100
100
|
- lib/pakyow/presenter/attributes/boolean.rb
|
@@ -119,23 +119,22 @@ files:
|
|
119
119
|
- lib/pakyow/presenter/front_matter_parser.rb
|
120
120
|
- lib/pakyow/presenter/helpers/rendering.rb
|
121
121
|
- lib/pakyow/presenter/presentable.rb
|
122
|
-
- lib/pakyow/presenter/presentable_error.rb
|
123
122
|
- lib/pakyow/presenter/presenter.rb
|
124
123
|
- lib/pakyow/presenter/presenters/endpoint.rb
|
125
124
|
- lib/pakyow/presenter/presenters/form.rb
|
126
125
|
- lib/pakyow/presenter/processor.rb
|
127
126
|
- lib/pakyow/presenter/renderable.rb
|
128
127
|
- lib/pakyow/presenter/renderer.rb
|
129
|
-
- lib/pakyow/presenter/
|
130
|
-
- lib/pakyow/presenter/
|
131
|
-
- lib/pakyow/presenter/
|
132
|
-
- lib/pakyow/presenter/
|
133
|
-
- lib/pakyow/presenter/
|
134
|
-
- lib/pakyow/presenter/
|
135
|
-
- lib/pakyow/presenter/
|
136
|
-
- lib/pakyow/presenter/
|
137
|
-
- lib/pakyow/presenter/
|
138
|
-
- lib/pakyow/presenter/
|
128
|
+
- lib/pakyow/presenter/renderer/behavior/cleanup_prototype_nodes.rb
|
129
|
+
- lib/pakyow/presenter/renderer/behavior/cleanup_unbound_bindings.rb
|
130
|
+
- lib/pakyow/presenter/renderer/behavior/create_template_nodes.rb
|
131
|
+
- lib/pakyow/presenter/renderer/behavior/insert_prototype_bar.rb
|
132
|
+
- lib/pakyow/presenter/renderer/behavior/install_authenticity.rb
|
133
|
+
- lib/pakyow/presenter/renderer/behavior/place_in_mode.rb
|
134
|
+
- lib/pakyow/presenter/renderer/behavior/render_components.rb
|
135
|
+
- lib/pakyow/presenter/renderer/behavior/set_page_title.rb
|
136
|
+
- lib/pakyow/presenter/renderer/behavior/setup_endpoints.rb
|
137
|
+
- lib/pakyow/presenter/renderer/behavior/setup_forms.rb
|
139
138
|
- lib/pakyow/presenter/significant_nodes.rb
|
140
139
|
- lib/pakyow/presenter/templates.rb
|
141
140
|
- lib/pakyow/presenter/versioned_view.rb
|