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

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