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.



14
15
16
17
# File 'lib/troy/embedded_ruby.rb', line 14

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

Instance Attribute Details

#contentObject (readonly)

The template content.



7
8
9
# File 'lib/troy/embedded_ruby.rb', line 7

def content
  @content
end

#dataObject (readonly)

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



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

def data
  @data
end

Instance Method Details

#contextObject



19
20
21
# File 'lib/troy/embedded_ruby.rb', line 19

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

#renderObject



23
24
25
# File 'lib/troy/embedded_ruby.rb', line 23

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