pakyow-presenter/lib/presenter/view_context.rb in pakyow-presenter-0.9.1 vs pakyow-presenter/lib/presenter/view_context.rb in pakyow-presenter-0.10.0
- old
+ new
@@ -4,23 +4,29 @@
# AppContext to all binding methods. This object is expected to only
# be used from the app, not internally.
#
class ViewContext
include Helpers
- VIEW_CLASSES = [View, ViewCollection, Partial, Template, Container]
+ VIEW_CLASSES = [View, ViewCollection, Partial, Template, Container, ViewVersion]
# The arities of misc view methods that switch the behavior from
# instance_exec to yield.
#
EXEC_ARITIES = { with: 0, for: 1, for_with_index: 2, repeat: 1,
repeat_with_index: 2, bind: 1, bind_with_index: 2, apply: 1 }
+ attr_reader :context
+
def initialize(view, context)
@view = view
@context = context
end
+ def subject
+ @view
+ end
+
# View methods that expect context, so it can be mixed in.
#
%i[bind bind_with_index apply].each do |method|
define_method(method) do |data, **kargs, &block|
kargs[:context] ||= @context
@@ -34,9 +40,21 @@
%i[with for for_with_index repeat repeat_with_index].each do |method|
define_method(method) do |*args, &block|
ret = @view.send(method, *args, &wrap(method, &block))
handle_return_value(ret)
end
+ end
+
+ def scope(name)
+ collection = @view.scope(name)
+
+ if !collection.is_a?(ViewVersion) && collection.versioned?
+ ret = ViewVersion.new(collection.views)
+ else
+ ret = collection
+ end
+
+ handle_return_value(ret)
end
# Pass these through, handling the return value.
#
def method_missing(method, *args, &block)