Class: Marker::Helpers::FieldTag

Inherits:
Object
  • Object
show all
Defined in:
lib/marker/helpers/field_tag.rb

Constant Summary collapse

DEFAULT_MAP_ENGINE =
'google'.freeze
DEFAULT_STYLE =
'width:800px;height:400px'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_name, method_name, template, options = {}, html_options = {}) ⇒ FieldTag

Wrapper for render marker field Usage:

marker = FieldTag.new(object_name, method_name, template, options)
marker.to_s


15
16
17
18
19
20
21
22
23
24
# File 'lib/marker/helpers/field_tag.rb', line 15

def initialize(object_name, method_name, template, options = {}, html_options = {}) #:nodoc:
  @options = { object_name: object_name, method_name: method_name }.merge!(options)
  @template = template
  @html_options = html_options

  @engine = (@options.delete(:engine) || DEFAULT_MAP_ENGINE)
  @object = (@options.delete(:object) || @template.instance_variable_get("@#{object_name}"))

  @html_options[:id] ||= id
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



4
5
6
# File 'lib/marker/helpers/field_tag.rb', line 4

def engine
  @engine
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



4
5
6
# File 'lib/marker/helpers/field_tag.rb', line 4

def html_options
  @html_options
end

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/marker/helpers/field_tag.rb', line 4

def object
  @object
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/marker/helpers/field_tag.rb', line 4

def template
  @template
end

Instance Method Details

#idObject



31
32
33
# File 'lib/marker/helpers/field_tag.rb', line 31

def id
  @id ||= @template.dom_id(@object, method_name)
end

#input_optionsObject



35
36
37
38
39
40
41
42
43
# File 'lib/marker/helpers/field_tag.rb', line 35

def input_options
  @input_options ||= {
    data: {
      marker: method_name,
      zoom: @html_options[:zoom]
    },
    style: DEFAULT_STYLE
  }.merge!(@html_options)
end

#method_nameObject



45
46
47
# File 'lib/marker/helpers/field_tag.rb', line 45

def method_name
  @options[:method_name]
end

#object_nameObject



49
50
51
# File 'lib/marker/helpers/field_tag.rb', line 49

def object_name
  @options[:object_name]
end

#to_s(locals = {}) ⇒ Object

:nodoc:



26
27
28
29
# File 'lib/marker/helpers/field_tag.rb', line 26

def to_s(locals = {}) #:nodoc:
  locals = { field: self }.merge!(locals)
  @template.render partial: "marker/#{@engine}", locals: locals
end