lib/hanami/extensions/action/slice_configured_action.rb in hanami-2.0.3 vs lib/hanami/extensions/action/slice_configured_action.rb in hanami-2.1.0.beta1

- old
+ new

@@ -119,21 +119,29 @@ view_identifiers = actions_config.view_name_inferrer.call( action_class_name: action_class.name, slice: slice, ) - view_identifiers.detect do |identifier| - break slice[identifier] if slice.key?(identifier) + view_identifiers.each do |identifier| + return slice[identifier] if slice.key?(identifier) end + + nil end def resolve_view_context - identifier = actions_config.view_context_identifier + if Hanami.bundled?("hanami-view") + return Extensions::View::Context.context_class(slice).new + end - if slice.key?(identifier) - slice[identifier] - elsif slice.app.key?(identifier) - slice.app[identifier] + # If hanami-view isn't bundled, try and find a possible third party context class with the + # same `Views::Context` name (but don't fall back to automatically defining one). + if slice.namespace.const_defined?(:Views) + views_namespace = slice.namespace.const_get(:Views) + + if views_namespace.const_defined?(:Context) + views_namespace.const_get(:Context).new + end end end def resolve_routes slice.app["routes"] if slice.app.key?("routes")