Sha256: aefc532d7b9465584a3aff1161650eee5bbe5fd18405d1eb865aead517505c0b

Contents?: true

Size: 781 Bytes

Versions: 4

Compression:

Stored size: 781 Bytes

Contents

module Cutaneous
  class Template
    attr_accessor :loader, :lexer, :path

    def initialize(lexer)
      @lexer = lexer
    end

    def compiler
      @compiler ||= Compiler.new(lexer, loader)
    end

    def render(context)
      context.__loader = loader
      context.instance_eval(&template_proc)
    end

    def convert(to_syntax)
      lexer.convert(to_syntax)
    end

    def template_proc
      @template_proc ||= eval(template_proc_src, nil, path || "(cutaneous)")
    end

    def template_proc_src
      "lambda { |context| self.__buf = __buf = ''; #{script}; __buf.to_s }"
    end

    def script
      compiler.script
    end

    def block_order
      compiler.block_order
    end

    def block(block_name)
      compiler.block(block_name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cutaneous-0.3.0 lib/cutaneous/template.rb
cutaneous-0.2.0 lib/cutaneous/template.rb
cutaneous-0.1.7 lib/cutaneous/template.rb
cutaneous-0.1.6 lib/cutaneous/template.rb