Class: Jekyll::Maps::GoogleMapTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-maps/google_map_tag.rb

Constant Summary collapse

JS_LIB_NAME =
"jekyllMaps".freeze
DEFAULT_MAP_WIDTH =
600
DEFAULT_MAP_HEIGHT =
400

Instance Method Summary collapse

Constructor Details

#initialize(_, args, _) ⇒ GoogleMapTag

Returns a new instance of GoogleMapTag.



8
9
10
11
12
# File 'lib/jekyll-maps/google_map_tag.rb', line 8

def initialize(_, args, _)
  @args   = OptionsParser.parse(args)
  @finder = LocationFinder.new(@args)
  super
end

Instance Method Details

#render(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-maps/google_map_tag.rb', line 14

def render(context)
  locations = @finder.find(context.registers[:site], context.registers[:page])
  @args[:attributes][:id] ||= SecureRandom.uuid

  "<div \#{render_attributes}></div>\n<script type='text/javascript'>\n  \#{JS_LIB_NAME}.register(\n    '\#{@args[:attributes][:id]}',\n    \#{locations.to_json},\n    \#{map_options(context.registers[:site]).to_json}\n  );\n</script>\n"
end