new custom_fields gem

This commit is contained in:
did 2011-03-20 21:12:40 +01:00
parent 1e5624ce06
commit d270bf8f69
4 changed files with 14 additions and 77 deletions

View File

@ -20,8 +20,7 @@ gem 'inherited_resources', '~> 1.1.2'
gem 'rmagick', '2.12.2'
gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave'
# gem 'custom_fields', '1.0.0.beta.7'
gem 'custom_fields', '1.0.0.beta.7', :path => '../gems/custom_fields'
gem 'custom_fields', '1.0.0.beta.8'
gem 'fog', '0.3.7'
gem 'mimetype-fu'
gem 'actionmailer-with-request'

View File

@ -11,14 +11,6 @@ GIT
xpath (0.1.2)
nokogiri (~> 1.4)
PATH
remote: ../gems/custom_fields
specs:
custom_fields (1.0.0.beta.7)
activesupport (>= 3.0.4)
locomotive_carrierwave
mongoid (~> 2.0.0.rc.7)
GEM
remote: http://rubygems.org/
specs:
@ -85,6 +77,10 @@ GEM
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.15)
custom_fields (1.0.0.beta.8)
activesupport (>= 3.0.4)
locomotive_carrierwave
mongoid (~> 2.0.0.rc.7)
daemons (1.1.0)
database_cleaner (0.6.6)
delayed_job (2.1.4)
@ -265,7 +261,7 @@ DEPENDENCIES
capybara
cucumber (= 0.8.5)
cucumber-rails
custom_fields (= 1.0.0.beta.7)!
custom_fields (= 1.0.0.beta.8)
database_cleaner
delayed_job (= 2.1.4)
delayed_job_mongoid (= 1.0.2)

View File

@ -7,23 +7,20 @@ module Admin::ContentTypesHelper
@content_types = current_site.content_types.ordered.
limit(:contents => Locomotive.config.lastest_items_nb).
only(:name, :slug, :highlighted_field_name, :updated_at).to_a
# only(:name, :slug, :highlighted_field_name, :content_custom_fields_updated_at).to_a
only(:name, :slug, :highlighted_field_name, :content_custom_fields_version).to_a
if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS
@content_types.delete(@content_type)
@content_types.insert(0, @content_type)
end
# # be sure, we've got the custom klass up-to-date, otherwise it will fail miserably
# @content_types.each do |content_type|
# # puts "content_type custom_fields !!! ? #{content_type.name} / #{content_type.content_klass.try(:built_at).inspect} / #{content_type.content_custom_fields_updated_at.try(:utc)}"
# if content_type.content_klass_out_of_date?
# puts "RELOADED #{content_type.name}"
# content_type.reload
# content_type.invalidate_content_klass
# end
# end
# be sure, we've got the custom klass up-to-date, otherwise it will fail miserably
@content_types.each do |content_type|
if content_type.content_klass_out_of_date?
content_type.reload
content_type.invalidate_content_klass
end
end
@content_types
end

View File

@ -14,62 +14,7 @@ module CustomFields
end
end
module Category # TODO: patch to apply in the next CustomFields version
module InstanceMethods
def category_to_hash
{ 'category_items' => self.category_items.collect(&:to_hash) }
end
end
class Item
def to_hash(more = {})
self.fields.keys.inject({}) do |memo, meth|
memo[meth] = self.send(meth.to_sym); memo
end.merge({
'id' => self._id,
'new_record' => self.new_record?,
'errors' => self.errors
}).merge(more)
end
def to_json
self.to_hash.to_json
end
end
end
end
class Field # TODO: patch to apply in the next CustomFields version
after_save :invalidate_klass
def to_hash_with_types(more = {})
to_hash_without_types(more).tap do |hash|
self.class.field_types.keys.each do |type|
if self.respond_to?(:"#{type}_to_hash")
hash.merge!(self.send(:"#{type}_to_hash"))
end
end
end
end
alias_method_chain :to_hash, :types
protected
def invalidate_klass
target_name = self.association_name.to_s.gsub('_custom_fields', '')
self._parent.send(:"invalidate_#{target_name}_klass")
end
end
end