Class: Caisson::Helpers::Form::Base
- Inherits:
-
Object
- Object
- Caisson::Helpers::Form::Base
- Defined in:
- lib/caisson/helpers/form/base.rb
Instance Method Summary collapse
-
#button(text, options = {}) ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************.
- #button_to(text, options = {}, html_options = {}) ⇒ Object
- #buttons(&block) ⇒ Object
- #checkbox(name, selected = false, options = {}) ⇒ Object
-
#initialize(core) ⇒ Base
constructor
************************************************************************************* CONSTRUCTOR *************************************************************************************.
- #label(text, options = {}) ⇒ Object
- #line(label_str, content, options = {}) ⇒ Object
- #line_checkbox(label_str, field_name, selected = false, options = {}) ⇒ Object
- #line_password(label_str, field_name, value = '', options = {}) ⇒ Object
- #line_select(label_str, field_name, choices, selection, options = {}) ⇒ Object
- #line_static(label_str, value, options = {}) ⇒ Object
- #line_switch(label_str, field_name, choices, selection, options = {}) ⇒ Object
- #line_text(label_str, field_name, value = '', options = {}) ⇒ Object
- #line_time(label_str, field_name, value = '', options = {}) ⇒ Object
- #password(name, value = '', options = {}) ⇒ Object
- #select(name, choices, selection, options = {}) ⇒ Object
- #static(value, options = {}) ⇒ Object
- #switch(name, choices, selection, options = {}) ⇒ Object
- #text(name, value = '', options = {}) ⇒ Object
- #time(name, value, options = {}) ⇒ Object
Constructor Details
#initialize(core) ⇒ Base
************************************************************************************* CONSTRUCTOR *************************************************************************************
9 10 11 |
# File 'lib/caisson/helpers/form/base.rb', line 9 def initialize(core) @core = core end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
193 |
# File 'lib/caisson/helpers/form/base.rb', line 193 def method_missing(*args, &block) return @core.send(*args, &block) end |
Instance Method Details
#button(text, options = {}) ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************
17 18 19 |
# File 'lib/caisson/helpers/form/base.rb', line 17 def (text, ={}) Caisson::Helpers::Form::Button.new(@core).build(text, ) end |
#button_to(text, options = {}, html_options = {}) ⇒ Object
21 22 23 |
# File 'lib/caisson/helpers/form/base.rb', line 21 def (text, ={}, ={}) Caisson::Helpers::Form::Button.new(@core).(text, , ) end |
#buttons(&block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/caisson/helpers/form/base.rb', line 25 def (&block) content = '<div class="buttons row"><div class="large-12 columns">' content << @core.capture(self, &block) content << '</div></div>' return content.html_safe end |
#checkbox(name, selected = false, options = {}) ⇒ Object
74 75 76 |
# File 'lib/caisson/helpers/form/base.rb', line 74 def checkbox(name, selected=false, ={}) new_field('checkbox', name, selected, ) end |
#label(text, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/caisson/helpers/form/base.rb', line 33 def label(text, ={}) .reverse_merge!(content: '', placeholder: nil, separator: ' : ') label_for = [:content].scan(/<[input|textarea|select|span|div].+id="(.+?)"./).flatten.first attributes = {} attributes[:for] = label_for if label_for attributes[:class] = 'placeholder' if [:placeholder] text = ' '.html_safe if text.empty? text += [:separator].to_s if not [:placeholder] return content_tag(:label, text, attributes) end |
#line(label_str, content, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/caisson/helpers/form/base.rb', line 48 def line(label_str, content, ={}) .reverse_merge!(class: nil, id: nil, label_separator: ' : ', placeholder: false) css_class = ['row', 'form-line', [:class]].compact.join(' ') line_content = '<div class="' + css_class + '"><div class="large-12 columns field">' line_content << label(label_str, content: content, separator: [:label_separator], placeholder: [:placeholder]) if not label_str.nil? line_content << content line_content << '</div></div>' return line_content.html_safe end |
#line_checkbox(label_str, field_name, selected = false, options = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/caisson/helpers/form/base.rb', line 82 def line_checkbox(label_str, field_name, selected=false, ={}) .reverse_merge!(label_separator: nil, wrap_field: false) [:class] = [[:class], 'line-checkbox'].compact.join(' ') return line(label_str, checkbox(field_name, selected), ) end |
#line_password(label_str, field_name, value = '', options = {}) ⇒ Object
90 91 92 93 94 |
# File 'lib/caisson/helpers/form/base.rb', line 90 def line_password(label_str, field_name, value='', ={}) = (label_str, ) line(label_str, password(field_name, value, ), ) end |
#line_select(label_str, field_name, choices, selection, options = {}) ⇒ Object
96 97 98 |
# File 'lib/caisson/helpers/form/base.rb', line 96 def line_select(label_str, field_name, choices, selection, ={}) line(label_str, select(field_name, choices, selection), ) end |
#line_static(label_str, value, options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/caisson/helpers/form/base.rb', line 100 def line_static(label_str, value, ={}) .reverse_merge!(wrap_field: false) [:class] = [[:class], 'line-static'].compact.join(' ') = {} [:date_format] = .delete(:date_format) if [:date_format] line(label_str, static(value, ), ) end |
#line_switch(label_str, field_name, choices, selection, options = {}) ⇒ Object
111 112 113 |
# File 'lib/caisson/helpers/form/base.rb', line 111 def line_switch(label_str, field_name, choices, selection, ={}) line(label_str, switch(field_name, choices, selection), ) end |
#line_text(label_str, field_name, value = '', options = {}) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/caisson/helpers/form/base.rb', line 115 def line_text(label_str, field_name, value='', ={}) .reverse_merge!(wrap_field: false) = (label_str, ) line(label_str, text(field_name, value, ), ) end |
#line_time(label_str, field_name, value = '', options = {}) ⇒ Object
123 124 125 |
# File 'lib/caisson/helpers/form/base.rb', line 123 def line_time(label_str, field_name, value='', ={}) line(label_str, time(field_name, value), ) end |
#password(name, value = '', options = {}) ⇒ Object
127 128 129 |
# File 'lib/caisson/helpers/form/base.rb', line 127 def password(name, value='', ={}) new_field('password', name, value, ) end |
#select(name, choices, selection, options = {}) ⇒ Object
131 132 133 134 135 |
# File 'lib/caisson/helpers/form/base.rb', line 131 def select(name, choices, selection, ={}) .reverse_merge!(submit: false, translate: false) new_field('select', name, choices, selection, ) end |
#static(value, options = {}) ⇒ Object
137 138 139 |
# File 'lib/caisson/helpers/form/base.rb', line 137 def static(value, ={}) new_field('static', value, ) end |
#switch(name, choices, selection, options = {}) ⇒ Object
141 142 143 144 145 |
# File 'lib/caisson/helpers/form/base.rb', line 141 def switch(name, choices, selection, ={}) .reverse_merge!(submit: false, translate: false) new_field('switch', name, choices, selection, ) end |
#text(name, value = '', options = {}) ⇒ Object
147 148 149 |
# File 'lib/caisson/helpers/form/base.rb', line 147 def text(name, value='', ={}) new_field('text', name, value, ) end |
#time(name, value, options = {}) ⇒ Object
151 152 153 |
# File 'lib/caisson/helpers/form/base.rb', line 151 def time(name, value, ={}) new_field('time_field', name, value, ) end |