Class: GetText::ErbParser

### Home Classes Methods

### In Files

- lib/gettext/tools/parser/erb.rb

### Parent

Object

### Methods

- ::init
- ::new
- ::parse
- #detect_encoding
- #parse

### Class/Module Index

Quicksearch

- GetText
- GetText::ClassInfo
- GetText::ErbParser
- GetText::GladeParser
- GetText::LocalePath
- GetText::MO
- GetText::MO::HeaderRev1
- GetText::MO::InvalidFormat
- GetText::NoboundTextDomainError
- GetText::PO
- GetText::PO::NonExistentEntryError
- GetText::POEntry
- GetText::POEntry::Formatter
- GetText::POEntry::InvalidTypeError
- GetText::POEntry::NoMsgctxtError
- GetText::POEntry::NoMsgidError
- GetText::POEntry::NoMsgidPluralError
- GetText::POEntryForRubyParser
- GetText::POFormat
- GetText::POParser
- GetText::ParseError
- GetText::RubyParser
- GetText::TextDomain
- GetText::TextDomainGroup
- GetText::TextDomainManager
- GetText::Tools
- GetText::Tools::MsgCat
- GetText::Tools::MsgCat::Config
- GetText::Tools::MsgCat::Merger
- GetText::Tools::MsgInit
- GetText::Tools::MsgInit::ArgumentError
- GetText::Tools::MsgInit::Error
- GetText::Tools::MsgInit::ValidationError
- GetText::Tools::MsgMerge
- GetText::Tools::MsgMerge::Config
- GetText::Tools::MsgMerge::FuzzyEntryFinder
- GetText::Tools::MsgMerge::Merger
- GetText::Tools::Task
- GetText::Tools::Task::Error
- GetText::Tools::Task::Path
- GetText::Tools::Task::ValidationError
- GetText::Tools::XGetText

No matching classes.

# GetText::ErbParser

### Constants

MAGIC_COMMENT

### Public Class Methods

init(config) click to toggle source

Sets some preferences to parse ERB files.

- config: a Hash of the config. It can takes some values below:

  - :extnames: An Array of target files extension. Default is [".rhtml"].

    # File lib/gettext/tools/parser/erb.rb, line 24
    def init(config)
      config.each{|k, v|
        @config[k] = v
      }
    end

new(path, options={}) click to toggle source

@param path [String] eRuby script path to be parsed @param options [Hash]

    # File lib/gettext/tools/parser/erb.rb, line 54
    def initialize(path, options={})
      @path = path
      @options = options
    end

parse(path, options={}) click to toggle source

Parses eRuby script located at `path`.

This is a short cut method. It equals to `new(path, options).parse`.

@return [Array<POEntry>] Extracted messages @see initialize and parse

    # File lib/gettext/tools/parser/erb.rb, line 44
    def parse(path, options={})
      parser = new(path, options)
      parser.parse
    end

### Public Instance Methods

detect_encoding(erb_source) click to toggle source

    # File lib/gettext/tools/parser/erb.rb, line 77
    def detect_encoding(erb_source)
      if /\A#coding:(.*)\n/ =~ erb_source
        $1
      else
        nil
      end
    end

parse() click to toggle source

Extracts messages from @path.

@return [Array<POEntry>] Extracted messages

    # File lib/gettext/tools/parser/erb.rb, line 62
    def parse
      content = IO.read(@path)
      src = ERB.new(content).src

      # Force the src encoding back to the encoding in magic comment
      # or original content.
      encoding = detect_encoding(src) || content.encoding
      src.force_encoding(encoding)

      # Remove magic comment prepended by erb in Ruby 1.9.
      src = src.gsub(MAGIC_COMMENT, "")

      RubyParser.new(@path, @options).parse_source(src)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.