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.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/{pakyow-presenter/CHANGELOG.md → CHANGELOG.md} +0 -5
  3. data/LICENSE +4 -0
  4. data/{pakyow-presenter/README.md → README.md} +1 -2
  5. data/lib/pakyow/generators/presenter/presenter_generator.rb +28 -0
  6. data/lib/pakyow/generators/presenter/templates/presenter.rb.tt +2 -0
  7. data/lib/pakyow/plugin/helpers/rendering.rb +19 -0
  8. data/lib/pakyow/presenter/actions/auto_render.rb +15 -0
  9. data/lib/pakyow/presenter/attributes/attribute.rb +22 -0
  10. data/lib/pakyow/presenter/attributes/boolean.rb +24 -0
  11. data/lib/pakyow/presenter/attributes/hash.rb +89 -0
  12. data/lib/pakyow/presenter/attributes/set.rb +61 -0
  13. data/lib/pakyow/presenter/attributes/string.rb +38 -0
  14. data/lib/pakyow/presenter/attributes.rb +126 -0
  15. data/lib/pakyow/presenter/behavior/config.rb +29 -0
  16. data/lib/pakyow/presenter/behavior/error_rendering.rb +124 -0
  17. data/lib/pakyow/presenter/behavior/exposures.rb +29 -0
  18. data/lib/pakyow/presenter/behavior/implicit_rendering.rb +21 -0
  19. data/lib/pakyow/presenter/behavior/initializing.rb +37 -0
  20. data/lib/pakyow/presenter/behavior/modes.rb +117 -0
  21. data/lib/pakyow/presenter/behavior/versions.rb +71 -0
  22. data/lib/pakyow/presenter/behavior/watching.rb +21 -0
  23. data/lib/pakyow/presenter/binder.rb +115 -0
  24. data/lib/pakyow/presenter/binding_parts.rb +64 -0
  25. data/lib/pakyow/presenter/component.rb +74 -0
  26. data/lib/pakyow/presenter/composers/component.rb +78 -0
  27. data/lib/pakyow/presenter/composers/view.rb +73 -0
  28. data/lib/pakyow/presenter/errors.rb +63 -0
  29. data/lib/pakyow/presenter/framework.rb +203 -0
  30. data/lib/pakyow/presenter/front_matter_parser.rb +42 -0
  31. data/lib/pakyow/presenter/helpers/rendering.rb +18 -0
  32. data/lib/pakyow/presenter/presentable.rb +28 -0
  33. data/lib/pakyow/presenter/presentable_error.rb +19 -0
  34. data/lib/pakyow/presenter/presenter.rb +766 -0
  35. data/lib/pakyow/presenter/presenters/endpoint.rb +158 -0
  36. data/lib/pakyow/presenter/presenters/form.rb +522 -0
  37. data/lib/pakyow/presenter/processor.rb +61 -0
  38. data/lib/pakyow/presenter/renderable.rb +28 -0
  39. data/lib/pakyow/presenter/renderer.rb +269 -0
  40. data/lib/pakyow/presenter/rendering/actions/cleanup_prototype_nodes.rb +21 -0
  41. data/lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb +35 -0
  42. data/lib/pakyow/presenter/rendering/actions/create_template_nodes.rb +27 -0
  43. data/lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb +101 -0
  44. data/lib/pakyow/presenter/rendering/actions/install_authenticity.rb +42 -0
  45. data/lib/pakyow/presenter/rendering/actions/place_in_mode.rb +56 -0
  46. data/lib/pakyow/presenter/rendering/actions/render_components.rb +279 -0
  47. data/lib/pakyow/presenter/rendering/actions/set_page_title.rb +35 -0
  48. data/lib/pakyow/presenter/rendering/actions/setup_endpoints.rb +62 -0
  49. data/lib/pakyow/presenter/rendering/actions/setup_forms.rb +174 -0
  50. data/lib/pakyow/presenter/significant_nodes.rb +309 -0
  51. data/lib/pakyow/presenter/templates.rb +229 -0
  52. data/lib/pakyow/presenter/versioned_view.rb +209 -0
  53. data/lib/pakyow/presenter/view.rb +586 -0
  54. data/lib/pakyow/presenter/views/form.rb +58 -0
  55. data/lib/pakyow/presenter/views/layout.rb +32 -0
  56. data/lib/pakyow/presenter/views/page.rb +72 -0
  57. data/lib/pakyow/presenter/views/partial.rb +28 -0
  58. data/lib/pakyow/presenter.rb +33 -0
  59. data/lib/pakyow/views/errors/layouts/development_error.html +102 -0
  60. data/lib/pakyow/views/errors/layouts/production_error.html +27 -0
  61. data/lib/pakyow/views/errors/pages/404.html +12 -0
  62. data/lib/pakyow/views/errors/pages/500.html +12 -0
  63. data/lib/pakyow/views/errors/pages/development/500.html +39 -0
  64. data/lib/string_doc/attributes.rb +109 -0
  65. data/lib/string_doc/meta_attributes.rb +48 -0
  66. data/lib/string_doc/meta_node.rb +328 -0
  67. data/lib/string_doc/node.rb +377 -0
  68. data/lib/string_doc.rb +642 -0
  69. metadata +95 -75
  70. data/pakyow-presenter/LICENSE +0 -20
  71. data/pakyow-presenter/lib/pakyow/presenter/attributes.rb +0 -228
  72. data/pakyow-presenter/lib/pakyow/presenter/base.rb +0 -38
  73. data/pakyow-presenter/lib/pakyow/presenter/binder.rb +0 -116
  74. data/pakyow-presenter/lib/pakyow/presenter/binder_set.rb +0 -94
  75. data/pakyow-presenter/lib/pakyow/presenter/binding_eval.rb +0 -37
  76. data/pakyow-presenter/lib/pakyow/presenter/config/presenter.rb +0 -42
  77. data/pakyow-presenter/lib/pakyow/presenter/container.rb +0 -6
  78. data/pakyow-presenter/lib/pakyow/presenter/doc_helpers.rb +0 -17
  79. data/pakyow-presenter/lib/pakyow/presenter/exceptions.rb +0 -11
  80. data/pakyow-presenter/lib/pakyow/presenter/ext/app.rb +0 -33
  81. data/pakyow-presenter/lib/pakyow/presenter/ext/call_context.rb +0 -28
  82. data/pakyow-presenter/lib/pakyow/presenter/helpers.rb +0 -46
  83. data/pakyow-presenter/lib/pakyow/presenter/page.rb +0 -110
  84. data/pakyow-presenter/lib/pakyow/presenter/partial.rb +0 -6
  85. data/pakyow-presenter/lib/pakyow/presenter/presenter.rb +0 -232
  86. data/pakyow-presenter/lib/pakyow/presenter/string_doc.rb +0 -380
  87. data/pakyow-presenter/lib/pakyow/presenter/string_doc_parser.rb +0 -144
  88. data/pakyow-presenter/lib/pakyow/presenter/string_doc_renderer.rb +0 -18
  89. data/pakyow-presenter/lib/pakyow/presenter/template.rb +0 -51
  90. data/pakyow-presenter/lib/pakyow/presenter/view.rb +0 -541
  91. data/pakyow-presenter/lib/pakyow/presenter/view_collection.rb +0 -330
  92. data/pakyow-presenter/lib/pakyow/presenter/view_composer.rb +0 -237
  93. data/pakyow-presenter/lib/pakyow/presenter/view_context.rb +0 -111
  94. data/pakyow-presenter/lib/pakyow/presenter/view_store.rb +0 -262
  95. data/pakyow-presenter/lib/pakyow/presenter/view_store_loader.rb +0 -43
  96. data/pakyow-presenter/lib/pakyow/presenter/view_version.rb +0 -113
  97. data/pakyow-presenter/lib/pakyow/presenter.rb +0 -8
  98. data/pakyow-presenter/lib/pakyow/views/errors/404.erb +0 -26
  99. data/pakyow-presenter/lib/pakyow/views/errors/500.erb +0 -23
  100. data/pakyow-presenter/lib/pakyow-presenter.rb +0 -1
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: 0.11.3
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
@@ -9,152 +9,172 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-15 00:00:00.000000000 Z
12
+ date: 2019-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: pakyow-support
15
+ name: pakyow-core
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.11.3
20
+ version: 1.0.0.rc1
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: 0.11.3
27
+ version: 1.0.0.rc1
28
28
  - !ruby/object:Gem::Dependency
