mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 19:33:32 -04:00
feat: Added mustache templating.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
require 'json'
|
||||
require 'yaml'
|
||||
|
||||
# Our custom YAML tags must retain their magic.
|
||||
class TaggedMap < Hash
|
||||
yaml_tag '!code'
|
||||
def init_with(psych_coder)
|
||||
self.replace({:__tag__ => 'code'}.merge(psych_coder.map))
|
||||
end
|
||||
end
|
||||
|
||||
YAML::add_tag('code', TaggedMap)
|
||||
|
||||
desc 'Build all alternate versions of the specs.'
|
||||
multitask :build => [ 'build:json' ]
|
||||
|
||||
namespace :build do
|
||||
note = 'Do not edit this file; changes belong in the appropriate YAML file.'
|
||||
|
||||
desc 'Build JSON versions of the specs.'
|
||||
task :json do
|
||||
rm(Dir['specs/*.json'], :verbose => false)
|
||||
Dir.glob('specs/*.yml').each do |filename|
|
||||
json_file = filename.gsub('.yml', '.json')
|
||||
|
||||
File.open(json_file, 'w') do |file|
|
||||
warning = {:__ATTN__ => note}
|
||||
doc = YAML.load_file(
|
||||
filename,
|
||||
permitted_classes: [TaggedMap]
|
||||
)
|
||||
file << JSON.pretty_generate(warning.merge(doc)) << "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user