Module: Gluttonberg::Content::Block::ClassMethods
- Defined in:
- lib/gluttonberg/content/block.rb
Instance Method Summary collapse
-
#all_with_localization(opts) ⇒ Object
Returns all the matching models with the specificed localization loaded.
-
#is_localized(&blk) ⇒ Object
This declaration is used to create properties on a model which need to be localized.
-
#localized? ⇒ Boolean
Does this class have an associated localization class.
Instance Method Details
#all_with_localization(opts) ⇒ Object
Returns all the matching models with the specificed localization loaded.
96 97 98 99 100 101 |
# File 'lib/gluttonberg/content/block.rb', line 96 def all_with_localization(opts) page_localization_id = opts.delete(:page_localization_id) results = all(opts) results.each { |r| r.load_localization(page_localization_id) } results end |
#is_localized(&blk) ⇒ Object
This declaration is used to create properties on a model which need to be localized. It does this by generating a localized class and association.
It also registers the class as being localized.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gluttonberg/content/block.rb', line 55 def is_localized(&blk) self.localized = true self.attr_accessible :section_name # Generate the localization model class_name = "#{self.name.demodulize}Localization" storage_name = "gb_#{class_name.tableize}" localized_model = Class.new(ActiveRecord::Base) foreign_key = self.name.foreign_key localized_model.table_name = storage_name Gluttonberg.const_set(class_name, localized_model) # Mix in our base set of properties and methods localized_model.send(:include, Gluttonberg::Content::BlockLocalization) # Generate additional properties from the block passed in localized_model.class_eval(&blk) # Store the name so we can easily access it without having to look # at this parent class localized_model.content_type = self.content_type # Tell the content module that we are localized localized_model.association_name = "#{self.content_type}_localizations" Gluttonberg::Content.register_localization( "#{self.content_type}_localizations".to_sym , localized_model) # Set up the associations has_many :localizations, :class_name => Gluttonberg.const_get(class_name).to_s , :foreign_key => "#{self.content_type}_id" , :dependent => :destroy localized_model.belongs_to(:parent, :class_name => self.name , :foreign_key => "#{self.content_type}_id") localized_model.attr_accessible :text, :parent, :page_localization localized_model.is_versioned localized_model.clean_html([:text]) end |
#localized? ⇒ Boolean
Does this class have an associated localization class.
91 92 93 |
# File 'lib/gluttonberg/content/block.rb', line 91 def localized? self.localized end |