Module: YMaps::ActionView::HtmlHelper

Included in:
Helpers
Defined in:
lib/ymaps/action_view/html_helper.rb

Defined Under Namespace

Classes: StaticMapPoint

Instance Method Summary collapse

Instance Method Details

#adr_microformat(resource) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ymaps/action_view/html_helper.rb', line 97

def adr_microformat(resource)
  result = []
  if resource.respond_to?(:country) && resource.country.present?
    result << (:span, resource.country, :class => 'country-name')
  end
  if resource.respond_to?(:postal_code) && resource.postal_code.present?
    result << (:span, resource.postal_code, :class => 'postal-code')
  end
  if resource.respond_to?(:city) && resource.city.present?
    result << (:span, resource.city, :class => 'locality')
  end
  if resource.respond_to?(:street_address) && resource.street_address.present?
    result << (:span, resource.street_address, :class => 'street-address')
  end
  (:div, result.join(', '), :class => 'adr')
end

#geo_microformat(resource) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ymaps/action_view/html_helper.rb', line 85

def geo_microformat(resource)
  latlng = resource.to_latlng
  resource_class ||= resource.class

  (:dl, :class => 'geo') do
    (:dt, resource_class.human_attribute_name(:lat)) +
      (:dd, latlng.lat, :class => 'latitude') +
      (:dt, resource_class.human_attribute_name(:lng)) +
      (:dd, latlng.lng, :class => 'longitude')
  end
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ymaps/action_view/html_helper.rb', line 24

def map_link(resource = nil, options = {})
  resource, options = nil, resource if resource.is_a?(Hash)

  url_params = options.delete(:url) { {} }
  href = if resource
           polymorphic_url(resource, {:format => :ymapsml}.merge(url_params))
         else
           url_for({:format => :ymapsml,
                    :only_path => false,
                    :time => Time.now}.merge(url_params))
         end

  tag(:link,
      options.merge!(:id => 'alternate_ymapsml',
                     :href => href,
                     :rel => 'alternate',
                     :type => 'application/ymapsml+xml'))
end

#static_map(resources, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ymaps/action_view/html_helper.rb', line 52

def static_map(resources, options = {})
  title = options.delete(:title) { resources.to_s }
  map_type = options.delete(:map) { 'map' }
  width = options.delete(:width) { 600 }
  height = options.delete(:height) { 450 }
  map_size = "#{width},#{height}"
  zoom     = options.delete(:zoom) { 16 }

  common_point = StaticMapPoint.new(
    options.delete(:style) { 'pm' },
    options.delete(:color) { 'wt' },
    options.delete(:size)  { 'm' },
    options.delete(:number) { 0 }
  )

  collection = Array(resources).inject([]) do |result, resource|
    common_point.gml_lnglat = resource.latlng.gml_lnglat
    common_point.number += 1
    result << common_point.to_s
    result
  end.join('~')

  (:div, :class => 'b-map') do
    image_tag("http://static-maps.yandex.ru/1.x/?key=#{YMaps.key}&l=#{map_type}&pt=#{collection}&size=#{map_size}&z=#{zoom}", options.merge(
      :title => title,
      :alt => title,
      :class => 'static',
      :width => width,
      :height => height
    ))
  end
end

#ymaps_include_tag(key = nil, by_require = 0) ⇒ Object



48
49
50
# File 'lib/ymaps/action_view/html_helper.rb', line 48

def ymaps_include_tag(key = nil, by_require = 0)
  javascript_include_tag(ymaps_javascript_path(key, by_require))
end

#ymaps_javascript_path(key = nil, by_require = 0) ⇒ Object



43
44
45
46
# File 'lib/ymaps/action_view/html_helper.rb', line 43

def ymaps_javascript_path(key = nil, by_require = 0)
  query = {:key => key || YMaps.key, :loadByRequire => by_require}.to_query
  "http://api-maps.yandex.ru/1.1/index.xml?#{query}"
end