module ActionView::Helpers::AutoTagHelper

Constants

VERSION

Public Instance Methods

auto_input_tag(sym,model,name,value) click to toggle source
# File lib/action_view/helpers/auto_tag_helper.rb, line 64
def auto_input_tag(sym,model,name,value)
  column = model.columns_hash[sym.to_s]
  type = column.type
  opts = model.try(:input_options,sym) || {}
  reference_tag(sym,model,name,value) || boolean_tag(type,name,value) || datetime_tag(type,name,value,opts) || number_tag(type,name,value,opts) || text_tag(type,name,value,opts)
end
boolean_tag(type,name,value) click to toggle source
# File lib/action_view/helpers/auto_tag_helper.rb, line 84
def boolean_tag(type,name,value)
  if type.to_sym == :boolean
    check_box_tag(name,value="1",value)
  else
    nil
  end
end
datetime_tag(type,name,value,opts={}) click to toggle source

type == :datetime

datetime-local
# File lib/action_view/helpers/auto_tag_helper.rb, line 115
def datetime_tag(type,name,value,opts={})
  type = type.to_sym
  case type
  when :datetime
    opts = opts.stringify_keys
    opts["type"] ||= type.to_s
    text_field_tag(name,value,opts)
  when :time,:date
    text_field_tag(name,value,opts.merge(type: type))
  else
    nil
  end
end
display_tag(method_name,rec,html_options={}) click to toggle source

Parameters:

method_name

called method name

rec

object which is called method

html_options

html options , ex: {style: “width: 100px; height: 100px; color: ff0000;” placeholder: ‘your name’}

# File lib/action_view/helpers/auto_tag_helper.rb, line 19
def display_tag(method_name,rec,html_options={})
  rec.class.try(:reflections).try(:each) do |reflname,refl|
    if refl.foreign_key.to_sym == method_name.to_sym && refl.macro == :belongs_to
      method_name = reflname
      break
    end
  end
  v = rec.__send__(method_name)
  display_tag_with_display_options(v,rec,method_name,html_options) || v.try(:__display__) || v.to_s
end
display_tag_with_display_options(v,rec,method_name,html_options={}) click to toggle source
# File lib/action_view/helpers/auto_tag_helper.rb, line 30
def display_tag_with_display_options(v,rec,method_name,html_options={})
  if !rec.class.respond_to? :display_options
    return nil
  end

  opts = (rec.class.display_options(method_name) || {}).symbolize_keys
  opt_type = opts[:type]
  opt_method = opts[:method]
  display_type = ActionView::Helpers::AutoTagHelper::DisplayTypes[opt_type]

  if !(opt_method || display_type)
    return nil
  end

  args = (opts[:args] || [v])

  if args.kind_of? Proc
    args = args.call(v,rec)
  end

  if !args.kind_of? Array
    args = [args]
  end

  if opt_method
    @tag_options = html_options
    r = self.__send__(opt_method,*args)
    @tag_options = nil
    r
  else
    display_type.display_tag(v,html_options)
  end
end
number_tag(type,name,value,opts={}) click to toggle source

type == :integer

[:range  :week , :month]
# File lib/action_view/helpers/auto_tag_helper.rb, line 94
def number_tag(type,name,value,opts={})
  case type.to_sym
  when :integer
    opts = opts.stringify_keys
    case (opts["type"] || type).to_sym
    when :range
      range_field_tag(name, value, opts)
    when :week,:month
      text_field_tag(name, value, opts)
    else
      number_field_tag(name, value, opts)
    end
  when :float,:decimal
    number_field_tag(name, value, opts)
  else
    nil
  end
end
reference_tag(sym,model,name,value) click to toggle source
# File lib/action_view/helpers/auto_tag_helper.rb, line 71
def reference_tag(sym,model,name,value)
  if !model.respond_to? :select_list
    return nil
  end

  rtn = nil
  column = model.columns_hash[sym.to_s]
  if list = model.select_list(sym)
    rtn = select_tag(name,options_from_collection_for_select(list, :id, :__display__, value.to_s),include_blank: column.null)
  end
  rtn
end
text_tag(type,name,value,opts={}) click to toggle source

type == :string

input_type: [:color, :email, :number, :password, :tel, :url]
# File lib/action_view/helpers/auto_tag_helper.rb, line 131
def text_tag(type,name,value,opts={})
  case type.to_sym
  when :text
    text_area_tag(name,value)
  when :string
    text_field_tag(name,value,opts)
  else
    nil
  end
end