Created
June 12, 2017 13:29
-
-
Save solisoft/6b9896f4ba4bc69264770757fc6ef0bd to your computer and use it in GitHub Desktop.
Compile mustache template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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