Class: AttributePairGenerator
- Inherits:
-
Object
- Object
- AttributePairGenerator
- Includes:
- ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/attribute_pair_generator.rb
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
Instance Method Summary collapse
- #checkbox(options) ⇒ Object
- #date(options) ⇒ Object
-
#initialize(init_obj = nil) ⇒ AttributePairGenerator
constructor
A new instance of AttributePairGenerator.
- #link(options) ⇒ Object
- #plain_text(options) ⇒ Object
- #radio(options) ⇒ Object
- #select(options) ⇒ Object
- #text_area(options) ⇒ Object
- #text_field(options) ⇒ Object
Constructor Details
#initialize(init_obj = nil) ⇒ AttributePairGenerator
Returns a new instance of AttributePairGenerator.
10 11 12 |
# File 'lib/attribute_pair_generator.rb', line 10 def initialize(init_obj = nil) @obj = init_obj end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
8 9 10 |
# File 'lib/attribute_pair_generator.rb', line 8 def obj @obj end |
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
7 8 9 |
# File 'lib/attribute_pair_generator.rb', line 7 def output_buffer @output_buffer end |
Instance Method Details
#checkbox(options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/attribute_pair_generator.rb', line 36 def checkbox() hidden_tag = hidden_field_tag attribute(), [:unchecked_value].nil? ? false : [:unchecked_value] checked_value = [:checked_value] || true is_checked = value().to_s == checked_value.to_s content = hidden_tag + check_box_tag(attribute(), checked_value, is_checked, ()) render(content, ) end |
#date(options) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/attribute_pair_generator.rb', line 23 def date() = () (([:class] ||= '') << ' datepicker').strip! content = text_field_tag attribute(), value(), render(content, ) end |
#link(options) ⇒ Object
14 15 16 17 |
# File 'lib/attribute_pair_generator.rb', line 14 def link() content = link_to [:title], [:url], [:field_options] render(content, ) end |
#plain_text(options) ⇒ Object
19 20 21 |
# File 'lib/attribute_pair_generator.rb', line 19 def plain_text() render(value(), ) end |
#radio(options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/attribute_pair_generator.rb', line 54 def radio() content = content_tag :ol, class: 'unstyled' do [:collection].map do |element| if element.is_a?(Array) value = element[0] label = element[1] else value = label = element end content_tag :li do label_tag("#{attribute()}_#{value}", (attribute(), value || '', value == value(), ()) + label, class: 'radio') end end.flatten.join("").html_safe end render(content, ) end |
#select(options) ⇒ Object
31 32 33 34 |
# File 'lib/attribute_pair_generator.rb', line 31 def select() content = select_tag attribute(), ([:collection], value()), (, prompt: [:prompt], include_blank: [:include_blank]) render(content, ) end |
#text_area(options) ⇒ Object
49 50 51 52 |
# File 'lib/attribute_pair_generator.rb', line 49 def text_area() content = text_area_tag attribute(), value(), () render(content, ) end |
#text_field(options) ⇒ Object
44 45 46 47 |
# File 'lib/attribute_pair_generator.rb', line 44 def text_field() content = text_field_tag attribute(), value(), () render(content, ) end |