Module: Gluttonberg::Content::Block
- Extended by:
- ActiveSupport::Concern
- Included in:
- HtmlContent, ImageContent, PlainTextContent, SelectContent, TextareaContent
- Defined in:
- lib/gluttonberg/content/block.rb
Overview
This module can be mixed into a class to make it behave like a content block. A content block is a class that can be associated with a section on in a page description.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.classes ⇒ Object
An accessor which provides the collection of classes with mixin this module.
-
.register(klass) ⇒ Object
register content classes.
Instance Method Summary collapse
-
#association_name ⇒ Object
The name of the generated association.
-
#content_type ⇒ Object
Content type is simply the inflected version of the content class name, e.g.
-
#load_localization(id_or_model) ⇒ Object
Loads a localized version based on the specified page localization, then stashes it in an accessor.
-
#localized? ⇒ Boolean
Checks to see if this content class has localized properties.
-
#section ⇒ Object
Returns the section this content instance is associated with.
- #section_label ⇒ Object
- #section_position ⇒ Object
- #select_options_data ⇒ Object
- #select_options_default_value ⇒ Object
Class Method Details
.classes ⇒ Object
An accessor which provides the collection of classes with mixin this module.
37 38 39 |
# File 'lib/gluttonberg/content/block.rb', line 37 def self.classes @classes end |
.register(klass) ⇒ Object
register content classes. We can do this inside included block, but in rails lazyloading behavior it is not properly working.
30 31 32 33 |
# File 'lib/gluttonberg/content/block.rb', line 30 def self.register(klass) @classes << klass @classes.uniq! end |
Instance Method Details
#association_name ⇒ Object
The name of the generated association. This is the association that
119 120 121 |
# File 'lib/gluttonberg/content/block.rb', line 119 def association_name self.class.association_name end |
#content_type ⇒ Object
Content type is simply the inflected version of the content class name, e.g. FooContent becomes :foo_content
148 149 150 |
# File 'lib/gluttonberg/content/block.rb', line 148 def content_type self.class.content_type end |
#load_localization(id_or_model) ⇒ Object
Loads a localized version based on the specified page localization, then stashes it in an accessor
154 155 156 157 158 159 160 |
# File 'lib/gluttonberg/content/block.rb', line 154 def load_localization(id_or_model) if localized? localization_id = id_or_model.is_a?(Numeric) ? id_or_model : id_or_model.id conditions = {:page_localization_id => localization_id, :"#{self.class.content_type}_id" => id} @current_localization = localizations.find(:first , :conditions => conditions) end end |
#localized? ⇒ Boolean
Checks to see if this content class has localized properties.
114 115 116 |
# File 'lib/gluttonberg/content/block.rb', line 114 def localized? self.class.localized? end |
#section ⇒ Object
Returns the section this content instance is associated with. It does this by looking at the associated page, it’s description then the matching section.
109 110 111 |
# File 'lib/gluttonberg/content/block.rb', line 109 def section @section ||= page.description.sections[section_name.to_sym] end |
#section_label ⇒ Object
124 125 126 |
# File 'lib/gluttonberg/content/block.rb', line 124 def section_label section[:label] end |
#section_position ⇒ Object
142 143 144 |
# File 'lib/gluttonberg/content/block.rb', line 142 def section_position section[:position] if section end |
#select_options_data ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/gluttonberg/content/block.rb', line 128 def unless section[:select_options_data].blank? section[:select_options_data].call else [] end end |
#select_options_default_value ⇒ Object
136 137 138 139 140 |
# File 'lib/gluttonberg/content/block.rb', line 136 def unless section[:select_options_default_value].blank? section[:select_options_default_value].call end end |