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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 901a17c34b45df79bb990ed3253e7bda1000859b
4
- data.tar.gz: 28581cf21dae5f2b3b6a44e253b09843628f101e
3
+ metadata.gz: f22ae8bbc000b21b49861cdd2319f2aed3ee137f
4
+ data.tar.gz: 1f565dcb4c706fd63d5082d841dc1c849461b7b1
5
5
  SHA512:
6
- metadata.gz: 7c6b0c8bff73444ff667022d860c343bf06f7f50add710dd212cd5f66eceae71209ca555358f6a89bc4d9f998397ca832dae80c66868d61db6926a6f760b5aa4
7
- data.tar.gz: 098f651f7932f30151d173c432901e0475af25de286c32e8e739872245a783d18c769a548dc64012b4087cea644bd2b373ce54946c66d60e4c58daa252266bdb
6
+ metadata.gz: 4a24146da5ccf0c9b59e7053556f81bb11537983c0ec0b9d18ed46ec72b88756e9464621fcbf32462a40de5f850849574d60f65945930b76a8cd8c87ca58701e
7
+ data.tar.gz: 0012d2741b5d85896d5532db529a8876574a3d5b4ae0ad05265f3f94dd47223609ee61c3153e3372c8367cb2ae96f3cfeb172824b50fc2a54df6e2f457b391c7
@@ -1,3 +1,19 @@
1
+ # 0.11.0
2
+
3
+ * Fixes several bugs related to nested partials
4
+ * Reprocesses view contents with html processor
5
+ * Fixes a bug causing partials not to be duped
6
+ * Automatically defines bindings as restful
7
+ * Introduces binding parts
8
+ * Fixes a bug removing a node from StringDoc
9
+ * Renames `app.all_views_visible` config option to `presenter.require_route`
10
+ * Fixes some bugs caused by not properly duping view objects
11
+ * Replaces Nokogiri with Oga
12
+ * Moves everything into the Pakyow namespace
13
+ * Adds support for versioned props
14
+ * Prioritize root view paths over child paths
15
+ * ViewVersion state is now properly updated when matching
16
+
1
17
  # 0.10.0 / 2015-10-19
2
18
 
3
19
  * Adds precomposition to composer
@@ -1,11 +1 @@
1
- libdir = File.dirname(__FILE__)
2
- $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
-
4
- # Gems
5
- require 'nokogiri'
6
-
7
- require 'presenter/base'
8
- require 'presenter/presenter'
9
- require 'presenter/config/presenter'
10
- require 'presenter/helpers'
11
- require 'presenter/ext/app'
1
+ require 'pakyow/presenter'
@@ -0,0 +1,8 @@
1
+ require 'oga'
2
+
3
+ require 'pakyow/presenter/base'
4
+ require 'pakyow/presenter/presenter'
5
+ require 'pakyow/presenter/config/presenter'
6
+ require 'pakyow/presenter/helpers'
7
+ require 'pakyow/presenter/ext/app'
8
+ require 'pakyow/presenter/ext/call_context'
@@ -1,12 +1,6 @@
1
1
  module Pakyow
2
2
  module Presenter
3
3
  class Attribute
4
- @@types = {
5
- :hash => [:style],
6
- :bool => [:selected, :checked, :disabled, :readonly, :multiple],
7
- :mult => [:class]
8
- }
9
-
10
4
  def initialize(name, raw_value, control, doc)
11
5
  @type = type_of_attribute(name)
12
6
  @name = name
@@ -77,6 +71,14 @@ module Pakyow
77
71
  self.class.ancestors
78
72
  end
79
73
 
74
+ def types
75
+ @types ||= {
76
+ :hash => [:style],
77
+ :bool => [:selected, :checked, :disabled, :readonly, :multiple],
78
+ :mult => [:class]
79
+ }
80
+ end
81
+
80
82
  private
81
83
 
82
84
  def update_value
@@ -92,9 +94,9 @@ module Pakyow
92
94
  def type_of_attribute(attribute)
93
95
  attribute = attribute.to_sym
94
96
 
95
- return :bool if @@types[:bool].include?(attribute)
96
- return :mult if @@types[:mult].include?(attribute)
97
- return :hash if @@types[:hash].include?(attribute)
97
+ return :bool if types[:bool].include?(attribute)
98
+ return :mult if types[:mult].include?(attribute)
99
+ return :hash if types[:hash].include?(attribute)
98
100
  return :single
99
101
  end
100
102
 
@@ -155,6 +157,10 @@ module Pakyow
155
157
  method_missing(:id, *args)
156
158
  end
157
159
 