29
- name: pakyow-core
29
+ name: pakyow-routing
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 0.11.3
34
+ version: 1.0.0.rc1
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: 0.11.3
41
+ version: 1.0.0.rc1
42
42
  - !ruby/object:Gem::Dependency
43
- name: oga
43
+ name: pakyow-support
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: '2.0'
48
+ version: 1.0.0.rc1
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '2.0'
56
- - !ruby/object:Gem::Dependency
57
- name: minitest
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '5.6'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
53
+ - - '='
68
54
  - !ruby/object:Gem::Version
69
- version: '5.6'
55
+ version: 1.0.0.rc1
70
56
  - !ruby/object:Gem::Dependency
71
- name: rspec
57
+ name: oga
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - "~>"
75
61
  - !ruby/object:Gem::Version
76
- version: '3.2'
77
- type: :development
62
+ version: '2.15'
63
+ type: :runtime
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: '3.2'
69
+ version: '2.15'
84
70
  - !ruby/object:Gem::Dependency
85
- name: pry
71
+ name: redcarpet
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - "~>"
89
75
  - !ruby/object:Gem::Version
90
- version: '0.10'
91
- type: :development
76
+ version: '3.4'
77
+ type: :runtime
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
95
81
  - - "~>"
96
82
  - !ruby/object:Gem::Version
