diff options
author | Brandon Mathis <brandon@imathis.com> | 2013-03-10 17:08:56 -0500 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2013-03-10 17:09:12 -0500 |
commit | 2bec7f858a42b01171b157b5cda60cc54feb7e8d (patch) | |
tree | f09f68180aeadc66bd91b039885669f81c33b63e | |
parent | 1c7919902d38a15835a1657a19ec9cf9bbb151be (diff) | |
download | my_new_personal_website-2bec7f858a42b01171b157b5cda60cc54feb7e8d.tar.xz my_new_personal_website-2bec7f858a42b01171b157b5cda60cc54feb7e8d.zip |
added config_tag plugin for integration of configuration into templates
Diffstat (limited to '')
-rw-r--r-- | plugins/config_tag.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/config_tag.rb b/plugins/config_tag.rb new file mode 100644 index 00000000..b071b181 --- /dev/null +++ b/plugins/config_tag.rb @@ -0,0 +1,29 @@ +require 'json' + +class ConfigTag < Liquid::Tag + def initialize(tag_name, options, tokens) + super + @options = options.split(' ').map {|i| i.strip } + @key = @options.first + @tag = (@options[1] || 'div') + end + + def render(context) + config = context.registers[:site].config + options = @options.first.split('.').map { |k| config = config[k] }.last #reference objects with dot notation + keyclass = @key.sub(/_/, '-').sub(/\./, '-') + tag = "<#{@tag} class='#{keyclass}'" + options.each do |k,v| + unless v.nil? + v = v.join ',' if v.respond_to? 'join' + v = v.to_json if v.respond_to? 'keys' + tag += " data-#{k.sub'_','-'}='#{v}'" + end + end + tag += "></#{@tag}>" + p tag + tag + end +end + +Liquid::Template.register_tag('config_tag', ConfigTag) |