Module: GetText::ErbParser
Instance Method Summary collapse
-
#init(config) ⇒ Object
Sets some preferences to parse ERB files.
-
#parse(file, targets = []) ⇒ Object
:nodoc:.
-
#target?(file) ⇒ Boolean
:nodoc:.
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”].
-
26 27 28 29 30 |
# File 'lib/gettext/tools/parser/erb.rb', line 26 def init(config) config.each{|k, v| @config[k] = v } end |
#parse(file, targets = []) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 |
# File 'lib/gettext/tools/parser/erb.rb', line 32 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:
40 41 42 43 44 45 |
# File 'lib/gettext/tools/parser/erb.rb', line 40 def target?(file) # :nodoc: @config[:extnames].each do |v| return true if File.extname(file) == v end false end |