diff --git a/Rakefile b/Rakefile index 6c6008f..087a342 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,15 @@ require 'json' require 'yaml' -# Our custom YAML tags must retain their magic. -%w[ code ].each do |tag| - YAML::add_builtin_type(tag) { |_,val| val.merge(:__tag__ => tag) } +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' ] diff --git a/specs/~lambdas.json b/specs/~lambdas.json index 3a0ac03..c139628 100644 --- a/specs/~lambdas.json +++ b/specs/~lambdas.json @@ -7,6 +7,7 @@ "desc": "A lambda's return value should be interpolated.", "data": { "lambda": { + "__tag__": "code", "ruby": "proc { \"world\" }", "perl": "sub { \"world\" }", "js": "function() { return \"world\" }", @@ -25,6 +26,7 @@ "data": { "planet": "world", "lambda": { + "__tag__": "code", "ruby": "proc { \"{{planet}}\" }", "perl": "sub { \"{{planet}}\" }", "js": "function() { return \"{{planet}}\" }", @@ -43,6 +45,7 @@ "data": { "planet": "world", "lambda": { + "__tag__": "code", "ruby": "proc { \"|planet| => {{planet}}\" }", "perl": "sub { \"|planet| => {{planet}}\" }", "js": "function() { return \"|planet| => {{planet}}\" }", @@ -60,6 +63,7 @@ "desc": "Interpolated lambdas should not be cached.", "data": { "lambda": { + "__tag__": "code", "ruby": "proc { $calls ||= 0; $calls += 1 }", "perl": "sub { no strict; $calls += 1 }", "js": "function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }", @@ -77,6 +81,7 @@ "desc": "Lambda results should be appropriately escaped.", "data": { "lambda": { + "__tag__": "code", "ruby": "proc { \">\" }", "perl": "sub { \">\" }", "js": "function() { return \">\" }", @@ -95,6 +100,7 @@ "data": { "x": "Error!", "lambda": { + "__tag__": "code", "ruby": "proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }", "perl": "sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }", "js": "function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }", @@ -113,6 +119,7 @@ "data": { "planet": "Earth", "lambda": { + "__tag__": "code", "ruby": "proc { |text| \"#{text}{{planet}}#{text}\" }", "perl": "sub { $_[0] . \"{{planet}}\" . $_[0] }", "js": "function(txt) { return txt + \"{{planet}}\" + txt }", @@ -131,6 +138,7 @@ "data": { "planet": "Earth", "lambda": { + "__tag__": "code", "ruby": "proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }", "perl": "sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }", "js": "function(txt) { return txt + \"{{planet}} => |planet|\" + txt }", @@ -148,6 +156,7 @@ "desc": "Lambdas used for sections should not be cached.", "data": { "lambda": { + "__tag__": "code", "ruby": "proc { |text| \"__#{text}__\" }", "perl": "sub { \"__\" . $_[0] . \"__\" }", "js": "function(txt) { return \"__\" + txt + \"__\" }", @@ -166,6 +175,7 @@ "data": { "static": "static", "lambda": { + "__tag__": "code", "ruby": "proc { |text| false }", "perl": "sub { 0 }", "js": "function(txt) { return false }",