Module: GetText::ErbContainer

Includes:
GetText
Defined in:
lib/gettext/erb.rb

Overview

This module provides basic functions to evaluate plural ERB files(.rhtml) in a TextDomain. You need to implement a class which includes GetText::ErbContainer.

See simple examples below:

require 'gettext/erb'
class SimpleContainer
  include GetText::ErbContainer

  def initialize(domainname, domainpath = nil, locale = nil, charset = nil)
    bindtextdomain(domainname, domainpath, locale)
  end
end

container = SimpleContainer.new("helloerb1", "locale")
puts container.eval_file("/your/erb/file.rhtml")

This module is an example for template engines such as ERB. You can implement another implementation easily to read gettext/erb.rb.

Constant Summary

Constants included from GetText

CACHE_BOUND_TARGET_MAX_SIZE, VERSION

Instance Method Summary collapse

Methods included from GetText

N_, #Nn_, _, #add_default_locale_path, bindtextdomain, #bindtextdomain_to, bound_target, bound_targets, cached=, cached?, cgi, cgi=, clear_cache, create_mofiles, current_textdomain_info, each_textdomain, find_targets, gettext, included, locale, locale=, msgmerge, msgmerge_all, n_, ngettext, #npgettext, ns_, nsgettext, output_charset, output_charset=, p_, pgettext, remove_all_textdomains, rgettext, rmsgfmt, rmsgmerge, s_, set_cgi, set_locale, set_locale_all, set_output_charset, setlocale, sgettext, textdomain, #textdomain_to, update_pofiles

Instance Method Details

#eval_file(rhtmlpath) ⇒ Object

Evaluates ERB file in the instance and returns the result HTML.

  • rhtml: an ERB file

  • Returns: the Evaluated ERB result



52
53
54
# File 'lib/gettext/erb.rb', line 52

def eval_file(rhtmlpath)
  eval_src(IO.read(rhtmlpath))
end

#eval_src(rhtml) ⇒ Object

Evaluates ERB source(String) in the instance and returns the result HTML.

  • rhtml: an ERB source

  • Returns: the Evaluated ERB result



43
44
45
46
# File 'lib/gettext/erb.rb', line 43

def eval_src(rhtml)
  erb = ERB.new(rhtml).src
  eval(erb, binding)
end