Module: Useful::ErbHelpers::Proper
- Includes:
- Common
- Defined in:
- lib/useful/erb_helpers/proper.rb
Constant Summary
Constants included from Common
Class Method Summary collapse
Instance Method Summary collapse
-
#proper_check_box_tag(*args) ⇒ Object
TODO: write tests.
-
#proper_radio_button_tag(*args) ⇒ Object
TODO: write tests.
-
#proper_select_tag(name, options = {}, &block) ⇒ Object
This one’s a little different than the corresponding actionpack version: => ie.
Methods included from Common
#erb_helper_clear_output_buffer
Class Method Details
.included(receiver) ⇒ Object
76 77 78 |
# File 'lib/useful/erb_helpers/proper.rb', line 76 def self.included(receiver) receiver.send :include, Useful::ErbHelpers::Tags end |
Instance Method Details
#proper_check_box_tag(*args) ⇒ Object
TODO: write tests
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/useful/erb_helpers/proper.rb', line 32 def proper_check_box_tag(*args) name, value, checked, = ('1', args) [:id] ||= erb_helper_common_safe_id(name.to_s) [:checked] = OPTIONS[:checked] if checked label_text = .delete(:label) unchecked_value = .delete(:unchecked_value) unchecked_value = '0' if unchecked_value.nil? disable_unchecked_value = .delete(:disable_unchecked_value) # ''.tap do |html| # html << input_tag(:hidden, name, unchecked_value, :id => "#{options[:id]}_hidden") unless disable_unchecked_value.is_true? # html << input_tag(:checkbox, name, value, options) # html << tag(:label, :for => options[:id]) { label_text } unless label_text.blank? # end ''.tap do |html| html << input_tag(:hidden, name, unchecked_value, :id => "#{options[:id]}_hidden") unless disable_unchecked_value.is_true? html << if label_text.blank? input_tag(:checkbox, name, value, ) else tag(:label, :for => [:id]) do input_tag(:checkbox, name, value, ) + label_text end end end end |
#proper_radio_button_tag(*args) ⇒ Object
TODO: write tests
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/useful/erb_helpers/proper.rb', line 58 def (*args) name, value, checked, = (nil, args) [:id] ||= erb_helper_common_safe_id(name.to_s) [:checked] = OPTIONS[:checked] if checked label_text = .delete(:label) || value.to_s.humanize label_container_tag = .delete(:tag) || :span = input_tag(:radio, name, value, ) ''.tap do |html| html << if label_text.blank? else tag(:label, :for => [:id]) do + tag(label_container_tag) { label_text } end end end end |
#proper_select_tag(name, options = {}, &block) ⇒ Object
This one’s a little different than the corresponding actionpack version:
> ie. you don’t pass an options string as the 2nd argument
> you, instead, pass a block that should return the desired options string
> ie, proper_select_tag(‘user’) { ‘<option>test</option>’ }
23 24 25 26 27 28 29 |
# File 'lib/useful/erb_helpers/proper.rb', line 23 def proper_select_tag(name, ={}, &block) html_name = ([:multiple].is_true? && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name [:multiple] = OPTIONS[:multiple] if [:multiple] == true [:tag] = 'select' @_out_buf ||= '' @_out_buf << input_tag(nil, html_name, nil, , &block) end |