160
+ def method(*args)
161
+ method_missing(:method, *args)
162
+ end
163
+
158
164
  def update_value_for_attribute(attribute, value)
159
165
  @doc.update_attribute(attribute, value)
160
166
  end
@@ -163,6 +169,10 @@ module Pakyow
163
169
  @doc.remove_attribute(attribute)
164
170
  end
165
171
 
172
+ def include?(attribute)
173
+ @doc.has_attribute?(attribute)
174
+ end
175
+
166
176
  protected
167
177
 
168
178
  def set_attribute(attribute, value)
@@ -170,11 +180,8 @@ module Pakyow
170
180
  end
171
181
 
172
182
  def get_attribute(attribute)
173
- unless a = @attributes[attribute]
174
- a = Attribute.new(attribute, @doc.get_attribute(attribute), self, @doc)
175
- end
176
-
177
- return a
183
+ @attributes[attribute] ||
184
+ Attribute.new(attribute, @doc.get_attribute(attribute), self, @doc)
178
185
  end
179
186
  end
180
187
 
@@ -0,0 +1,38 @@
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
@@ -59,16 +59,29 @@ module Pakyow
59
59
 
60
60
  if binding_fn
61
61
  binding_eval = BindingEval.new(prop, bindable, context)
62
- binding_eval.instance_exec(binding_eval.value, bindable, context, &binding_fn)
63
- else # default value
64
- if bindable.is_a?(Hash)
65
- bindable.fetch(prop) { bindable[prop.to_s] }
66
- elsif bindable.class.method_defined?(prop)
67
- bindable.send(prop)
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
68
69
  end
70
+ result
71
+ else # default value
72
+ value_from_data(prop, bindable)
69
73
  end
70
74
  end
71
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
+
72
85
  # Returns true if a binding is defined for the scope->prop.
73
86
  #
74
87
  def has_scoped_prop?(scope, prop, bindings)
@@ -68,28 +68,25 @@ module Pakyow
68
68
 
69
69
  def restful(route_group)
70
70
  binding :_root do
71
- routes = Router.instance.group(route_group)
72
-
73
- {
74
- view: lambda { |view|
75
- action = view.attrs.action.value
76
- return if (action && !action.empty?)
77
-
78
- route_params = params.dup
79
- if view.doc.tagname == 'form'
80
- if id = bindable[:id]
81
- view.prepend(View.new('<input type="hidden" name="_method" value="patch">'))
82
- route_params[:"#{route_group}_id"] = id
83
- action = :update
84
- else
85
- action = :create
86
- end
87
-
88
- view.attrs.action = routes.path(action, route_params)
89
- view.attrs.method = 'post'
71
+ part :view do |view|
72
+ routes = Router.instance.group(route_group)
73
+ action = view.attrs.action.value
74
+ next if (action && !action.empty?)
75
+
76
+ route_params = params.dup
77
+ if view.doc.tagname == 'form'
78
+ if id = bindable[:id]
79
+ view.prepend(View.new('<input type="hidden" name="_method" value="patch">'))
80
+ route_params[:"#{route_group}_id"] = id
81
+ action = :update
82
+ else
83
+ action = :create
90
84
  end
91
- }
92
- }
85
+
86
+ view.attrs.action = routes.path(action, route_params)
87
+ view.attrs.method = 'post'
88
+ end
89
+ end
93
90
  end
94
91
  end
95
92
  end
@@ -6,6 +6,7 @@ module Pakyow
6
6
  attr_reader :context, :bindable
7
7
 
8
8
  def initialize(prop, bindable, context)
9
+ @parts = {}
9
10
  @prop = prop
10
11
  @bindable = bindable
11
12
  @context = context
@@ -18,6 +19,19 @@ module Pakyow
18
19
  bindable.send(@prop)
19
20
  end
20
21
  end
