lib/express_templates/components/capabilities/resourceful.rb in express_templates-0.9.8 vs lib/express_templates/components/capabilities/resourceful.rb in express_templates-0.10.1

- old
+ new

@@ -36,11 +36,11 @@ def _namespaced_resource_class if namespace "#{namespace}/#{resource_name}".classify else - resource_name.classify + resource_name.to_s.classify end end def template_virtual_path begin @@ -118,11 +118,11 @@ config[:collection].call() else config[:collection] end else - helpers.collection + self.send(collection_name) # should be in view assigns end end def collection_path if config[:collection_path] @@ -168,31 +168,27 @@ resource_class_name = resource_class.to_s resource_class_name.match(/::/) ? resource_class_name.split("::").first.try(:underscore) : nil end - # accepts boolean to indicate whether to use an ivar or not - # and also may accept a resource on which we call to_param - def resource_path(ivar_or_resource = nil) + def resource_path(object = nil) if config[:resource_path] - if config[:resource_path].respond_to?(:call) && - ivar_or_resource.respond_to?(:to_param) && - ![true, false].include?(ivar_or_resource) - config[:resource_path].call(ivar_or_resource) + if config[:resource_path].respond_to?(:call) && object.respond_to?(:to_param) + config[:resource_path].call(object) else config[:resource_path] end else if helpers.respond_to?(:resource_path) && helpers.resource.to_param.present? # skip on nil resource helpers.resource_path else - if ivar_or_resource.respond_to?(:to_param) && - ![true, false].include?(ivar_or_resource) - helpers.instance_eval("#{resource_path_helper}('#{ivar_or_resource.to_param}')") + if resource_path_helper.match(/\w+\.\w+/) + namespace, path_helper = resource_path_helper.split('.') + helpers.send(namespace).send(path_helper, object) else - helpers.instance_eval("#{resource_path_helper}(#{ivar_or_resource ? '@' : ''}#{resource_name})") + helpers.send(resource_path_helper, object) end end end end @@ -204,9 +200,13 @@ end end def resource_attributes resource_class.columns + end + + def resource + self.send(resource_name) end end end end end