Module: InputCSS

Included in:
ActionView::Helpers::TagHelper
Defined in:
lib/input_css.rb,
lib/input_css/version.rb

Overview

Modifies the ‘options’ of the tag helper so that, by default, there’s a CSS class attribute based on the type attribute (Note: only applies to input fields)

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.css_options_for_tag(name, options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/input_css.rb', line 12

def css_options_for_tag(name, options)
  options = HashWithIndifferentAccess.new(options)
  return options if options[:type] == 'hidden'

  # alter CSS class based on type
  # (only for <input ... /> tags)
  if name.to_s.downcase =~ /^input$/
    type, css = options[:type], options[:class]
    type = 'text' if type == 'password'
    options[:class] = "#{css.to_s} #{type.to_s}".gsub!(/^\s*/, '') unless css && css.split.include?(type)
  end
  options
end

Instance Method Details

#tag(name, options = nil, open = false, escape = true) ⇒ Object



7
8
9
10
# File 'lib/input_css.rb', line 7

def tag(name, options=nil, open=false, escape=true)
  options = css_options_for_tag(name, options)
  super
end