Module: Decidim::EnhancedTextwork::MapHelper

Includes:
ApplicationHelper
Included in:
ApplicationHelper
Defined in:
app/helpers/decidim/enhanced_textwork/map_helper.rb

Overview

This helper include some methods for rendering paragraphs dynamic maps.

Instance Method Summary collapse

Instance Method Details

#has_position?(paragraph) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'app/helpers/decidim/enhanced_textwork/map_helper.rb', line 41

def has_position?(paragraph)
  return if paragraph.address.blank?

  paragraph.latitude.present? && paragraph.longitude.present?
end

#paragraph_data_for_map(paragraph) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/decidim/enhanced_textwork/map_helper.rb', line 17

def paragraph_data_for_map(paragraph)
  paragraph
    .slice(:latitude, :longitude, :address)
    .merge(
      title: decidim_html_escape(present(paragraph).title),
      body: html_truncate(decidim_sanitize(present(paragraph).body), length: 100),
      icon: icon("paragraphs", width: 40, height: 70, remove_icon_class: true),
      link: paragraph_path(paragraph)
    )
end

#paragraph_preview_data_for_map(paragraph) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/decidim/enhanced_textwork/map_helper.rb', line 28

def paragraph_preview_data_for_map(paragraph)
  {
    type: "drag-marker",
    marker: paragraph.slice(
      :latitude,
      :longitude,
      :address
    ).merge(
      icon: icon("paragraphs", width: 40, height: 70, remove_icon_class: true)
    )
  }
end

#paragraphs_data_for_map(geocoded_paragraphs) ⇒ Object

Serialize a collection of geocoded paragraphs to be used by the dynamic map component

geocoded_paragraphs - A collection of geocoded paragraphs



11
12
13
14
15
# File 'app/helpers/decidim/enhanced_textwork/map_helper.rb', line 11

def paragraphs_data_for_map(geocoded_paragraphs)
  geocoded_paragraphs.map do |paragraph|
    paragraph_data_for_map(paragraph)
  end
end