Sha256: 41fe54b2c25ca7b2999e8f1d334a8c5e89ed43c0541ebeb719110281b42a80e1

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'malt/engines/abstract'

module Malt::Engine

  # Tenjin
  #
  #   http://www.kuwata-lab.com/tenjin/
  #
  # options
  #   :escapefunc=>'CGI.escapeHTML'
  #
  class Tenjin < Abstract

    default :tenjin, :rbhtml

    #
    def render(params, &yld)
      text = params[:text]
      file = params[:file]
      data = params[:data]
      type = params[:type]
      into = params[:to] || :html

      return super(params, &yld) if type == :rbhtml && into != :html

      data = make_hash(data, &yld)
      template = intermediate(params)
      template.convert(text, file)

      template.render(data)
    end

    #
    def compile(params)
      text = params[:text]
      file = params[:file]
      intermediate(params).convert(text, file) 
    end

    private

    def intermediate(params)
      ::Tenjin::Template.new(nil, engine_options(params))
    end

    # Load Liquid library if not already loaded.
    def initialize_engine
      return if defined? ::Tenjin::Engine
      require_library 'tenjin'
    end

    def engine_options(params)
      opts = {}
      opts[:escapefunc] = params[:escapefunc] || settings[:escapefunc]
      opts
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
malt-0.3.0 lib/malt/engines/tenjin.rb
malt-0.2.0 lib/malt/engines/tenjin.rb