Skip to content

Instantly share code, notes, and snippets.

@mopsled
Created December 27, 2012 07:10
Show Gist options
  • Save mopsled/4386193 to your computer and use it in GitHub Desktop.
Save mopsled/4386193 to your computer and use it in GitHub Desktop.
# Note: You can use any normal ruby library in your extenstion
require 'yaml'
module Jekyll
class YAMLToArray < Liquid::Tag
def initialize(tag_name, params, tokens)
super
@file, @variable = params.split(',', 2).map{ |x| x.strip }
end
def render(context)
includes_dir = File.join(context.registers[:site].source, '_includes')
yaml_file = File.join(includes_dir, @file)
if File.file? yaml_file
context.environments.first[@variable] = YAML.load_file(yaml_file)
return
else
"Included file '#{@file}' not found in _includes directory"
end
end
end
end
Liquid::Template.register_tag('yaml_to_array', Jekyll::YAMLToArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment