pakyow-presenter 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/pakyow-presenter/CHANGELOG.md +94 -0
  3. data/pakyow-presenter/{MIT-LICENSE → LICENSE} +2 -2
  4. data/pakyow-presenter/README.md +36 -0
  5. data/pakyow-presenter/lib/pakyow-presenter.rb +1 -4
  6. data/pakyow-presenter/lib/presenter/attributes.rb +10 -1
  7. data/pakyow-presenter/lib/presenter/base.rb +2 -1
  8. data/pakyow-presenter/lib/presenter/binder.rb +20 -6
  9. data/pakyow-presenter/lib/presenter/binder_set.rb +21 -17
  10. data/pakyow-presenter/lib/presenter/config/presenter.rb +2 -2
  11. data/pakyow-presenter/lib/presenter/ext/app.rb +32 -1
  12. data/pakyow-presenter/lib/presenter/helpers.rb +6 -6
  13. data/pakyow-presenter/lib/presenter/page.rb +4 -4
  14. data/pakyow-presenter/lib/presenter/presenter.rb +32 -10
  15. data/pakyow-presenter/lib/presenter/string_doc.rb +78 -11
  16. data/pakyow-presenter/lib/presenter/string_doc_parser.rb +16 -7
  17. data/pakyow-presenter/lib/presenter/view.rb +55 -17
  18. data/pakyow-presenter/lib/presenter/view_collection.rb +74 -7
  19. data/pakyow-presenter/lib/presenter/view_composer.rb +52 -8
  20. data/pakyow-presenter/lib/presenter/view_context.rb +19 -1
  21. data/pakyow-presenter/lib/presenter/view_store.rb +202 -163
  22. data/pakyow-presenter/lib/presenter/view_store_loader.rb +43 -0
  23. data/pakyow-presenter/lib/presenter/view_version.rb +97 -0
  24. data/pakyow-presenter/lib/views/errors/404.html +5 -0
  25. data/pakyow-presenter/{README → lib/views/errors/500.html} +0 -0
  26. metadata +36 -21
  27. data/pakyow-presenter/CHANGES +0 -57
  28. data/pakyow-presenter/lib/presenter/nokogiri_doc.rb +0 -321
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.9.1
4
+ version: 0.10.0
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: 2014-12-06 00:00:00.000000000 Z
12
+ date: 2015-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakyow-support
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.9.1
20
+ version: 0.10.0
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.9.1
27
+ version: 0.10.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pakyow-core
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 0.9.1
34
+ version: 0.10.0
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.9.1
41
+ version: 0.10.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nokogiri
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -59,38 +59,51 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '5.0'
62
+ version: '5.6'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '5.0'
69
+ version: '5.6'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.2'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: pry
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '0.9'
90
+ version: '0.10'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '0.9'
84
- description: A library for building frontends for Pakyow apps, including templating
85
- and data binding.
97
+ version: '0.10'
98
+ description: Views and presentation for Pakyow
86
99
  email: bryan@metabahn.com
87
100
  executables: []
88
101
  extensions: []
89
102
  extra_rdoc_files: []
90
103
  files:
91
- - pakyow-presenter/CHANGES
92
- - pakyow-presenter/MIT-LICENSE
93
- - pakyow-presenter/README
104
+ - pakyow-presenter/CHANGELOG.md
105
+ - pakyow-presenter/LICENSE
106
+ - pakyow-presenter/README.md
94
107
  - pakyow-presenter/lib/pakyow-presenter.rb
95
108
  - pakyow-presenter/lib/presenter/attributes.rb
96
109
  - pakyow-presenter/lib/presenter/base.rb
@@ -103,7 +116,6 @@ files:
103
116
  - pakyow-presenter/lib/presenter/exceptions.rb
104
117
  - pakyow-presenter/lib/presenter/ext/app.rb
105
118
  - pakyow-presenter/lib/presenter/helpers.rb
106
- - pakyow-presenter/lib/presenter/nokogiri_doc.rb
107
119
  - pakyow-presenter/lib/presenter/page.rb
108
120
  - pakyow-presenter/lib/presenter/partial.rb
109
121
  - pakyow-presenter/lib/presenter/presenter.rb
