Class: Makanai::Template

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

Defined Under Namespace

Classes: UnsupportedException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, engine: :erb, locals: {}) ⇒ Template

Returns a new instance of Template.



7
8
9
10
11
# File 'lib/makanai/template.rb', line 7

def initialize(path:, engine: :erb, locals: {})
  @path = path
  @engine = engine
  @locals = locals
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



13
14
15
# File 'lib/makanai/template.rb', line 13

def engine
  @engine
end

#localsObject (readonly)

Returns the value of attribute locals.



13
14
15
# File 'lib/makanai/template.rb', line 13

def locals
  @locals
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/makanai/template.rb', line 13

def path
  @path
end

Instance Method Details

#renderObject



15
16
17
18
# File 'lib/makanai/template.rb', line 15

def render
  template_file = File.read("#{path}.#{engine}")
  engine_class.new(text: template_file, locals: locals).result
end