Class: I18nTemplate::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_template/handler.rb

Overview

Handler is ActionView wrapper for erb handler. If internationalize? returns true it calls erb handler with internationalized template otherwise it calls handler with regular template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



8
9
10
11
12
# File 'lib/i18n_template/handler.rb', line 8

def initialize(options = {})
  @options = options
  @default_format = ::Mime::HTML
  init_erb_handler
end

Instance Attribute Details

#default_formatObject (readonly)

default format



15
16
17
# File 'lib/i18n_template/handler.rb', line 15

def default_format
  @default_format
end

#erb_handlerObject (readonly)

erb handler



18
19
20
# File 'lib/i18n_template/handler.rb', line 18

def erb_handler
  @erb_handler
end

Instance Method Details

#call(template) ⇒ Object

call method implements ActionView::Template handler interface



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/i18n_template/handler.rb', line 21

def call(template)
  if internationalize?(template)
    document = ::I18nTemplate::Document.new(template.source)
    document.process!
    document.warnings.each { |warning| $stderr.puts warning } if @options[:verbose]

    erb_handler.call(document)
  else
    erb_handler.call(template)
  end
end