Sha256: c2c6246d2f37d9293746ff3b0192c21b204344cb8d7b08a1c438b534b7ba31ac

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

# The TagHelper module is re-opened directly instead of including additional
# modules in order for the chained behavior to be applied to other, unanticipated
# classes that include ActionView::Helpers::TagHelper directly.
ActionView::Helpers::TagHelper.class_eval do
  # Appends the input type to the value currently stored in the html options
  # for the tag.
  def styled_input(name, options = nil)
    options = (options || {}).stringify_keys
    options['class'] = "#{options['class']} #{options['type']}".strip if name.to_s == 'input' && options.include?('type') && options['type'] != 'hidden'
    options
  end
  
  # Ensure that the options are updated for input tags before generating
  # the html for the tag
  def tag_with_styled_inputs(name, options = nil, *args) #:nodoc:
    tag_without_styled_inputs(name, styled_input(name, options), *args)
  end
  alias_method_chain :tag, :styled_inputs
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
pluginaweek-styled_inputs-0.1.1 lib/styled_inputs/extensions/tag_helper.rb
styled_inputs-0.1.2 lib/styled_inputs/extensions/tag_helper.rb
styled_inputs-0.1.1 lib/styled_inputs/extensions/tag_helper.rb