Module: Ramaze::Tool::Gettext::Parser

Defined in:
lib/ramaze/contrib/gettext/parser.rb

Constant Summary collapse

TARGETS =
Ramaze::Template::ENGINES.values.inject([]) do |exts, list|
  list += exts
end

Class Method Summary collapse

Class Method Details

.add_message(ary, msg, file, line_number) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/ramaze/contrib/gettext/parser.rb', line 31

def add_message(ary, msg, file, line_number)
  loc = message_location(file, line_number)
  if value = ary.assoc(msg)
    value << loc
  else
    ary << [msg, loc]
  end
  return ary
end

.message_location(file, line_number) ⇒ Object



41
42
43
# File 'lib/ramaze/contrib/gettext/parser.rb', line 41

def message_location(file, line_number)
  file + ":line" + line_number.to_s
end

.parse(file, ary) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ramaze/contrib/gettext/parser.rb', line 18

def parse(file, ary)
  regex = Ramaze::Tool::Gettext.trait[:regex]
  body = File.read(file)
  body.gsub!(regex) do
    msg = $1
    unless msg.to_s.empty?
      line_number = body[0..(body.index(msg))].split("\n").size
      add_message(ary, msg, file, line_number)
    end
  end
  return ary
end

.target?(file) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ramaze/contrib/gettext/parser.rb', line 14

def target?(file)
  TARGETS.include?(File.extname(file)[1..-1])
end