Module: Jekyll::GisBlogger::Utils

Included in:
Tags::DatatableTag, Tags::GpxTrackTag, Tags::LungkuiTag, Tags::MapTag, Tags::StorymapTag
Defined in:
lib/jekyll-gis-blogger/utils.rb

Overview

Shared helpers for all GIS Blogger Liquid tag plugins.

Constant Summary collapse

ATTR_RE =
/(\w+)\s*=\s*(?:"([^"]*)"|'([^']*)')/

Instance Method Summary collapse

Instance Method Details

#absolute?(path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jekyll-gis-blogger/utils.rb', line 20

def absolute?(path)
  path.start_with?("http://", "https://", "//")
end

#inline(object) ⇒ Object



16
17
18
# File 'lib/jekyll-gis-blogger/utils.rb', line 16

def inline(object)
  JSON.generate(object).gsub("</", '<\/')
end

#order_of(props, index) ⇒ Object



24
25
26
# File 'lib/jekyll-gis-blogger/utils.rb', line 24

def order_of(props, index)
  present?(props["order"]) ? props["order"].to_f : index.to_f
end

#present?(v) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/jekyll-gis-blogger/utils.rb', line 33

def present?(v)
  !v.nil? && v.to_s.strip != ""
end

#read_source(site, path) ⇒ Object



9
10
11
12
13
14
# File 'lib/jekyll-gis-blogger/utils.rb', line 9

def read_source(site, path)
  File.read(site.in_source_dir(path))
rescue StandardError => e
  Jekyll.logger.warn "GisBlogger:", "Cannot read #{path}: #{e.message}"
  ""
end

#truthy(v) ⇒ Object



28
29
30
31
# File 'lib/jekyll-gis-blogger/utils.rb', line 28

def truthy(v)
  return v if v == true || v == false
  %w[1 true yes y].include?(v.to_s.strip.downcase)
end