Class: ComfortableMexicanSofa::FormBuilder
- Inherits:
-
BootstrapForm::FormBuilder
- Object
- BootstrapForm::FormBuilder
- ComfortableMexicanSofa::FormBuilder
- Defined in:
- lib/comfortable_mexican_sofa/form_builder.rb
Instance Method Summary collapse
- #collection(tag, index) ⇒ Object
-
#default_tag_field(tag, index, method = :text_field_tag, options = {}) ⇒ Object
– Tag Field Fields —————————————————–.
- #field_boolean(tag, index) ⇒ Object
- #field_date_time(tag, index) ⇒ Object
- #field_integer(tag, index) ⇒ Object
- #field_name_for(tag) ⇒ Object
- #field_rich_text(tag, index) ⇒ Object
- #field_string(tag, index) ⇒ Object
- #field_text(tag, index) ⇒ Object
- #page_date_time(tag, index) ⇒ Object
- #page_file(tag, index) ⇒ Object
- #page_files(tag, index) ⇒ Object
- #page_integer(tag, index) ⇒ Object
- #page_markdown(tag, index) ⇒ Object
- #page_rich_text(tag, index) ⇒ Object
- #page_string(tag, index) ⇒ Object
- #page_text(tag, index) ⇒ Object
Instance Method Details
#collection(tag, index) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 99 def collection(tag, index) = [["---- Select #{tag.collection_class.titleize} ----", nil]] + tag.collection_objects.collect do |m| [m.send(tag.collection_title), m.send(tag.collection_identifier)] end fieldname = field_name_for(tag) content = @template.select_tag( "#{fieldname}[blocks_attributes][#{index}][content]", @template.(, :selected => tag.content), :id => nil ) content << @template.hidden_field_tag("#{fieldname}[blocks_attributes][#{index}][identifier]", tag.identifier, :id => nil) form_group :label => {:text => tag.identifier.titleize}, :class => tag.class.to_s.demodulize.underscore do content end end |
#default_tag_field(tag, index, method = :text_field_tag, options = {}) ⇒ Object
– Tag Field Fields —————————————————–
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 8 def default_tag_field(tag, index, method = :text_field_tag, = {}) label = tag.blockable.class.human_attribute_name(tag.identifier.to_s) css_class = tag.class.to_s.demodulize.underscore content = '' fieldname = field_name_for(tag) case method when :file_field_tag input_params = {:id => nil} name = "#{fieldname}[blocks_attributes][#{index}][content]" if .delete(:multiple) input_params.merge!(:multiple => true) name << '[]' end content << @template.send(method, name, input_params) content << @template.render(:partial => 'comfy/admin/cms/files/page_form', :object => tag.block) else [:class] = ' form-control' content << @template.send(method, "#{fieldname}[blocks_attributes][#{index}][content]", tag.content, ) end content << @template.hidden_field_tag("#{fieldname}[blocks_attributes][#{index}][identifier]", tag.identifier, :id => nil) form_group :label => {:text => label} do content.html_safe end end |
#field_boolean(tag, index) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 57 def field_boolean(tag, index) fieldname = field_name_for(tag) content = @template.hidden_field_tag("#{fieldname}[blocks_attributes][#{index}][content]", '', :id => nil) content << @template.check_box_tag("#{fieldname}[blocks_attributes][#{index}][content]", '1', tag.content.present?, :id => nil) content << @template.hidden_field_tag("#{fieldname}[blocks_attributes][#{index}][identifier]", tag.identifier, :id => nil) form_group :label => {:text => tag.identifier.titleize + "?"} do content end end |
#field_date_time(tag, index) ⇒ Object
37 38 39 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 37 def field_date_time(tag, index) default_tag_field(tag, index, :text_field_tag, :data => {'cms-datetime' => true}) end |
#field_integer(tag, index) ⇒ Object
41 42 43 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 41 def field_integer(tag, index) default_tag_field(tag, index, :number_field_tag) end |
#field_name_for(tag) ⇒ Object
3 4 5 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 3 def field_name_for(tag) tag.blockable.class.name.demodulize.underscore.gsub(/\//,'_') end |
#field_rich_text(tag, index) ⇒ Object
53 54 55 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 53 def field_rich_text(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-rich-text' => true}) end |
#field_string(tag, index) ⇒ Object
45 46 47 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 45 def field_string(tag, index) default_tag_field(tag, index) end |
#field_text(tag, index) ⇒ Object
49 50 51 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 49 def field_text(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-cm-mode' => 'text/html'}) end |
#page_date_time(tag, index) ⇒ Object
67 68 69 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 67 def page_date_time(tag, index) default_tag_field(tag, index, :text_field_tag, :data => {'cms-datetime' => true}) end |
#page_file(tag, index) ⇒ Object
87 88 89 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 87 def page_file(tag, index) default_tag_field(tag, index, :file_field_tag) end |
#page_files(tag, index) ⇒ Object
91 92 93 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 91 def page_files(tag, index) default_tag_field(tag, index, :file_field_tag, :multiple => true) end |
#page_integer(tag, index) ⇒ Object
71 72 73 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 71 def page_integer(tag, index) default_tag_field(tag, index, :number_field_tag) end |
#page_markdown(tag, index) ⇒ Object
95 96 97 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 95 def page_markdown(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-cm-mode' => 'text/x-markdown'}) end |
#page_rich_text(tag, index) ⇒ Object
83 84 85 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 83 def page_rich_text(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-rich-text' => true}) end |
#page_string(tag, index) ⇒ Object
75 76 77 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 75 def page_string(tag, index) default_tag_field(tag, index) end |
#page_text(tag, index) ⇒ Object
79 80 81 |
# File 'lib/comfortable_mexican_sofa/form_builder.rb', line 79 def page_text(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-cm-mode' => 'text/html'}) end |