Class: Utopia::Trenni

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/trenni.rb

Defined Under Namespace

Classes: Buffer, Scanner

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, filename = '<Trenni>') ⇒ Trenni

Returns a new instance of Trenni.



112
113
114
115
116
# File 'lib/utopia/trenni.rb', line 112

def initialize(template, filename = '<Trenni>')
	@template = template
	@filename = filename
	compile!
end

Class Method Details

.load(path) ⇒ Object



108
109
110
# File 'lib/utopia/trenni.rb', line 108

def self.load(path)
	return self.new(File.read(path), path)
end

Instance Method Details

#compile!(filename = @filename) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/utopia/trenni.rb', line 118

def compile!(filename = @filename)
	buffer = Buffer.new
	scanner = Scanner.new(buffer, @template)
	
	scanner.parse
	
	@code = buffer.code
end

#result(binding) ⇒ Object



127
128
129
# File 'lib/utopia/trenni.rb', line 127

def result(binding)
	eval(@code, binding, @filename)
end