Class: Jekyll::LeafletMap

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-leaflet-mze/leaflet-map.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, input, tokens) ⇒ LeafletMap



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jekyll-leaflet-mze/leaflet-map.rb', line 6

def initialize(tag_name, input, tokens)
    super
    if input.empty?
        @input = {}
    else
        @input = input
    end
    
    if !(input.is_a? String)
        raise "leaflet-map input argument must be a String"
    end

end

Instance Method Details

#render(context) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll-leaflet-mze/leaflet-map.rb', line 21

def render(context)
    text = super        
    if !(text.is_a? String)
        raise "leaflet-map content between the tag blocks must a String"
    end
    leaflet_providers_js_content = File.read(
        File.expand_path("./leaflet-providers.js", File.dirname(__FILE__)))

    map_js = File.read(
        File.expand_path("./leaflet-map.js", File.dirname(__FILE__)))
    map_html = File.read(
        File.expand_path("./leaflet-map.html", File.dirname(__FILE__)))

    @input = parse_liquid_output_in(@input, context)
    id = SecureRandom.hex
    map_js = map_js % {id: id,
                       leaflet_providers_js_content: leaflet_providers_js_content,
                       tag_input_arg_json: @input,
                       inside_block_leaflet_items: text}
    map_html = map_html % {id: id,
                           leaflet_map_js_content: map_js}

    map_html
end