Class: Troy::EmbeddedRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/troy/embedded_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, data) ⇒ EmbeddedRuby

Returns a new instance of EmbeddedRuby.



12
13
14
15
# File 'lib/troy/embedded_ruby.rb', line 12

def initialize(content, data)
  @content = content
  @data = data
end

Instance Attribute Details

#contentObject (readonly)

The template content.



5
6
7
# File 'lib/troy/embedded_ruby.rb', line 5

def content
  @content
end

#dataObject (readonly)

The data that must be rendered within the Troy::Context object.



10
11
12
# File 'lib/troy/embedded_ruby.rb', line 10

def data
  @data
end

Instance Method Details

#contextObject



17
18
19
# File 'lib/troy/embedded_ruby.rb', line 17

def context
  @context ||= Context.new(data).extend(Helpers)
end

#renderObject



21
22
23
# File 'lib/troy/embedded_ruby.rb', line 21

def render
  ERB.new(content).result context.to_binding
end