22
+
23
+ def eval(&block)
24
+ ret = instance_exec(value, bindable, context, &block)
25
+ if ret.respond_to?(:to_hash)
26
+ @parts.merge!(ret.to_hash)
27
+ end
28
+ @parts.empty? ? ret : @parts
29
+ end
30
+
31
+ def part(name, &block)
32
+ @parts[name.to_sym] = block
33
+ nil # Return nil so #part return value is ignored
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -1,7 +1,6 @@
1
- Pakyow::Config.register(:presenter) { |config|
2
-
1
+ Pakyow::Config.register :presenter do |config|
3
2
  # registered view stores
4
- config.opt :view_stores, lambda {
3
+ config.opt :view_stores, -> {
5
4
  @stores ||= {
6
5
  default: File.join(Pakyow::Config.app.root, 'app', 'views')
7
6
  }
@@ -11,7 +10,7 @@ Pakyow::Config.register(:presenter) { |config|
11
10
  config.opt :default_views, { default: :default }
12
11
 
13
12
  # a convenience option to lookup the default_view for a view store by name
14
- config.opt :default_view, lambda { |store_name|
13
+ config.opt :default_view, -> (store_name) {
15
14
  views = Pakyow::Config.presenter.default_views
16
15
  views.fetch(store_name) { views[:default] }
17
16
  }
@@ -20,7 +19,7 @@ Pakyow::Config.register(:presenter) { |config|
20
19
  config.opt :template_dirs, { default: '_templates' }
21
20
 
22
21
  # a convenience option to lookup the template_dir for a view store by name
23
- config.opt :template_dir, lambda { |store_name|
22
+ config.opt :template_dir, -> (store_name) {
24
23
  dirs = Pakyow::Config.presenter.template_dirs
25
24
  dirs.fetch(store_name) { dirs[:default] }
26
25
  }
@@ -31,6 +30,13 @@ Pakyow::Config.register(:presenter) { |config|
31
30
  # the attribute expected for prop definitions
32
31
  config.opt :prop_attribute, 'data-prop'
33
32
 
33
+ # if true, views are visible without a route defined
34
+ config.opt :require_route, true
35
+
34
36
  # the document class used to parse and render views
35
37
  config.opt :view_doc_class, Pakyow::Presenter::StringDoc
36
- }
38
+ end.env :development do |opts|
39
+ opts.require_route = false
40
+ end.env :production do |opts|
41
+ opts.require_route = true
42
+ end
@@ -0,0 +1,33 @@
1
+ module Pakyow
2
+ class App
3
+ class << self
4
+ RESOURCE_ACTIONS[:presenter] = Proc.new { |app, set_name, _, _|
5
+ app.bindings { scope(set_name) { restful(set_name) } }
6
+ }
7
+
8
+ def bindings(set_name = :main, &block)
9
+ if set_name && block
10
+ bindings[set_name] = block
11
+ else
12
+ @bindings ||= {}
13
+ end
14
+ end
15
+
16
+ def processor(*args, &block)
17
+ args.each {|format|
18
+ processors[format] = block
19
+ }
20
+ end
21
+
22
+ def processors
23
+ @processors ||= {}
24
+ end
25
+ end
26
+
27
+ # Convenience method for defining bindings on an app instance.
28
+ #
29
+ def bindings(set_name = :main, &block)
30
+ self.class.bindings(set_name, &block)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ require 'erb'
2
+
3
+ module Pakyow
4
+ class CallContext
5
+ protected
6
+
7
+ def presenter_handle_error(code)
8
+ return if !config.app.errors_in_browser || req.format != :html
9
+ response.body = [content_for_code(code)]
10
+ end
11
+
12
+ def content_for_code(code)
13
+ content = ERB.new(File.read(path_for_code(code))).result(binding)
14
+ page = Presenter::Page.new(:presenter, content, '/')
15
+ composer = presenter.compose_at('/', page: page)
16
+ composer.to_html
17
+ end
18
+
19
+ def path_for_code(code)
20
+ File.join(
21
+ File.expand_path('../../../', __FILE__),
22
+ 'views',
23
+ 'errors',
24
+ code.to_s + '.erb'
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ require 'forwardable'
2
+
3
+ module Pakyow
4
+ module Helpers
5
+ module Context
6
+ extend Forwardable
7
+
8
+ def_delegators :@presenter, :store, :store=, :content, :view=,
9
+ :template=, :page=, :path, :path=, :compose, :composer, :precompose!
10
+
11
+ def view
12
+ Presenter::ViewContext.new(presenter.view, self)
13
+ end
14
+
15
+ def partial(*args)
16
+ Presenter::ViewContext.new(presenter.partial(*args), self)
17
+ end
18
+
19
+ def template
20
+ Presenter::ViewContext.new(presenter.template, self)
21
+ end
22
+
23
+ def page
24
+ Presenter::ViewContext.new(presenter.page, self)
25
+ end
26
+
27
+ def container(*args)
28
+ Presenter::ViewContext.new(presenter.container(*args), self)
29
+ end
30
+
31
+ def bindings(name)
32
+ presenter.bindings(name).bindings
33
+ end
34
+
35
+ def presenter
36
+ @presenter
37
+ end
38
+ end
39
+
40
+ module App
41
+ def presenter
42
+ @presenter
43
+ end
44
+ end
45
+ end
46
+ end