Class: ComfortableMexicanLoveseat::FormBuilder
- Inherits:
-
ComfortableMexicanSofa::FormBuilder
- Object
- ComfortableMexicanSofa::FormBuilder
- ComfortableMexicanLoveseat::FormBuilder
- Defined in:
- lib/comfortable_mexican_loveseat/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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 101 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 —————————————————–
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 36 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 10 def default_tag_field(tag, index, method = :text_field_tag, = {}) label = I18n.t(tag.identifier.to_s).include?(tag.identifier.to_s) ? tag.blockable.class.human_attribute_name(tag.identifier.to_s) : I18n.t(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
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 58 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) label = I18n.t(tag.identifier.to_s).include?(tag.identifier.to_s) ? tag.blockable.class.human_attribute_name(tag.identifier.to_s) : I18n.t(tag.identifier.to_s) form_group :label => {:text => label} do content end end |
#field_date_time(tag, index) ⇒ Object
38 39 40 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 38 def field_date_time(tag, index) default_tag_field(tag, index, :text_field_tag, :data => {'cms-datetime' => true}) end |
#field_integer(tag, index) ⇒ Object
42 43 44 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 42 def field_integer(tag, index) default_tag_field(tag, index, :number_field_tag) end |
#field_name_for(tag) ⇒ Object
5 6 7 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 5 def field_name_for(tag) tag.blockable.class.name.demodulize.underscore.gsub(/\//,'_') end |
#field_rich_text(tag, index) ⇒ Object
54 55 56 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 54 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
46 47 48 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 46 def field_string(tag, index) default_tag_field(tag, index) end |
#field_text(tag, index) ⇒ Object
50 51 52 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 50 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
69 70 71 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 69 def page_date_time(tag, index) default_tag_field(tag, index, :text_field_tag, :data => {'cms-datetime' => true}) end |
#page_file(tag, index) ⇒ Object
89 90 91 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 89 def page_file(tag, index) default_tag_field(tag, index, :file_field_tag) end |
#page_files(tag, index) ⇒ Object
93 94 95 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 93 def page_files(tag, index) default_tag_field(tag, index, :file_field_tag, :multiple => true) end |
#page_integer(tag, index) ⇒ Object
73 74 75 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 73 def page_integer(tag, index) default_tag_field(tag, index, :number_field_tag) end |
#page_markdown(tag, index) ⇒ Object
97 98 99 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 97 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
85 86 87 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 85 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
77 78 79 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 77 def page_string(tag, index) default_tag_field(tag, index) end |
#page_text(tag, index) ⇒ Object
81 82 83 |
# File 'lib/comfortable_mexican_loveseat/form_builder.rb', line 81 def page_text(tag, index) default_tag_field(tag, index, :text_area_tag, :data => {'cms-cm-mode' => 'text/html'}) end |