module ActionView::Helpers::AutoTagHelper::DisplayTypes

Public Class Methods

[](type_name) click to toggle source
# File lib/action_view/helpers/auto_tag_helper/display_types.rb, line 43
def self.[](type_name)
  get(type_name)
end
get(type_name) click to toggle source

register(:google_map_latlon, GoogleMapByLatLon) get(:google_map_latlon)

# => GoogleMapByLatLon
# File lib/action_view/helpers/auto_tag_helper/display_types.rb, line 39
def self.get(type_name)
  type_name.present? ? @@display_types[type_name.to_sym] : nil
end
register(type_name, obj) click to toggle source

For examples

module MyGoogleMapByLatLon
  def self.display_tag latlon
    lat = latlon[:lat]
    lon = latlon[:lon]
    ...
  end
end

ActionView::Helpers::AutoTagHelper::DisplayTypes.register(:google_map_latlon, MyGoogleMapByLatLon)

class User < ActiveRecord::Base
  set_display_type(:myhome_coodinates, :google_map_latlon)
  def myhome_coodinates
    {lat: self.lat, lon: self.lon}
  end
end

user = User.find(1)
display_tag(:myhome_coodinates, user, width: 600, height: 350)
# => MyGoogleMapByLatLon.display_tag(user.myhome_coodinates,width: 600, height: 350)
# File lib/action_view/helpers/auto_tag_helper/display_types.rb, line 32
def self.register(type_name, obj)
  @@display_types[type_name.to_sym]=obj
end