97
- version: '0.10'
83
+ version: '3.4'
98
84
  description: Views and presentation for Pakyow
99
85
  email: bryan@metabahn.com
100
86
  executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
104
- - pakyow-presenter/CHANGELOG.md
105
- - pakyow-presenter/LICENSE
106
- - pakyow-presenter/README.md
107
- - pakyow-presenter/lib/pakyow-presenter.rb
108
- - pakyow-presenter/lib/pakyow/presenter.rb
109
- - pakyow-presenter/lib/pakyow/presenter/attributes.rb
110
- - pakyow-presenter/lib/pakyow/presenter/base.rb
111
- - pakyow-presenter/lib/pakyow/presenter/binder.rb
112
- - pakyow-presenter/lib/pakyow/presenter/binder_set.rb
113
- - pakyow-presenter/lib/pakyow/presenter/binding_eval.rb
114
- - pakyow-presenter/lib/pakyow/presenter/config/presenter.rb
115
- - pakyow-presenter/lib/pakyow/presenter/container.rb
116
- - pakyow-presenter/lib/pakyow/presenter/doc_helpers.rb
117
- - pakyow-presenter/lib/pakyow/presenter/exceptions.rb
118
- - pakyow-presenter/lib/pakyow/presenter/ext/app.rb
119
- - pakyow-presenter/lib/pakyow/presenter/ext/call_context.rb
120
- - pakyow-presenter/lib/pakyow/presenter/helpers.rb
121
- - pakyow-presenter/lib/pakyow/presenter/page.rb
122
- - pakyow-presenter/lib/pakyow/presenter/partial.rb
123
- - pakyow-presenter/lib/pakyow/presenter/presenter.rb
124
- - pakyow-presenter/lib/pakyow/presenter/string_doc.rb
125
- - pakyow-presenter/lib/pakyow/presenter/string_doc_parser.rb
126
- - pakyow-presenter/lib/pakyow/presenter/string_doc_renderer.rb
127
- - pakyow-presenter/lib/pakyow/presenter/template.rb
128
- - pakyow-presenter/lib/pakyow/presenter/view.rb
129
- - pakyow-presenter/lib/pakyow/presenter/view_collection.rb
130
- - pakyow-presenter/lib/pakyow/presenter/view_composer.rb
131
- - pakyow-presenter/lib/pakyow/presenter/view_context.rb
132
- - pakyow-presenter/lib/pakyow/presenter/view_store.rb
133
- - pakyow-presenter/lib/pakyow/presenter/view_store_loader.rb
134
- - pakyow-presenter/lib/pakyow/presenter/view_version.rb
135
- - pakyow-presenter/lib/pakyow/views/errors/404.erb
136
- - pakyow-presenter/lib/pakyow/views/errors/500.erb
137
- homepage: http://pakyow.org
90
+ - CHANGELOG.md
91
+ - LICENSE
92
+ - README.md
93
+ - lib/pakyow/generators/presenter/presenter_generator.rb
94
+ - lib/pakyow/generators/presenter/templates/presenter.rb.tt
95
+ - lib/pakyow/plugin/helpers/rendering.rb
96
+ - lib/pakyow/presenter.rb
97
+ - lib/pakyow/presenter/actions/auto_render.rb
98
+ - lib/pakyow/presenter/attributes.rb
99
+ - lib/pakyow/presenter/attributes/attribute.rb
100
+ - lib/pakyow/presenter/attributes/boolean.rb
101
+ - lib/pakyow/presenter/attributes/hash.rb
102
+ - lib/pakyow/presenter/attributes/set.rb
103
+ - lib/pakyow/presenter/attributes/string.rb
104
+ - lib/pakyow/presenter/behavior/config.rb
105
+ - lib/pakyow/presenter/behavior/error_rendering.rb
106
+ - lib/pakyow/presenter/behavior/exposures.rb
107
+ - lib/pakyow/presenter/behavior/implicit_rendering.rb
108
+ - lib/pakyow/presenter/behavior/initializing.rb
109
+ - lib/pakyow/presenter/behavior/modes.rb
110
+ - lib/pakyow/presenter/behavior/versions.rb
111
+ - lib/pakyow/presenter/behavior/watching.rb
112
+ - lib/pakyow/presenter/binder.rb
113
+ - lib/pakyow/presenter/binding_parts.rb
114
+ - lib/pakyow/presenter/component.rb
115
+ - lib/pakyow/presenter/composers/component.rb
116
+ - lib/pakyow/presenter/composers/view.rb
117
+ - lib/pakyow/presenter/errors.rb
118
+ - lib/pakyow/presenter/framework.rb
119
+ - lib/pakyow/presenter/front_matter_parser.rb
120
+ - lib/pakyow/presenter/helpers/rendering.rb
121
+ - lib/pakyow/presenter/presentable.rb
122
+ - lib/pakyow/presenter/presentable_error.rb
123
+ - lib/pakyow/presenter/presenter.rb
124
+ - lib/pakyow/presenter/presenters/endpoint.rb
125
+ - lib/pakyow/presenter/presenters/form.rb
126
+ - lib/pakyow/presenter/processor.rb
127
+ - lib/pakyow/presenter/renderable.rb
128
+ - 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
139
+ - lib/pakyow/presenter/significant_nodes.rb
140
+ - lib/pakyow/presenter/templates.rb
141
+ - lib/pakyow/presenter/versioned_view.rb
142
+ - lib/pakyow/presenter/view.rb
143
+ - lib/pakyow/presenter/views/form.rb
144
+ - lib/pakyow/presenter/views/layout.rb
145
+ - lib/pakyow/presenter/views/page.rb
146
+ - lib/pakyow/presenter/views/partial.rb
147
+ - lib/pakyow/views/errors/layouts/development_error.html
148
+ - lib/pakyow/views/errors/layouts/production_error.html
149
+ - lib/pakyow/views/errors/pages/404.html
150
+ - lib/pakyow/views/errors/pages/500.html
151
+ - lib/pakyow/views/errors/pages/development/500.html
152
+ - lib/string_doc.rb
153
+ - lib/string_doc/attributes.rb
154
+ - lib/string_doc/meta_attributes.rb
155
+ - lib/string_doc/meta_node.rb
156
+ - lib/string_doc/node.rb
157
+ homepage: https://pakyow.org
138
158
  licenses:
