Permalink
Browse files

sketched out basics

  • Loading branch information...
0 parents commit 2e47c37b2ef25950c603bc346e482eb606259a0c @matthewowen committed Jul 9, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 jekyll_json.rb
@@ -0,0 +1,24 @@
+require 'json'
+
+module Jekyll
+ class JSONTag < Liquid::Tag
+ def initialize(tag_name, text, tokens)
+ @key = text.strip
+ @hash_to_jsonify = Jekyll.configuration({})[@key]
+ super
+ end
+ def render(context)
+ @data = context['page'][@key]
+ # this isn't a sophisticated merge. if there are nested
+ # hashes, it'll completely overwrite them (so if you have
+ # deeply nested settings in _config.yml that aren't replicated
+ # in your page's settings, they'll get blatted).
+ @data.each_pair do |k,v|
+ @hash_to_jsonify[k] = v
+ end
+ return @hash_to_jsonify.to_json
+ end
+ end
+end
+
+Liquid::Template.register_tag('yaml_to_json', Jekyll::JSONTag)

0 comments on commit 2e47c37

Please sign in to comment.