Module: GetText::ErbParser

Extended by:
ErbParser
Included in:
ErbParser
Defined in:
lib/gettext/tools/parser/erb.rb

Instance Method Summary collapse

Instance Method Details

#init(config) ⇒ Object

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”].



24
25
26
27
28
# File 'lib/gettext/tools/parser/erb.rb', line 24

def init(config)
  config.each{|k, v|
	@config[k] = v
  }
end

#parse(file, targets = []) ⇒ Object

:nodoc:



30
31
32
33
34
35
36
# File 'lib/gettext/tools/parser/erb.rb', line 30

def parse(file, targets = []) # :nodoc:
  src = ERB.new(IO.readlines(file).join).src
  # Remove magic comment prepended by erb in Ruby 1.9.
  src.sub!(/\A#.*?coding[:=].*?\n/, '') if src.respond_to?(:encode)
  erb = src.split(/$/)
  RubyParser.parse_lines(file, erb, targets)
end

#target?(file) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/gettext/tools/parser/erb.rb', line 38

def target?(file) # :nodoc:
  @config[:extnames].each do |v|
	return true if File.extname(file) == v
  end
  false
end