Class: Decidim::Map::DynamicMap::Builder

Inherits:
Frontend::Builder show all
Defined in:
lib/decidim/map/dynamic_map.rb

Overview

A builder for the dynamic maps to be used in the views. Provides all the necessary functionality to display and initialize the maps.

Direct Known Subclasses

Provider::DynamicMap::Here::Builder

Instance Method Summary collapse

Methods inherited from Frontend::Builder

#initialize

Constructor Details

This class inherits a constructor from Decidim::Map::Frontend::Builder

Instance Method Details

#append_assetsObject

See Also:

  • View::Builder#append_assets


79
80
81
82
# File 'lib/decidim/map/dynamic_map.rb', line 79

def append_assets
  template.append_stylesheet_pack_tag("decidim_map")
  template.append_javascript_pack_tag("decidim_map_provider_default")
end

#map_element(html_options = {}) ⇒ String

Displays the map element’s markup for the view.

Parameters:

  • html_options (Hash) (defaults to: {})

    Extra options to pass to the map element.

Returns:

  • (String)

    The map element’s markup.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/decidim/map/dynamic_map.rb', line 63

def map_element(html_options = {})
  map_html_options = {
    "data-decidim-map" => view_options.to_json,
    # The data-markers-data is kept for backwards compatibility
    "data-markers-data" => options.fetch(:markers, []).to_json
  }.merge(html_options)

  append_assets
  content = template.capture { yield }.html_safe if block_given?

  template.(:div, map_html_options) do
    (content || "")
  end
end