pakyow-presenter 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/pakyow-presenter/CHANGELOG.md +16 -0
  3. data/pakyow-presenter/lib/pakyow-presenter.rb +1 -11
  4. data/pakyow-presenter/lib/pakyow/presenter.rb +8 -0
  5. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/attributes.rb +21 -14
  6. data/pakyow-presenter/lib/pakyow/presenter/base.rb +38 -0
  7. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/binder.rb +19 -6
  8. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/binder_set.rb +18 -21
  9. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/binding_eval.rb +14 -0
  10. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/config/presenter.rb +12 -6
  11. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/container.rb +0 -0
  12. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/doc_helpers.rb +0 -0
  13. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/exceptions.rb +0 -0
  14. data/pakyow-presenter/lib/pakyow/presenter/ext/app.rb +33 -0
  15. data/pakyow-presenter/lib/pakyow/presenter/ext/call_context.rb +28 -0
  16. data/pakyow-presenter/lib/pakyow/presenter/helpers.rb +46 -0
  17. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/page.rb +0 -0
  18. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/partial.rb +0 -0
  19. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/presenter.rb +14 -9
  20. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/string_doc.rb +35 -9
  21. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/string_doc_parser.rb +41 -30
  22. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/string_doc_renderer.rb +0 -0
  23. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/template.rb +0 -0
  24. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view.rb +79 -36
  25. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_collection.rb +10 -4
  26. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_composer.rb +43 -3
  27. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_context.rb +12 -8
  28. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_store.rb +3 -1
  29. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_store_loader.rb +0 -0
  30. data/pakyow-presenter/lib/{presenter → pakyow/presenter}/view_version.rb +19 -3
  31. data/pakyow-presenter/lib/pakyow/views/errors/404.erb +26 -0
  32. data/pakyow-presenter/lib/pakyow/views/errors/500.erb +23 -0
  33. metadata +39 -38
  34. data/pakyow-presenter/lib/presenter/base.rb +0 -27
  35. data/pakyow-presenter/lib/presenter/ext/app.rb +0 -63
  36. data/pakyow-presenter/lib/presenter/helpers.rb +0 -40
  37. data/pakyow-presenter/lib/views/errors/404.html +0 -5
  38. data/pakyow-presenter/lib/views/errors/500.html +0 -0
@@ -10,6 +10,13 @@ module Pakyow
10
10
  @scoped_as = scope
11
11
  end
12
12
 
13
+ def initialize_copy(original_view)
14
+ super
15
+
16
+ @views = Pakyow::Utils::Dup.deep(original_view.views)
17
+ @scoped_as = original_view.scoped_as
18
+ end
19
+
13
20
  def ==(other)
14
21
  @views.each_with_index do |view, i|
15
22
  return false if view != other.views[i]
@@ -70,11 +77,10 @@ module Pakyow
70
77
  end
71
78
  end
72
79
 
80
+ # TODO: decide if we care to check the type of
81
+ # objects being added to the collection
73
82
  def <<(val)
74
- if val.is_a? View
75
- @views << val
76
- end
77
-
83
+ @views << val
78
84
  self
79
85
  end
80
86
 
@@ -27,14 +27,47 @@ module Pakyow
27
27
  (@page.is_a?(Page) && @page.info(:template)) || path
28
28
  }
29
29
 
30
- @partials = {}
31
-
30
+ # Setting up partials is a bit complicated, but here's how it works.
31
+ #
32
+ # First we set `@partials` to the ones passed or the partials from the
33
+ # store for the path that we're composing at. We do this so that
34
+ # partials are included in `parts` after this (important since we
35
+ # want partials defined in partials to be found properly).
32
36
  begin
37
+ @partials = {}
33
38
  @partials = includes(opts.fetch(:includes))
34
39
  rescue
35
40
  @partials = store.partials(path) unless path.nil?
36
41
  end
37
42
 
