Class: IRust::TemplateRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/irust/template_renderer.rb

Constant Summary collapse

RUST_TEMPLATE =
File.expand_path("../template.rs.erb", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rust_code, history = nil) ⇒ TemplateRenderer

Returns a new instance of TemplateRenderer.



9
10
11
# File 'lib/irust/template_renderer.rb', line 9

def initialize(rust_code, history = nil)
  @rust_code, @history = rust_code, history
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



7
8
9
# File 'lib/irust/template_renderer.rb', line 7

def history
  @history
end

#rust_codeObject (readonly)

Returns the value of attribute rust_code.



7
8
9
# File 'lib/irust/template_renderer.rb', line 7

def rust_code
  @rust_code
end

Instance Method Details

#let_varObject



18
19
20
# File 'lib/irust/template_renderer.rb', line 18

def let_var
  rust_code[/^\s*(let|fn)\s+(mut\s+)?(\w+)/, 3]
end

#renderObject



13
14
15
16
# File 'lib/irust/template_renderer.rb', line 13

def render
  template = File.read(RUST_TEMPLATE)
  ERB.new(template).result(binding)
end