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
- #adr_microformat(resource) ⇒ Object
- #geo_microformat(resource) ⇒ Object
- #map_link(resource = nil, options = {}) ⇒ Object
- #static_map(resources, options = {}) ⇒ Object
- #ymaps_include_tag(key = nil, by_require = 0) ⇒ Object
- #ymaps_javascript_path(key = nil, by_require = 0) ⇒ Object
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 << content_tag(:span, resource.country, :class => 'country-name') end if resource.respond_to?(:postal_code) && resource.postal_code.present? result << content_tag(:span, resource.postal_code, :class => 'postal-code') end if resource.respond_to?(:city) && resource.city.present? result << content_tag(:span, resource.city, :class => 'locality') end if resource.respond_to?(:street_address) && resource.street_address.present? result << content_tag(:span, resource.street_address, :class => 'street-address') end content_tag(: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 content_tag(:dl, :class => 'geo') do content_tag(:dt, resource_class.human_attribute_name(:lat)) + content_tag(:dd, latlng.lat, :class => 'latitude') + content_tag(:dt, resource_class.human_attribute_name(:lng)) + content_tag(:dd, latlng.lng, :class => 'longitude') end end |
#map_link(resource = nil, options = {}) ⇒ Object
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, = {}) resource, = nil, resource if resource.is_a?(Hash) url_params = .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, .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, = {}) title = .delete(:title) { resources.to_s } map_type = .delete(:map) { 'map' } width = .delete(:width) { 600 } height = .delete(:height) { 450 } map_size = "#{width},#{height}" zoom = .delete(:zoom) { 16 } common_point = StaticMapPoint.new( .delete(:style) { 'pm' }, .delete(:color) { 'wt' }, .delete(:size) { 'm' }, .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('~') content_tag(: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}", .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 |