43
+ # Now we need to build the actual set of partials used by parts of the
44
+ # view that we're composing. This bit of code counts the number of each
45
+ # partial present; if it's greater than one we represent them as a view
46
+ # collection, otherwise it's just a partial.
47
+ #
48
+ # FIXME: It's possible there's a more straight-forward way to write this
49
+ # code; it should be explored at some poitn in the future.
50
+ partials = {}
51
+ @partials.each do |name, view|
52
+ count = parts.select { |part|
53
+ part.doc.partials.key?(name)
54
+ }.map { |part|
55
+ part.doc.partials[name].count
56
+ }.inject(&:+) || 0
57
+
58
+ partials[name] = view; next if count < 2
59
+
60
+ collection = ViewCollection.new
61
+
62
+ count.times do
63
+ collection << view.dup
64
+ end
65
+
66
+ partials[name] = collection
67
+ end
68
+
69
+ @partials = partials
70
+
38
71
  instance_exec(&block) if block_given?
39
72
  end
40
73
 
@@ -102,6 +135,7 @@ module Pakyow
102
135
 
103
136
  def partial(name)
104
137
  partial = @partials[name]
138
+ partial.includes(partials)
105
139
  return partial
106
140
  end
107
141
 
@@ -178,7 +212,13 @@ module Pakyow
178
212
  def partials_for_parts(parts, acc = [])
179
213
  # determine the partials to be included
180
214
  available_partials = parts.inject([]) { |sum, part|
181
- sum.concat(part.doc.partials.keys)
215
+ if part.is_a?(ViewCollection)
216
+ part.each do |view|
217
+ sum.concat(view.doc.partials.keys)
218
+ end
219
+ else
220
+ sum.concat(part.doc.partials.keys)
221
+ end
182
222
  }
183
223
 
184
224
  # add available partials as parts
@@ -44,16 +44,20 @@ module Pakyow
44
44
  end
45
45
  end
46
46
 
47
- def scope(name)
48
- collection = @view.scope(name)
47
+ # View methods that support versioning.
48
+ #
49
+ %i[scope prop].each do |method|
50
+ define_method(method) do |*args|
51
+ collection = @view.send(method, *args)
49
52
 
50
- if !collection.is_a?(ViewVersion) && collection.versioned?
51
- ret = ViewVersion.new(collection.views)
52
- else
53
- ret = collection
54
- end
53
+ if collection.views && collection.versioned?
54
+ ret = ViewVersion.new(collection.views)
55
+ else
56
+ ret = collection
57
+ end
55
58
 
56
- handle_return_value(ret)
59
+ handle_return_value(ret)
60
+ end
57
61
  end
58
62
 
59
63
  # Pass these through, handling the return value.
@@ -109,7 +109,7 @@ module Pakyow
109
109
  #TODO need to consider whose responsibility it is to make the dups
110
110
  view = obj ? info[obj.to_sym] : info
111
111
  raise MissingView, "No #{obj} at path '#{view_path}'" if view.nil?
112
- return view.dup
112
+ return Pakyow::Utils::Dup.deep(view)
113
113
  end
114
114
  end
115
115
 
@@ -208,6 +208,8 @@ module Pakyow
208
208
  @path_info[normalized_path] = info
209
209
  end
210
210
  end
211
+
212
+ @path_info = Hash[@path_info.sort { |a, b| a <=> b }]
211
213
  end
212
214
 
213
215
  def normalize_path(path, store_path = nil)
@@ -3,7 +3,7 @@ class Pakyow::Presenter::ViewVersion
3
3
 
4
4
  def initialize(views)
5
5
  @empty = views.find { |view| view.version == :empty }
6
- @default = views.find { |view| !view.doc.get_attribute(:'data-default').nil? } || views.find { |view| view.version != :empty }
6
+ @default = views.find { |view| view.doc.attribute?(:'data-default') } || views.find { |view| view.version != :empty }
7
7
  @versions = views
8
8
  end
9
9
 
@@ -15,6 +15,16 @@ class Pakyow::Presenter::ViewVersion
15
15
  @default = versions.first
16
16
  end
17
17
 
18
+ def with(&block)
19
+ if block.arity == 0
20
+ instance_exec(&block)
21
+ else
22
+ yield(self)
23
+ end
24
+
25
+ self
26
+ end
27
+
18
28
  def apply(data, bindings: {}, context: nil, &block)
19
29
  data = Array.ensure(data)
20
30
 
