Sha256: 8041255b395892ec453caef1f5e4ce436b144c08da8df27d3c548b9b8c620ecb

Contents?: true

Size: 911 Bytes

Versions: 1

Compression:

Stored size: 911 Bytes

Contents

require 'malt/formats/abstract_template'
require 'malt/formats/html'
require 'malt/engines/tenjin'

module Malt::Formats

  # Tenjin
  #
  #   http://www.kuwata-lab.com/tenjin/
  #
  class Tenjin < AbstractTemplate

    register 'tenjin'

    def rb
      render_engine.compile(text, file)
    end

    # Erb templates can be "precompiled" into Ruby templates.
    def to_rb
      text = rb
      Ruby.new(:text=>text, :file=>refile(:rb), :type=>:rb)
    end

    alias_method(:to_ruby, :to_rb)

    #
    def html
      render(:html, data, &yld)
    end

    #
    def to_html(data, &yld)
      new_text    = render(:html, data, &yld)
      new_file    = refile(:html)
      new_options = options.merge(:text=>new_text, :file=>new_file, :type=>:html)
      HTML.new(new_options)
    end

    private

    #
    def render_engine
      @render_engine ||= Malt::Engines::Tenjin.new(options)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
malt-0.1.0 lib/malt/formats/tenjin.rb