Skip to content

Instantly share code, notes, and snippets.

@solisoft
Created June 12, 2017 13:29
Show Gist options
  • Save solisoft/6b9896f4ba4bc69264770757fc6ef0bd to your computer and use it in GitHub Desktop.
Save solisoft/6b9896f4ba4bc69264770757fc6ef0bd to your computer and use it in GitHub Desktop.
Compile mustache template
# Beware arguments have a limit size ...
require "./mustache_cr/*"
require "option_parser"
require "json"
require "crustache"
require "base64"
module MustacheCr
template = ""
json = {} of String => String
OptionParser.parse! do |parser|
parser.banner = "Usage: mustache_cr [arguments]"
parser.on("-t NAME", "--template=NAME", "Mustache Template as base64") { |t| template = Base64.decode_string(t) }
parser.on("-j JSON", "--json=JSON", "JSON data to load as base64") { |j|
json = JSON.parse(Base64.decode_string(j)).as_h
}
end
# Parse a mustache template
unless template.empty?
renderer = Crustache.parse(template)
# Render!
puts Crustache.render renderer, json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment