Class: DeadSimpleCMS::Section::Builder
- Inherits:
-
Object
- Object
- DeadSimpleCMS::Section::Builder
- Defined in:
- lib/dead_simple_cms/section/builder.rb
Overview
Public: A Builder class which provides a nice DSL to describe different sections of the site that a user wants to modify through a CMS.
Instance Attribute Summary collapse
-
#group_hierarchy ⇒ Object
Returns the value of attribute group_hierarchy.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Class Method Summary collapse
Instance Method Summary collapse
- #group(*args, &block) ⇒ Object
-
#initialize(section, &block) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(section, &block) ⇒ Builder
Returns a new instance of Builder.
23 24 25 26 27 |
# File 'lib/dead_simple_cms/section/builder.rb', line 23 def initialize(section, &block) @section = section @group_hierarchy = [] instance_eval(&block) end |
Instance Attribute Details
#group_hierarchy ⇒ Object
Returns the value of attribute group_hierarchy.
7 8 9 |
# File 'lib/dead_simple_cms/section/builder.rb', line 7 def group_hierarchy @group_hierarchy end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
8 9 10 |
# File 'lib/dead_simple_cms/section/builder.rb', line 8 def section @section end |
Class Method Details
.define_attribute_builder_method(klass) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dead_simple_cms/section/builder.rb', line 12 def self.define_attribute_builder_method(klass) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{klass.builder_method_name}(identifier, options={}) group_hierarchy = self.group_hierarchy.presence || [section.root_group] # fallback on the root group attribute = #{klass}.new(identifier, options.merge(:group_hierarchy => group_hierarchy, :section => section)) group_hierarchy.last.add_attribute(attribute) section.add_attribute(attribute) end RUBY end |
Instance Method Details
#group(*args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dead_simple_cms/section/builder.rb', line 29 def group(*args, &block) = args. = .delete(:attribute_options) || {} identifier = args.first # If no identifier provided, first key, value pair of the hash is the identifier => group_configuration. identifier, group_configuration = .shift unless identifier unless group_configuration.is_a?(DeadSimpleCMS::Group::Configuration) group_configuration = DeadSimpleCMS.group_configurations[group_configuration] end .update(group_configuration.) if group_configuration group = Group.new(identifier, ) nest_group(group) do if group_configuration display(group_configuration.presenter_class, &group_configuration.render_proc) group_configuration.attribute_arguments.each do |attribute_identifier, (attribute_type, )| = .merge([attribute_identifier] || {}) send(attribute_type, attribute_identifier, ) end end instance_eval(&block) if block_given? end end |