Class: Flott::Template

Inherits:
Proc
  • Object
show all
Defined in:
lib/flott.rb

Overview

Class for compiled Template objects, that can later be evaluated in a Flott::Environment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemplate

Sets up a Template instance.



481
482
483
484
# File 'lib/flott.rb', line 481

def initialize
  super
  @pathes = []
end

Instance Attribute Details

#environmentObject

The environment this template was evaluated in during the last evaluate call. Returns nil if it wasn’t evaluated yet.



498
499
500
# File 'lib/flott.rb', line 498

def environment
  @environment
end

#page_cacheObject

Returns the Flott::Cache this Template originated from or nil, if no cache was used.



494
495
496
# File 'lib/flott.rb', line 494

def page_cache
  @page_cache
end

#pathesObject

The pathes of the template and all included sub-templates.



487
488
489
# File 'lib/flott.rb', line 487

def pathes
  @pathes
end

#sourceObject

The template’s source code after compilation.



490
491
492
# File 'lib/flott.rb', line 490

def source
  @source
end

Instance Method Details

#call(environment = Flott::Environment.new) ⇒ Object Also known as: evaluate

Evaluates this Template Object in the Environment environment (first argument).



507
508
509
510
511
512
513
514
515
516
# File 'lib/flott.rb', line 507

def call(environment = Flott::Environment.new, *)
  @environment = environment
  @environment.template = self
  @environment.page_cache = page_cache
  result = super
  attach_environment_to_output
  result
rescue SyntaxError => e
  raise CallError.wrap(e)
end

#mtimeObject

Returns the newest mtime of all the involved #pathes.



501
502
503
# File 'lib/flott.rb', line 501

def mtime
  @pathes.map { |path| File.stat(path).mtime }.max
end