the content_entries API returns always a flat list of entries + fix a bug about cycling dependencies when the content_type has a field named source

This commit is contained in:
Didier Lafforgue 2012-03-07 02:56:56 +01:00
parent ac823aac66
commit 37042eaa03
2 changed files with 15 additions and 10 deletions

View File

@ -5,7 +5,7 @@ module Locomotive
before_filter :set_content_type before_filter :set_content_type
def index def index
@content_entries = @content_type.list_or_group_entries @content_entries = @content_type.ordered_entries
respond_with @content_entries respond_with @content_entries
end end

View File

@ -36,16 +36,21 @@ module Locomotive
super + self.filtered_custom_fields_methods + default_list super + self.filtered_custom_fields_methods + default_list
end end
def method_missing(meth, *arguments, &block) def as_json(methods = nil)
if self.source.custom_fields_methods.include?(meth.to_s) methods ||= self.included_methods
if self.source.is_a_custom_field_many_relationship?(meth.to_s) {}.tap do |hash|
# go deeper methods.each do |meth|
self.source.send(meth).map { |entry| entry.to_presenter(:depth => self.depth + 1) } hash[meth]= (if self.source.custom_fields_methods.include?(meth.to_s)
else if self.source.is_a_custom_field_many_relationship?(meth.to_s)
self.source.send(meth) rescue nil # go deeper
self.source.send(meth).map { |entry| entry.to_presenter(:depth => self.depth + 1) }
else
self.source.send(meth) rescue nil
end
else
self.send(meth.to_sym) rescue nil
end)
end end
else
super
end end
end end