@@ -116,7 +128,11 @@ files:
116
128
  - pakyow-presenter/lib/presenter/view_composer.rb
117
129
  - pakyow-presenter/lib/presenter/view_context.rb
118
130
  - pakyow-presenter/lib/presenter/view_store.rb
119
- homepage: http://pakyow.com
131
+ - pakyow-presenter/lib/presenter/view_store_loader.rb
132
+ - pakyow-presenter/lib/presenter/view_version.rb
133
+ - pakyow-presenter/lib/views/errors/404.html
134
+ - pakyow-presenter/lib/views/errors/500.html
135
+ homepage: http://pakyow.org
120
136
  licenses:
121
137
  - MIT
122
138
  metadata: {}
@@ -135,10 +151,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
151
  - !ruby/object:Gem::Version
136
152
  version: '0'
137
153
  requirements: []
138
- rubyforge_project: pakyow-presenter
139
- rubygems_version: 2.2.2
154
+ rubyforge_project:
155
+ rubygems_version: 2.4.5
140
156
  signing_key:
141
157
  specification_version: 4
142
- summary: Presenter functionality for Pakyow apps.
158
+ summary: Pakyow Presenter
143
159
  test_files: []
144
- has_rdoc:
@@ -1,57 +0,0 @@
1
- = 0.9.1 / 2014-12-06
2
-
3
- * Fixes bug where name attribute wasn't set on form fields when binding without a value
4
- * Fixes bug causing all partials (not just available ones) to be defined as view parts
5
- * Fixes bug causing form action binding to break
6
-
7
- = 0.9.0 / 2014-11-09
8
-
9
- * Introduces StringDoc, replacing Nokogiri for view rendering with a performant alternative
10
- * Adds the ability to set an empty first option in bindings
11
- * Remove the annoying "no content" for container log message
12
- * Binding context must now be explicitly passed when binding
13
- * Yield bindable value before bindable in view binding fns
14
- * Fixes bug causing non-html view contents to be processed twice
15
- * Removes support for Ruby versions < 2.0.0
16
-
17
- = 0.8.0 / 2014-03-02
18
-
19
- * Major rewrite, including new view syntax, composer, and transformation api
20
-
21
- = 0.7.2 / 2012-02-29
22
-
23
- * No changes -- bumped version to be consistent
24
-
25
- = 0.7.1 / 2012-01-08
26
-
27
- * View caching fixes
28
- * Changed binder to allow definition for multiple endpoints
29
- * Changed in_context to accept context as block argument
30
- * Changed action binder to add leading slash if needed
31
- * Change to allow a view's content to be set to nil
32
- * Fixed Views#find method
33
-
34
- = 0.7.0 / 2011-11-19
35
-
36
- * Cleaned up core/presenter interface
37
- * Optimized view caching
38
- * Binding occurs on the label an object is being bound to, not the object type
39
- * Root view override in index directories no longer specify a root view for siblings
40
- * Fixed problem binding to a checkbox who’s value attribute is not set
41
-
42
- = 0.6.3 / 2011-09-13
43
-
44
- * Fixes binding to bindings defined by HTML 'name' attribute
45
-
46
- = 0.6.2 / 2011-08-20
47
-
48
- * Fixes issue binding object to root nodes
49
- * JRuby Support
50
-
51
- = 0.6.1 / 2011-08-20
52
-
53
- * Fixes gemspec problem
54
-
55
- = 0.6.0 / 2011-08-20
56
-
57
- * Initial gem release of 0.6.0 codebase
@@ -1,321 +0,0 @@
1
- module Pakyow
2
- module Presenter
3
- class NokogiriDoc
4
- PARTIAL_REGEX = /<!--\s*@include\s*([a-zA-Z0-9\-_]*)\s*-->/
5
-
6
- attr_accessor :doc, :scopes
7
-
8
- def breadth_first(doc)
9
- queue = [doc]
10
- until queue.empty?
11
- node = queue.shift
12
- catch(:reject) {
13
- yield node
14
- queue.concat(node.children)
15
- }
16
- end
17
- end
18
-
19
- def path_to(child)
20
- path = []
21
-
22
- return path if child == @doc
23
-
24
- child.ancestors.each {|a|
25
- # since ancestors goes all the way to doc root, stop when we get to the level of @doc
26
- break if a.children.include?(@doc)
27
-
28
- path.unshift(a.children.index(child))
29
- child = a
30
- }
31
-
32
- return path
33
- end
34
-
35
- def path_within_path?(child_path, parent_path)
36
- parent_path.each_with_index {|pp_step, i|
37
- return false unless pp_step == child_path[i]
38
- }
39
-
40
- true
41
- end
42
-
43
- def doc_from_path(path)
44
- o = @doc
45
-
46
- # if path is empty we're at self
47
- return o if path.empty?
48
-
49
- path.each {|i|
50
- if child = o.children[i]
51
- o = child
52
- else
53
- break
54
- end
55
- }
56
-
57
- return o
58
- end
59
-
60
- def view_from_path(path)
61
- view = View.from_doc(doc_from_path(path))
62
- view.related_views << self
63
-
64
- # workaround for nokogiri in jruby (see https://github.com/sparklemotion/nokogiri/issues/1060)
65
- view.doc.document.errors = []
66
-
67
- return view
68
- end
69
-
70
- def to_html
71
- @doc.to_html
72
- end
73
-
74
- alias :to_s :to_html
75
-
76
- def title=(title)
77
- return if @doc.nil?
78
-
79
- if o = @doc.css('title').first
80
- o.inner_html = Nokogiri::HTML::fragment(title.to_s)
81
- elsif o = @doc.css('head').first
82
- o.add_child(Nokogiri::HTML::fragment("<title>#{title}</title>"))
83
- end
84
- end
85
-
86
- def title
87
- return unless o = @doc.css('title').first
88
- o.inner_text
89
- end
90
-
91
- def self.from_doc(doc)
92
- instance = allocate
93
- instance.doc = doc
94
- return instance
95
- end
96
-
97
- def initialize(html)
98
- if html.match(/<html.*>/)
99
- @doc = Nokogiri::HTML::Document.parse(html)
100
- else
101
- @doc = Nokogiri::HTML.fragment(html)
102
- end
103
- end
104
-
105
- def initialize_copy(original_doc)
106
- super
107
-
108
- # this solves a memory leak that I believe is being
109
- # caused by Nokogiri; don't like this approach much
110
- # since it negatively affects performance
111
- #
112
- # https://gist.github.com/bryanp/2048ae4a38f94c9d97ef
113
- if original_doc.is_a?(Nokogiri::HTML::DocumentFragment)
114
- @doc = Nokogiri::HTML.fragment(original_doc.doc.to_html)
115
- else
116
- @doc = original_doc.doc.dup
117
- end
118
- end
119
-
120
- def soft_copy
121
- dup
122
- end
123
-
124
- def set_attribute(name, value)
125
- @doc[name.to_s] = value
126
- end
127
-
128
- def get_attribute(name)
129
- @doc[name.to_s]
130
- end
131
-
132
- def remove_attribute(name)
133
- @doc.remove_attribute(name.to_s)
134
- end
135
-
136
- def update_attribute(name, value)
137
- if !@doc.is_a?(Nokogiri::XML::Element) && @doc.children.count == 1
138
- @doc.children.first[name] = value
139
- else
140
- @doc.set_attribute(name, value)
141
- end
142
- end
143
-
144
- def remove
145
- if @doc.parent.nil?
146
- # best we can do is to remove the children
147
- @doc.children.remove
148
- else
149
- @doc.remove
150
- end
151
- end
152
-
153
- def clear
154
- return if @doc.blank?
155
- @doc.inner_html = ''
156
- end
157
-
158
- def text
159
- @doc.inner_text
160
- end
161
-
162
- def text=(text)
163
- @doc.content = text.to_s
164
- end
165
-
166
- def html
167
- @doc.inner_html
168
- end
169
-
170
- def html=(html)
171
- @doc.inner_html = Nokogiri::HTML.fragment(html.to_s)
172
- end
173
-
174
- def append(appendable)
175
- content = appendable.is_a?(NokogiriDoc) ? appendable.doc : appendable
176
- @doc.add_child(content)
177
- end
178
-
179
- def prepend(prependable)
180
- content = prependable.is_a?(NokogiriDoc) ? prependable.doc : prependable
181
- if first_child = @doc.children.first
182
- first_child.add_previous_sibling(content)
183
- else
184
- @doc = content
185
- end
186
- end
187
-
188
- def after(insertable)
189
- content = insertable.is_a?(NokogiriDoc) ? insertable.doc : insertable
190
- @doc.after(content)
191
- end
192
-
193
- def before(insertable)
194
- content = insertable.is_a?(NokogiriDoc) ? insertable.doc : insertable
195
- @doc.before(content)
196
- end
197
-
198
- def replace(replacement)
199
- content = replacement.is_a?(NokogiriDoc) ? replacement.doc : replacement
200
-
201
- if @doc.parent.nil?
202
- @doc.children.remove
203
- @doc.inner_html = content
204
- else
205
- @doc.replace(content)
206
- end
207
- end
208
-
209
- def scope(name)
210
- scopes.select { |b| b[:scope] == name }
211
- end
212
-
213
- def prop(scope_name, prop_name)
214
- return [] unless scope = scopes.select { |b| b[:scope] == scope_name }[0]
215
- scope[:props].select { |b| b[:prop] == prop_name }
216
- end
217
-
218
- def container(name)
219
- container = @containers[name.to_sym]
220
- return container[:doc]
221
- end
222
-
223
- def scopes
224
- find_scopes
225
- end
226
-
227
- def containers
228
- find_containers
229
- end
230
-
231
- def partials
232
- find_partials
233
- end
234
-
235
- def ==(o)
236
- to_html == o.to_html
237
- end
238
-
239
- def tagname
240
- @doc.name
241
- end
242
-
243
- def option(value: nil)
244
- @doc.css('option[value="' + value.to_s + '"]').first
245
- end
246
-
247
- private
248
-
249
- # returns an array of hashes that describe each scope
250
- def find_scopes(doc = @doc, ignore_root = false)
251
- scopes = []
252
- breadth_first(doc) {|o|
253
- next if o == doc && ignore_root
254
- next if !scope = o[Config.presenter.scope_attribute]
255
-
256
- scopes << {
257
- :doc => NokogiriDoc.from_doc(o),
258
- :scope => scope.to_sym,
259
- :props => find_props(o)
260
- }
261
-
262
- if o == doc
263
- # this is the root node, which we need as the first hash in the
264
- # list of scopes, but we don't want to nest other scopes inside
265
- # of it in this case
266
- scopes.last[:nested] = []
267
- else
268
- scopes.last[:nested] = find_scopes(o, true)
269
- # reject so children aren't traversed
270
- throw :reject
271
- end
272
- }
273
-
274
- return scopes
275
- end
276
-
277
- # returns an array of hashes, each with the container name and doc
278
- def find_containers
279
- containers = {}
280
-
281
- @doc.traverse {|e|
282
- next unless e.is_a?(Nokogiri::XML::Comment)
283
- next unless match = e.text.strip.match(/@container( ([a-zA-Z0-9\-_]*))*/)
284
- name = match[2] || :default
285
-
286
- containers[name.to_sym] = { doc: NokogiriDoc.from_doc(e) }
287
- }
288
-
289
- return containers
290
- end
291
-
292
- def find_props(o)
293
- props = []
294
- breadth_first(o) {|so|
295
- # don't go into deeper scopes
296
- throw :reject if so != o && so[Config.presenter.scope_attribute]
297
-
298
- next unless prop = so[Config.presenter.prop_attribute]
299
- props << { :prop => prop.to_sym, :doc => NokogiriDoc.from_doc(so) }
300
- }
301
-
302
- return props
303
- end
304
-
305
- def find_partials
306
- partials = {}
307
-
308
- @doc.traverse { |e|
309
- next unless e.is_a?(Nokogiri::XML::Comment)
310
- next unless match = e.to_html.strip.match(PARTIAL_REGEX)
311
-
312
- name = match[1]
313
- partials[name.to_sym] = NokogiriDoc.from_doc(e)
314
- }
315
-
316
- return partials
317
- end
318
-
319
- end
320
- end
321
- end