Class: Errgent::Renderer

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Renderer

Returns a new instance of Renderer.



2
3
4
5
6
7
# File 'lib/errgent/renderer.rb', line 2

def initialize(options = {})
  @vars = options[:vars] || {}
  @codes = options[:codes] || [403, 404, 422, 500]
  @layout = options[:layout] || 'layouts/error_page'
  @output = options[:output] || 'public/%s.html'
end

Instance Method Details

#helpers(&block) ⇒ Object



18
19
20
# File 'lib/errgent/renderer.rb', line 18

def helpers(&block)
  action_view.class_eval(&block)
end

#renderObject



9
10
11
12
13
14
15
16
# File 'lib/errgent/renderer.rb', line 9

def render
  @codes.each do |code|
    File.open(Rails.root.join(@output % code), 'w') do |io|
      action_view.assign(@vars.merge(code: code))
      io.write action_view.render(template: @layout)
    end
  end
end