Sha256: e335afe93e467e69f1a78495c56e3ca0f677a13407a04b60da2ffec1855501d8

Contents?: true

Size: 933 Bytes

Versions: 3

Compression:

Stored size: 933 Bytes

Contents

# Filter

class String

  def liquid(params={})
    nanoc_require 'liquid'

    Liquid::Template.parse(self).render((params[:assigns] || {}).stringify_keys)
  end

end

register_filter 'liquid' do |page, pages, config|
  assigns = { :page => page, :pages => pages }
  page.content.liquid(:assigns => assigns)
end

# Render tag

begin
  class Nanoc::LiquidRenderTag < ::Liquid::Tag
    Syntax = /(['"])([^'"]+)\1/

    def initialize(markup, tokens)
      if markup =~ Syntax
        @layout_name = $2
      else
        raise SyntaxError.new("Error in tag 'render' - Valid syntax: render '[layout]'")
      end

      super
    end

    def parse(tokens)
    end

    def render(context)
      source  = File.read('layouts/' + @layout_name + '.liquid')
      partial = Liquid::Template.parse(source)

      partial.render(context)
    end
  end

  Liquid::Template.register_tag('render', Nanoc::LiquidRenderTag)
rescue NameError
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-1.6 lib/nanoc/filters/liquid_filter.rb
nanoc-1.6.1 lib/nanoc/filters/liquid_filter.rb
nanoc-1.6.2 lib/nanoc/filters/liquid_filter.rb