Module: Useful::ErbHelpers::Proper

Includes:
Common
Defined in:
lib/useful/erb_helpers/proper.rb

Constant Summary

Constants included from Common

Common::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

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, options = proper_check_radio_options('1', args)
  options[:id] ||= erb_helper_common_safe_id(name.to_s)
  options[:checked] = OPTIONS[:checked] if checked
  label_text = options.delete(:label)
  unchecked_value = options.delete(:unchecked_value)
  unchecked_value = '0' if unchecked_value.nil?
  disable_unchecked_value = options.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, options)
    else
      tag(:label, :for => options[:id]) do
        input_tag(:checkbox, name, value, options) + 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 proper_radio_button_tag(*args)
  name, value, checked, options = proper_check_radio_options(nil, args)
  options[:id] ||= erb_helper_common_safe_id(name.to_s)
  options[:checked] = OPTIONS[:checked] if checked
  label_text = options.delete(:label) || value.to_s.humanize
  label_container_tag = options.delete(:tag) || :span
  radio_button_str = input_tag(:radio, name, value, options)
  ''.tap do |html|
    html << if label_text.blank?
      radio_button_str
    else
      tag(:label, :for => options[:id]) do
        radio_button_str + 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, options={}, &block)
  html_name = (options[:multiple].is_true? && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
  options[:multiple] = OPTIONS[:multiple] if options[:multiple] == true
  options[:tag] = 'select'
  @_out_buf ||= ''
  @_out_buf << input_tag(nil, html_name, nil, options, &block)
end