Class: Rapid::Template::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rapid/template/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/rapid/template/base.rb', line 8

def initialize content, options = {}
  @content = polish_content content
  @filename = options[:filename]
  
  @erb = Erubis::Eruby.new @content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/rapid/template/base.rb', line 6

def content
  @content
end

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/rapid/template/base.rb', line 6

def filename
  @filename
end

Instance Method Details

#pull(content) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rapid/template/base.rb', line 21

def pull content
  content = polish_content content
  
  nodes = Parser.new(@content).parse
  
  result = Pulling::Forgiving.new(content)
  nodes.pull result
  
  result.empty!
  result.to_hash
end

#push(skeleton) ⇒ Object



15
16
17
18
19
# File 'lib/rapid/template/base.rb', line 15

def push skeleton
  @erb.result skeleton.get_binding
rescue Exception, SyntaxError, NameError => e
  raise TemplateRenderError.new(@filename, e)
end