Sha256: e7a2a88bdf9d73df6b3010c0e90554119b3c5f9f0d056c6e369b01349bd54dfd

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

=begin
  gettext/erb.rb - GetText for ERB

  Copyright (C) 2005,2006  Masao Mutoh

  You may redistribute it and/or modify it under the same
  license terms as Ruby.

  $Id: erb.rb,v 1.4 2006/12/06 16:39:58 mutoh Exp $
=end

require 'erb'
require 'gettext'

module GetText

  # 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.
  module ErbContainer
    include GetText

    # Evaluates ERB source(String) in the instance and returns the result HTML.
    #
    # * rhtml: an ERB source
    # * Returns: the Evaluated ERB result
    def eval_src(rhtml)
      erb = ERB.new(rhtml).src
      eval(erb, binding)
    end

    # Evaluates ERB file in the instance and returns the result HTML.
    #
    # * rhtml: an ERB file
    # * Returns: the Evaluated ERB result
    def eval_file(rhtmlpath)
      eval_src(IO.read(rhtmlpath))
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gettext-1.10.0-mswin32 lib/gettext/erb.rb
gettext-1.9.0-mswin32 lib/gettext/erb.rb
gettext-1.10.0 lib/gettext/erb.rb
gettext-1.90.0 lib/gettext/erb.rb
gettext-1.9.0 lib/gettext/erb.rb
gettext-1.91.0 lib/gettext/erb.rb
gettext-1.92.0 lib/gettext/erb.rb
gettext-1.93.0 lib/gettext/erb.rb