lib/pakyow/presenter/presenter.rb in pakyow-presenter-1.0.0.rc3 vs lib/pakyow/presenter/presenter.rb in pakyow-presenter-1.0.0.rc4

- old
+ new

@@ -252,27 +252,16 @@ # unless presenter.view.used? presenter.use_implicit_version end - used_view = case presenter.view.object - when StringDoc::MetaNode - View.from_object( - presenter.view.object.nodes.find { |node| - node.labeled?(:versioned) - } - ) - else - presenter.view.versions.find { |version| - version.object.labeled?(:versioned) - } - end - - used_view.binding_props.map { |binding_prop| + # Implicitly use binding props. + # + presenter.view.binding_props.map { |binding_prop| binding_prop.label(:binding) }.uniq.each do |binding_prop_name| - if found = used_view.find(binding_prop_name) + if found = presenter.view.find(binding_prop_name) presenter_for(found).use_implicit_version unless found.used? end end end @@ -281,18 +270,18 @@ presenter.view.binding_scopes.uniq { |binding_scope| binding_scope.label(:binding) }.each do |binding_node| plural_binding_node_name = Support.inflector.pluralize(binding_node.label(:binding)).to_sym - nested_view = presenter.find(binding_node.label(:binding)) - - if binder.object.include?(binding_node.label(:binding)) - nested_view.present(binder.object[binding_node.label(:binding)]) - elsif binder.object.include?(plural_binding_node_name) - nested_view.present(binder.object[plural_binding_node_name]) - else - nested_view.remove + if nested_view = presenter.find(binding_node.label(:binding)) + if binder.object.include?(binding_node.label(:binding)) + nested_view.present(binder.object[binding_node.label(:binding)]) + elsif binder.object.include?(plural_binding_node_name) + nested_view.present(binder.object[plural_binding_node_name]) + else + nested_view.remove + end end end end end end @@ -387,12 +376,15 @@ end def to_html(output = String.new) @view.object.to_html(output, context: self) end - alias to_s to_html + def to_s + @view.to_s + end + def presenter_for(view, type: nil) if view.nil? nil else instance = self.class.new( @@ -406,17 +398,27 @@ end end # @api private def endpoint(name) + found = [] + object.each_significant_node(:endpoint) do |endpoint_node| if endpoint_node.label(:endpoint) == name.to_sym - return presenter_for(View.from_object(endpoint_node)) + found << endpoint_node end end - nil + if found.any? + if found[0].is_a?(StringDoc::MetaNode) + presenter_for(View.from_object(found[0])) + else + presenter_for(View.from_object(StringDoc::MetaNode.new(found))) + end + else + nil + end end # @api private def endpoint_action endpoint_action_node = object.find_first_significant_node( @@ -682,16 +684,11 @@ relate_value_to_render(return_value, render, views_with_renders) end end views_with_renders.values.each do |view_with_renders, renders_for_view| - attach_to_node = case view_with_renders - when VersionedView - StringDoc::MetaNode.new(view_with_renders.versions.map(&:object)) - when View - view_with_renders.object - end + attach_to_node = view_with_renders.object if attach_to_node.is_a?(StringDoc) attach_to_node = attach_to_node.find_first_significant_node(:html) end @@ -723,10 +720,10 @@ case node when StringDoc::MetaNode if node.nodes.any? returning = node presenter = context.presenter_for( - VersionedView.new([View.from_object(node)]) + VersionedView.new(View.from_object(node)) ) else next node end when StringDoc::Node