Class: Conjur::WebServer::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/conjur/webserver/renderer.rb

Overview

a helper class to render HTML partials

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Renderer

Returns a new instance of Renderer.



5
6
7
8
# File 'lib/conjur/webserver/renderer.rb', line 5

def initialize root
  @root = root
  @files = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *a, &b) ⇒ Object (private)



18
19
20
21
22
23
24
25
26
27
# File 'lib/conjur/webserver/renderer.rb', line 18

def method_missing name, *a, &b
  super if !a.empty? || block_given?

  # try to load fragments
  path = expand_path "_#{name}.html"
  super unless File.exists? path

  @files << path
  File.read path
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



10
11
12
# File 'lib/conjur/webserver/renderer.rb', line 10

def files
  @files
end

Instance Method Details

#render(template) ⇒ Object



12
13
14
# File 'lib/conjur/webserver/renderer.rb', line 12

def render template
  ERB.new(template).result binding
end