139
- - MIT
159
+ - LGPL-3.0
140
160
  metadata: {}
141
161
  post_install_message:
142
162
  rdoc_options: []
143
163
  require_paths:
144
- - pakyow-presenter/lib
164
+ - lib
145
165
  required_ruby_version: !ruby/object:Gem::Requirement
146
166
  requirements:
147
167
  - - ">="
148
168
  - !ruby/object:Gem::Version
149
- version: 2.0.0
169
+ version: 2.5.0
150
170
  required_rubygems_version: !ruby/object:Gem::Requirement
151
171
  requirements:
152
- - - ">="
172
+ - - ">"
153
173
  - !ruby/object:Gem::Version
154
- version: '0'
174
+ version: 1.3.1
155
175
  requirements: []
156
176
  rubyforge_project:
157
- rubygems_version: 2.5.1
177
+ rubygems_version: 2.7.6
158
178
  signing_key:
159
179
  specification_version: 4
160
180
  summary: Pakyow Presenter
@@ -1,20 +0,0 @@
1
- Copyright (c) 2011-2015 Bryan Powell
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,228 +0,0 @@
1
- module Pakyow
2
- module Presenter
3
- class Attribute
4
- def initialize(name, raw_value, control, doc)
5
- @type = type_of_attribute(name)
6
- @name = name
7
- @value = deconstruct_attribute_value_of_type(raw_value, @type)
8
- @control = control
9
- @doc = doc
10
- end
11
-
12
- def set(value)
13
- value = Array(value) if @type == :mult && !value.is_a?(Proc)
14
- @value = value
15
- update_value
16
- end
17
-
18
- # ensures that the value passed is contained in `value`
19
- def ensure(value)
20
- case @type
21
- when :mult
22
- @value << value unless @value.include?(value)
23
- when :bool
24
- @value = value
25
- else
26
- @value << value if @value.nil? || !@value.match(value)
27
- end
28
-
29
- update_value
30
- end
31
-
32
- # opposite of `ensure`
33
- def deny(value)
34
- case @type
35
- when :mult
36
- @value.delete(value.to_s)
37
- when :bool
38
- @value = !value
39
- else
40
- @value.gsub!(value.to_s, '')
41
- end
42
-
43
- update_value
44
- end
45
-
46
- def include?(attribute)
47
- @doc.has_attribute?(attribute)
48
- end
49
-
50
- # passes method call to `value`
51
- def method_missing(method, *args)
52
- ret = @value.send(method, *args)
53
- update_value
54
- return ret
55
- end
56
-
57
- # returns the full string value
58
- def to_s
59
- value = @value
60
- value = value.call(deconstruct_attribute_value_of_type(@doc.get_attribute(@name), @type)) if value.is_a? Proc
61
- value = construct_attribute_value_of_type(value, @type, @name)
62
-
63
- return value
64
- end
65
-
66
- def value
67
- @value
68
- end
69
-
70
- def ancestors
71
- self.class.ancestors
72
- end
73
-
74
- def types
75
- @types ||= {
76
- :hash => [:style],
77
- :bool => [:selected, :checked, :disabled, :readonly, :multiple],
78
- :mult => [:class]
79
- }
80
- end
81
-
82
- private
83
-
84
- def update_value
85
- updated_value = to_s
86
-
87
- if updated_value.nil?
88
- @control.remove_attribute(@name)
89
- else
90
- @control.update_value_for_attribute(@name, updated_value)
91
- end
92
- end
93
-
94
- def type_of_attribute(attribute)
95
- attribute = attribute.to_sym
96
-
97
- return :bool if types[:bool].include?(attribute)
98
- return :mult if types[:mult].include?(attribute)
99
- return :hash if types[:hash].include?(attribute)
100
- return :single
101
- end
102
-
103
- def deconstruct_attribute_value_of_type(value, type)
104
- return value ? value : '' if type == :single
105
- return value ? value.split(' ') : [] if type == :mult
106
- return !value.nil? if type == :bool
107
- return value_to_hash(value) if type == :hash
108
- end
109
-
110
- def construct_attribute_value_of_type(value, type, attribute)
111
- return value if type == :single
112
- return value.join(' ') if type == :mult
113
- return value ? attribute : nil if type == :bool
114
- return value.to_a.map {|a| a.join(':')}.join(';') if type == :hash
115
- end
116
-
117
- def value_to_hash(value)
118
- return {} if value.nil?
119
-
120
- value.split(';').inject({}) {|h, style|
121
- k,v = style.split(':')
122
- h[k.to_sym] = v
123
- h
124
- }
125
- end
126
- end
127
-
128
- class Attributes
129
- def initialize(doc)
130
- @doc = doc
131
- @attributes = {}
132
- end
133
-
134
- def method_missing(method, *args)
135
- method_str = method.to_s
136
-
137
- if method_str[0..1] == '[]'
138
- attribute = args[0]
139
- value = args[1]
140
- else
141
- attribute = method_str.gsub('=', '')
142
- value = args[0]
143
- end
144
-
145
- if method_str.include?('=')
146
- self.set_attribute(attribute, value)
147
- else
148
- self.get_attribute(attribute)
149
- end
150
- end
151
-
152
- def class(*args)
153
- method_missing(:class, *args)
154
- end
155
-
156
- def id(*args)
157
- method_missing(:id, *args)
158
- end
159
-
160
- def method(*args)
161
- method_missing(:method, *args)
162
- end
163
-
164
- def update_value_for_attribute(attribute, value)
165
- @doc.update_attribute(attribute, value)
166
- end
167
-
168
- def remove_attribute(attribute)
169
- @doc.remove_attribute(attribute)
170
- end
171
-
172
- def include?(attribute)
173
- @doc.has_attribute?(attribute)
174
- end
175
-
176
- protected
177
-
178
- def set_attribute(attribute, value)
179
- get_attribute(attribute).set(value)
180
- end
181
-
182
- def get_attribute(attribute)
183
- @attributes[attribute] ||
184
- Attribute.new(attribute, @doc.get_attribute(attribute), self, @doc)
185
- end
186
- end
187
-
188
- class AttributesCollection
189
- include Enumerable
190
-
191
- def initialize
192
- @attributes = []
193
- end
194
-
195
- def <<(attributes)
196
- if attributes.is_a?(Attribute) || attributes.is_a?(Attributes)
197
- @attributes << attributes
198
- else
199
- method_missing(:<<, *attributes)
200
- end
201
-
202
- self
203
- end
204
-
205
- def each
206
- @attributes.each { |a| yield(a) }
207
- end
208
-
209
- def method_missing(method, *args)
210
- @attributes.inject(AttributesCollection.new) { |coll, a|
211
- coll << a.send(method, *args)
212
- }
213
- end
214
-
215
- def to_s
216
- @attributes.inject([]) { |arr, a| arr << a.to_s }
217
- end
218
-
219
- def class(*args)
220
- method_missing(:class, *args)
221
- end
222
-
223
- def id(*args)
224
- method_missing(:id, *args)
225
- end
226
- end
227
- end
228
- end
@@ -1,38 +0,0 @@
1
- require 'yaml'
2
-
3
- require 'pakyow/presenter/view_store'
4
- require 'pakyow/presenter/view'
5
- require 'pakyow/presenter/template'
6
- require 'pakyow/presenter/page'
7
- require 'pakyow/presenter/container'
8
- require 'pakyow/presenter/partial'
9
- require 'pakyow/presenter/view_collection'
10
- require 'pakyow/presenter/binder'
11
- require 'pakyow/presenter/binder_set'
12
- require 'pakyow/presenter/attributes'
13
- require 'pakyow/presenter/exceptions'
14
- require 'pakyow/presenter/view_composer'
15
- require 'pakyow/presenter/string_doc'
16
- require 'pakyow/presenter/string_doc_parser'
17
- require 'pakyow/presenter/string_doc_renderer'
18
- require 'pakyow/presenter/binding_eval'
19
- require 'pakyow/presenter/doc_helpers'
20
- require 'pakyow/presenter/view_version'
21
- require 'pakyow/presenter/view_context'
22
- require 'pakyow/presenter/view_store_loader'
23
-
24
- module Pakyow
25
- module Presenter
26
- Pakyow::App.after :load do
27
- routes :__presenter do
28
- handler 404 do
29
- presenter_handle_error(404)
30
- end
31
-
32
- handler 500 do
33
- presenter_handle_error(500)
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,116 +0,0 @@
1
- require 'singleton'
2
-
3
- module Pakyow
4
- module Presenter
5
- # A singleton that manages BinderSet instances for an app. It handles
6
- # the creation / registration of sets and provides a mechanism
7
- # to augment data to be bound with values from the sets.
8
- #
9
- class Binder
10
- include Singleton
11
-
12
- # Access to the registered binder sets for an app.
13
- #
14
- attr_reader :sets
15
-
16
- def initialize
17
- @sets = {}
18
- end
19
-
20
- # Resets the registered binder sets.
21
- #
22
- # @return [Binder] the reset instance
23
- #
24
- def reset
25
- @sets = {}
26
- self
27
- end
28
-
29
- # Creates and registers a new binder set by name. A block should be passed
30
- # that defines the bindings. This block will be evaluated in context
31
- # of the created binder set.
32
- #
33
- # @see BinderSet
34
- #
35
- # @param name [Symbol] the name of the binder set to be created
36
- #
37
- def set(name, &block)
38
- @sets[name] = BinderSet.new(&block)
39
- end
40
-
41
- # Returns the value for the scope->prop by applying any defined bindings to the data.
42
- #
43
- # @param scope [Symbol] the scope name
44
- # @param prop [Symbol] the prop name
45
- # @param bindable [Symbol] the data being bound
46
- # @param bindings [Symbol] additional bindings to take into consideration when determining the value
47
- # @param context [Symbol] context passed through to the defined bindings
48
- #
49
- def value_for_scoped_prop(scope, prop, bindable, bindings, context)
50
- if @sets.empty?
51
- binding_fn = bindings[prop]
52
- else
53
- binding_fn = @sets.lazy.map { |set|
54
- set[1].match_for_prop(prop, scope, bindable, bindings)
55
- }.find { |match|
56
- !match.nil?
57
- }
58
- end
59
-
60
- if binding_fn
61
- binding_eval = BindingEval.new(prop, bindable, context)
62
- result = binding_eval.eval(&binding_fn)
63
-
64
- if result.nil?
65
- value = value_from_data(prop, bindable)
66
-
67
- fn = bindings[prop]
68
- result = fn.call(value, bindable, context) if fn
69
- end
70
- result
71
- else # default value
72
- value_from_data(prop, bindable)
73
- end
74
- end
75
-
76
- def value_from_data(prop, bindable)
77
- if bindable.is_a?(Hash)
78
- bindable.fetch(prop) { bindable[prop.to_s] }
79
- elsif bindable.class.method_defined?(prop)
80
- bindable.send(prop)
81
- end
82
- end
83
-
84
-
85
- # Returns true if a binding is defined for the scope->prop.
86
- #
87
- def has_scoped_prop?(scope, prop, bindings)
88
- @sets.lazy.map { |set|
89
- set[1].has_prop?(scope, prop, bindings)
90
- }.find { |has_prop|
91
- has_prop
92
- }
93
- end
94
-
95
- # Returns options for the scope->prop.
96
- #
97
- def options_for_scoped_prop(scope, prop, bindable, context)
98
- @sets.lazy.map { |set|
99
- set[1].options_for_prop(scope, prop, bindable, context)
100
- }.find { |options|
101
- !options.nil?
102
- }
103
- end
104
-
105
- def bindings_for_scope(scope, bindings = {})
106
- return bindings if @sets.empty?
107
-
108
- @sets.map { |set|
109
- set[1].bindings_for_scope(scope, bindings)
110
- }.inject({}) { |acc, bindings|
111
- acc.merge(bindings)
112
- }
113
- end
114
- end
115
- end
116
- end