Module: DeadSimpleCMS::Rails::ActionView::FormBuilders::Interface
- Included in:
- Default, SimpleForm
- Defined in:
- lib/dead_simple_cms/rails/action_view/form_builders/interface.rb
Overview
Public: Interface used for a form builder to work with dead simple cms.
Class Method Summary collapse
Instance Method Summary collapse
- #actions(&block) ⇒ Object
- #attribute(attribute) ⇒ Object
- #fields_for_group(section_or_group, options = {}) ⇒ Object
- #preview(section) ⇒ Object
- #radio_buttons(identifier, collection) ⇒ Object
- #update ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 8 def self.included(base) base.class_eval do class_attribute :form_for_method self.form_for_method = :form_for class_attribute :form_for_options self. = {} [:update, :actions, :preview, :attribute].each do |name| option_name = "#{name}_options" class_attribute option_name, :instance_writer => false self.send("#{option_name}=", {}) end end super end |
Instance Method Details
#actions(&block) ⇒ Object
38 39 40 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 38 def actions(&block) @template.content_tag(:div, , &block) end |
#attribute(attribute) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 25 def attribute(attribute) label(attribute.identifier, attribute.label) + case attribute.input_type when :string then text_field(attribute.identifier) when :text then text_area(attribute.identifier) when :file then file_field(attribute.identifier) when :select then select(attribute.identifier, attribute.collection) when :radio then (attribute.identifier, attribute.collection) when :check_box then check_box(attribute.identifier) else raise("Unknown type: #{attribute.identifier}") end end |
#fields_for_group(section_or_group, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 54 def fields_for_group(section_or_group, ={}) section_or_group.groups.values.map do |group| next if group.attributes.empty? && group.groups.empty? fields_for(group.identifier, ) do |builder| @template.content_tag(:fieldset, :id => Util.csserize(group.identifier)) do # Following fieldset/legend convention: https://github.com/twitter/bootstrap/issues/1214 legend = @template.content_tag(:legend, group.label) unless group.root? # don't show the group name if it's the root group. attributes = group.attributes.values.map { |attribute| builder.attribute(attribute) }.join.html_safe nested_groups = builder.fields_for_group(group, ) [legend, attributes, nested_groups].join.html_safe end end end.join.html_safe end |
#preview(section) ⇒ Object
50 51 52 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 50 def preview(section) @template.link_to("Preview", section.path, ) if section.path end |
#radio_buttons(identifier, collection) ⇒ Object
46 47 48 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 46 def (identifier, collection) collection.map { |v| (identifier, v) }.join.html_safe end |
#update ⇒ Object
42 43 44 |
# File 'lib/dead_simple_cms/rails/action_view/form_builders/interface.rb', line 42 def update submit("Update", ) end |