Class: Scribble::Template

Inherits:
Partial
  • Object
show all
Defined in:
lib/scribble/template.rb

Defined Under Namespace

Classes: Context

Instance Attribute Summary

Attributes inherited from Partial

#format

Instance Method Summary collapse

Methods inherited from Partial

#nodes, #parse, #transform

Constructor Details

#initialize(source, format: nil, loader: nil, converters: []) ⇒ Template

Returns a new instance of Template.



4
5
6
7
# File 'lib/scribble/template.rb', line 4

def initialize source, format: nil, loader: nil, converters: []
  super source, format: format
  @loader, @converters = loader, converters
end

Instance Method Details

#find_converter(from, to) ⇒ Object

Find converter



57
58
59
# File 'lib/scribble/template.rb', line 57

def find_converter from, to
  @converters.find { |converter| converter.from == from && converter.to == to }
end

#load(name, context) ⇒ Object

Load partial



45
46
47
48
49
50
51
52
53
# File 'lib/scribble/template.rb', line 45

def load name, context
  if @loader
    if partial = @loader.load(name)
      Partial::Context.new partial, context
    end
  else
    raise 'Cannot load partial without loader'
  end
end

#render(variables: {}, registers: {}, format: nil) ⇒ Object

Render



39
40
41
# File 'lib/scribble/template.rb', line 39

def render variables: {}, registers: {}, format: nil
  Context.new(self, registers, variables, format).render
end