Created
December 27, 2012 07:10
-
-
Save mopsled/4386193 to your computer and use it in GitHub Desktop.
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
# 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