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
@@ -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
- class Form < View
8
- using Support::Refinements::Array::Ensurable
9
+ module Views
10
+ class Form < View
11
+ using Support::Refinements::Array::Ensurable
9
12
 
10
- INPUT_TAG = "input"
11
- SELECT_TAG = "select"
12
- TEXTAREA_TAG = "textarea"
13
+ INPUT_TAG = "input"
14
+ SELECT_TAG = "select"
15
+ TEXTAREA_TAG = "textarea"
13
16
 
14
- FIELD_TAGS = [
15
- INPUT_TAG,
16
- SELECT_TAG,
17
- TEXTAREA_TAG
18
- ].freeze
17
+ FIELD_TAGS = [
18
+ INPUT_TAG,
19
+ SELECT_TAG,
20
+ TEXTAREA_TAG
21
+ ].freeze
19
22
 
20
- CHECKBOX_TYPE = "checkbox"
21
- RADIO_TYPE = "radio"
23
+ CHECKBOX_TYPE = "checkbox"
24
+ RADIO_TYPE = "radio"
22
25
 
23
- CHECKED_TYPES = [
24
- CHECKBOX_TYPE, RADIO_TYPE
25
- ].freeze
26
+ CHECKED_TYPES = [
27
+ CHECKBOX_TYPE, RADIO_TYPE
28
+ ].freeze
26
29
 
27
- private
30
+ private
28
31
 
29
- def bind_value_to_node(value, node)
30
- super
32
+ def bind_value_to_node(value, node)
33
+ super
31
34
 
32
- if node.tagname == SELECT_TAG
33
- select_option_with_value(value, View.from_object(node))
34
- end
35
+ if node.tagname == SELECT_TAG
36
+ select_option_with_value(value, View.from_object(node))
37
+ end
35
38
 
36
- if CHECKED_TYPES.include?(node.attributes[:type])
37
- check_or_uncheck_value(value, View.from_object(node))
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
- def check_or_uncheck_value(value, view)
42
- if view.attributes[:type] == "checkbox"
43
- # There could be multiple values checked, so check for inclusion.
44
- #
45
- view.attributes[:checked] = Array.ensure(value).map(&:to_s).include?(view.attributes[:value])
46
- else
47
- view.attributes[:checked] = view.attributes[:value] == value.to_s
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
- def select_option_with_value(value, view)
52
- view.object.each_significant_node(:option) do |option|
53
- View.from_object(option).attributes[:selected] = option.attributes[:value] == value
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
- class Layout < View
6
- attr_accessor :name
5
+ module Views
6
+ class Layout < View
7
+ attr_accessor :name
7
8
 
8
- class << self
9
- def load(path, content: nil, **args)
10
- self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args)
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
- def container(name = Page::DEFAULT_CONTAINER)
20
- @object.container(name.to_sym)
21
- end
15
+ def initialize(name, html = "", **args)
16
+ @name = name
17
+ super(html, **args)
18
+ end
22
19
 
23
- def build(page)
24
- @object.each_significant_node(:container) do |container_node|
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
- View.from_object(@object).add_info(info, page.info)
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
- class Page < View
8
- DEFAULT_CONTAINER = :main
7
+ module Views
8
+ class Page < View
9
+ DEFAULT_CONTAINER = :main
9
10
 
10
- attr_reader :name, :path
11
+ attr_reader :name, :path
11
12
 
12
- class << self
13
- def load(path, content: nil, **args)
14
- self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args, path: path)
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
- def initialize(name, html = "", path: nil, info: {}, **args)
19
- @containers = {}
20
- parse_content(html)
21
- @name, @path = name, path
22
- info[:layout] ||= :default
23
- super(html, info: info, **args)
24
- end
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
- def initialize_copy(_)
27
- super
27
+ def initialize_copy(_)
28
+ super
28
29
 
29
- @containers = Hash[@containers.map { |key, value|
30
- [key, value.dup]
31
- }]
32
- end
30
+ @containers = Hash[@containers.map { |key, value|
31
+ [key, value.dup]
32
+ }]
33
+ end
33
34
 
34
- def content(container)
35
- container = container.to_sym
35
+ def content(container)
36
+ container = container.to_sym
36
37
 
37
- if container == DEFAULT_CONTAINER
38
- @object
39
- elsif @containers.key?(container)
40
- @containers[container].object
41
- else
42
- nil
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
- def mixin(partials)
47
- super
47
+ def mixin(partials)
48
+ super
48
49
 
49
- @containers.values.each do |view|
50
- view.mixin(partials)
50
+ @containers.values.each do |view|
51
+ view.mixin(partials)
52
+ end
51
53
  end
52
- end
53
54
 
54
- def container_views
55
- [View.from_object(@object)].concat(@containers.values)
56
- end
55
+ def container_views
56
+ [View.from_object(@object)].concat(@containers.values)
57
+ end
57
58
 
58
- protected
59
+ private
59
60
 
60
- WITHIN_REGEX = /<!--\s*@within\s*([a-zA-Z0-9\-_]*)\s*-->(.*?)<!--\s*\/within\s*-->/m
61
+ WITHIN_REGEX = /<!--\s*@within\s*([a-zA-Z0-9\-_]*)\s*-->(.*?)<!--\s*\/within\s*-->/m
61
62
 
62
- def parse_content(html)
63
- html.scan(WITHIN_REGEX) do |match|
64
- container_name = match[0].to_sym
65
- @containers[container_name] = View.from_object(StringDoc.new(match[1]))
66
- end
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
- html.gsub!(WITHIN_REGEX, "")
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
- class Partial < View
6
- attr_accessor :name
5
+ module Views
6
+ class Partial < View
7
+ attr_accessor :name
7
8
 
8
- class << self
9
- def load(path, content: nil, **args)
10
- name = File.basename(path, ".*")
11
- name = name[1..-1] if name.start_with?("_")
12
- self.new(name.to_sym, content || File.read(path), **args)
13
- end
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
- def from_object(name, object)
16
- super(object).tap do |instance|
17
- instance.instance_variable_set(:@name, name)
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
- def initialize(name, html = "", **args)
23
- @name = name
24
- super(html, **args)
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
@@ -5,6 +5,7 @@ require "forwardable"
5
5
  class StringDoc
6
6
  # String-based XML attributes.
7
7
  #
8
+ # @api private
8
9
  class Attributes
9
10
  OPENING = '="'
10
11
  CLOSING = '"'
@@ -3,6 +3,7 @@
3
3
  class StringDoc
4
4
  # Lets two or more node's attributes to be manipulated together. Used by {StringDoc::MetaNode}.
5
5
  #
6
+ # @api private
6
7
  class MetaAttributes
7
8
  def initialize(attributes)
8
9
  @attributes = attributes
@@ -5,6 +5,7 @@ require "string_doc/meta_attributes"
5
5
  class StringDoc
6
6
  # Lets two or more nodes to be represented as a single node in a doc, then manipulated together.
7
7
  #
8
+ # @api private
8
9
  class MetaNode
9
10
  # @api private
10
11
  attr_reader :doc, :transforms, :internal_nodes
@@ -6,6 +6,7 @@ require "pakyow/support/inspectable"
6
6
  class StringDoc
7
7
  # String-based XML node.
8
8
  #
9
+ # @api private
9
10
  class Node
10
11
  class << self
11
12
  SELF_CLOSING = %w[area base basefont br hr input img link meta].freeze
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.rc2
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-04 00:00:00.000000000 Z
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.rc2
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.rc2
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.rc2
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.rc2
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.rc2
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.rc2
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/rendering/actions/cleanup_prototype_nodes.rb
130
- - lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb
131
- - lib/pakyow/presenter/rendering/actions/create_template_nodes.rb
132
- - lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb
133
- - lib/pakyow/presenter/rendering/actions/install_authenticity.rb
134
- - lib/pakyow/presenter/rendering/actions/place_in_mode.rb
135
- - lib/pakyow/presenter/rendering/actions/render_components.rb
136
- - lib/pakyow/presenter/rendering/actions/set_page_title.rb
137
- - lib/pakyow/presenter/rendering/actions/setup_endpoints.rb
138
- - lib/pakyow/presenter/rendering/actions/setup_forms.rb
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