Sha256: 8cb63923a23689238db5651503a0c350915f1354d9c172a120906a166d3ff931

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'malt/engines/abstract'

module Malt::Engine

  # Erubis template implementation.
  #
  #   http://www.kuwata-lab.com/erubis/
  #
  # Erubis is essentially compatibel with ERB, but it is faster.
  #
  class Erubis < Abstract

    register :erb, :rhtml

    # Render template.
    def render(params, &yld)
      text = params[:text]
      data = params[:data]
      data = make_binding(data, &yld)
      intermediate(params).result(data)
    end

    # Compile template into Ruby source code.
    def compile(params)
      text = params[:text]
      file = params[:file]
      intermediate(text, file).src
    end

    #
    def intermediate(params)
      text = params[:text]
      file = params[:file]

      opts = {}

      if params[:escape_html] || settings[:escape_html]
        ::Erubis::EscapedEruby.new(text, settings)
      else
        ::Erubis::Eruby.new(text, settings)
      end
    end

    #
    def safe
      options[:safe]
    end

    #
    def trim
      options[:trim]
    end

    ;;;; private ;;;;

    # Load ERB library if not already loaded.
    def initialize_engine
      return if defined? ::Erubius
      require_library('erubis')
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
malt-0.3.0 lib/malt/engines/erubis.rb
malt-0.2.0 lib/malt/engines/erubis.rb
malt-0.1.1 lib/malt/engines/erubis.rb