Sha256: cfe2f56fa9fba9ca7630ec26310d5985072153d2dd34d270fb7abf3dfdcc3933
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
require "antelope/template/errors" require "antelope/template/scanner" require "antelope/template/compiler" module Antelope class Template NO_SOURCE = Object.new def initialize(input, source = NO_SOURCE) @input = normalize_input(input) @source = determine_source(input, source) end def parse @result ||= begin scanner = Scanner.new(@input, @source) compiler = Compiler.new(scanner.scan) compiler.compile end end def result(binding = TOPLEVEL_BINDING.dup) # sue me. eval(parse, binding, "#{@source}.rb", 0) end alias_method :run, :result alias_method :call, :result private def normalize_input(input) case when String === input input when input.respond_to?(:read) input.read when input.respond_to?(:open) input.open("r") { |f| f.read } else raise ArgumentError, "Received #{input.class}, expected " \ "#{String}, #read" end end def determine_source(input, source) case when source != NO_SOURCE source when input.respond_to?(:to_path) input.to_path else "(template)" end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
antelope-0.2.0 | lib/antelope/template.rb |
antelope-0.1.11 | lib/antelope/template.rb |
antelope-0.1.10 | lib/antelope/template.rb |
antelope-0.1.9 | lib/antelope/template.rb |