@@ -31,7 +41,7 @@ class Pakyow::Presenter::ViewVersion
31
41
 
32
42
  def version(data, &block)
33
43
  data = Array.ensure(data)
34
- coll = Pakyow::Presenter::ViewCollection.new
44
+ coll = Pakyow::Presenter::ViewCollection.new(@default.scoped_as)
35
45
 
36
46
  if data.empty?
37
47
  @versions.each(&:remove)
@@ -79,7 +89,13 @@ class Pakyow::Presenter::ViewVersion
79
89
 
80
90
  def method_missing(method, *args, &block)
81
91
  if @default.respond_to?(method)
82
- @default.send(method, *args, &block)
92
+ ret = @default.send(method, *args, &block)
93
+
94
+ # because `match` mutates the default view (turning it into a collection), we
95
+ # need to set default to this new collection so that things continue to work
96
+ @default = ret if method == :match
97
+
98
+ ret
83
99
  end
84
100
  end
85
101
 
@@ -0,0 +1,26 @@
1
+ <%
2
+ path = String.normalize_path(request.path)
3
+ path = '/' if path.empty?
4
+
5
+ view_path = path == '/' ? 'index.html' : "#{path}.html"
6
+ %>
7
+
8
+ <h1>
9
+ Pakyow couldn't find anything to do :(
10
+ </h1>
11
+
12
+ <p class="lead">
13
+ If you want back-end code to execute for this request, create a route in <code>app/lib/routes.rb</code>:
14
+ </p>
15
+
16
+ <pre>
17
+ <code><span class="n">get</span> <span class="s1">'<%=path%>'</span> <span class="k">do</span>
18
+ <span class="c1"># your code goes here</span>
19
+ <span class="k">end</span></code>
20
+ </pre>
21
+
22
+ <p class="lead">
23
+ But, we recommend you start by creating a view at <code>app/views/<%=view_path%></code>.
24
+ The view will be served up automatically without writing any back-end code! This pattern
25
+ is called view-first development (you could also call it <em>awesome</em>).
26
+ </p>
@@ -0,0 +1,23 @@
1
+ <%
2
+ nice_source = req.error.backtrace[0].match(/^(.+?):(\d+)(|:in `(.+)')$/)
3
+ file = nice_source[1].gsub(File.expand_path(Config.app.root) + '/', '')
4
+ line = nice_source[2]
5
+ msg = CGI.escapeHTML("#{req.error.class}: #{req.error}")
6
+ trace = req.error.backtrace.map { |bt| CGI.escapeHTML(bt) }.join('<br>')
7
+ %>
8
+
9
+ <h1>
10
+ Pakyow found something wrong :(
11
+ </h1>
12
+
13
+ <p class="lead">
14
+ The error originated on line <%=line%> of <code><%=file%></code>.
15
+ </p>
16
+
17
+ <h5 class="error">
18
+ <%=msg%>
19
+ </h5>
20
+
21
+ <pre>
22
+ <code><%=trace%></code>
23
+ </pre>
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.10.2
4
+ version: 0.11.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: 2015-11-16 00:00:00.000000000 Z
12
+ date: 2016-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakyow-support
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.10.2
20
+ version: 0.11.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.10.2
27
+ version: 0.11.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.10.2
34
+ version: 0.11.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.10.2
41
+ version: 0.11.0
42
42
  - !ruby/object:Gem::Dependency
43
- name: nokogiri
43
+ name: oga
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.6'
48
+ version: '2.0'
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.6'
55
+ version: '2.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: minitest
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -105,33 +105,35 @@ files:
105
105
  - pakyow-presenter/LICENSE
106
106
  - pakyow-presenter/README.md
107
107
  - pakyow-presenter/lib/pakyow-presenter.rb
108
- - pakyow-presenter/lib/presenter/attributes.rb
109
- - pakyow-presenter/lib/presenter/base.rb
110
- - pakyow-presenter/lib/presenter/binder.rb
111
- - pakyow-presenter/lib/presenter/binder_set.rb
112
- - pakyow-presenter/lib/presenter/binding_eval.rb
113
- - pakyow-presenter/lib/presenter/config/presenter.rb
114
- - pakyow-presenter/lib/presenter/container.rb
115
- - pakyow-presenter/lib/presenter/doc_helpers.rb
116
- - pakyow-presenter/lib/presenter/exceptions.rb
117
- - pakyow-presenter/lib/presenter/ext/app.rb
118
- - pakyow-presenter/lib/presenter/helpers.rb
119
- - pakyow-presenter/lib/presenter/page.rb
120
- - pakyow-presenter/lib/presenter/partial.rb
121
- - pakyow-presenter/lib/presenter/presenter.rb
122
- - pakyow-presenter/lib/presenter/string_doc.rb
123
- - pakyow-presenter/lib/presenter/string_doc_parser.rb
124
- - pakyow-presenter/lib/presenter/string_doc_renderer.rb
125
- - pakyow-presenter/lib/presenter/template.rb
126
- - pakyow-presenter/lib/presenter/view.rb
127
- - pakyow-presenter/lib/presenter/view_collection.rb
128
- - pakyow-presenter/lib/presenter/view_composer.rb
129
- - pakyow-presenter/lib/presenter/view_context.rb
130
- - pakyow-presenter/lib/presenter/view_store.rb
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
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
135
137
  homepage: http://pakyow.org
136
138
  licenses:
137
139
  - MIT
@@ -152,9 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  version: '0'
153
155
  requirements: []
154
156
  rubyforge_project:
155
- rubygems_version: 2.4.5
157
+ rubygems_version: 2.5.1
156
158
  signing_key:
157
159
  specification_version: 4
158
160
  summary: Pakyow Presenter
159
161
  test_files: []
160
- has_rdoc:
@@ -1,27 +0,0 @@
1
- require 'yaml'
2
-
3
- require 'presenter/view_store'
4
- require 'presenter/view'
5
- require 'presenter/template'
6
- require 'presenter/page'
7
- require 'presenter/container'
8
- require 'presenter/partial'
9
- require 'presenter/view_collection'
10
- require 'presenter/binder'
11
- require 'presenter/binder_set'
12
- require 'presenter/attributes'
13
- require 'presenter/exceptions'
14
- require 'presenter/view_composer'
15
- require 'presenter/string_doc'
16
- require 'presenter/string_doc_parser'
17
- require 'presenter/string_doc_renderer'
18
- require 'presenter/binding_eval'
19
- require 'presenter/doc_helpers'
20
- require 'presenter/view_version'
21
- require 'presenter/view_context'
22
- require 'presenter/view_store_loader'
23
-
24
- module Pakyow
25
- module Presenter
26
- end
27
- end
@@ -1,63 +0,0 @@
1
- module Pakyow
2
- class App
3
- class << self
4
- @@bindings = {}
5
- @@processors = {}
6
-
7
- def bindings(set_name = :main, &block)
8
- if set_name && block
9
- @@bindings[set_name] = block
10
- else
11
- @@bindings
12
- end
13
- end
14
-
15
- def processor(*args, &block)
16
- args.each {|format|
17
- @@processors[format] = block
18
- }
19
- end
20
-
21
- def processors
22
- @@processors
23
- end
24
- end
25
-
26
- # Convenience method for defining bindings on an app instance.
27
- #
28
- def bindings(set_name = :main, &block)
29
- self.class.bindings(set_name, &block)
30
- end
31
-
32
- def content_for_code(code)
33
- content = File.open(
34
- File.join(
35
- File.expand_path(
36
- '../../../../../', __FILE__),
37
- 'pakyow-core',
38
- 'lib',
39
- 'views',
40
- 'errors',
41
- code.to_s + '.html'
42
- )
43
- ).read + File.open(
44
- File.join(
45
- File.expand_path(
46
- '../../../', __FILE__),
47
- 'views',
48
- 'errors',
49
- code.to_s + '.html'
50
- )
51
- ).read
52
-
53
- path = String.normalize_path(request.path)
54
- path = '/' if path.empty?
55
-
56
- content.gsub!('{view_path}', path == '/' ? 'index.html' : "#{path}.html")
57
-
58
- template = presenter.store.template(:default)
59
- template.container(:default).replace(content)
60
- template.to_html
61
- end
62
- end
63
- end