Class: GetText::ErubiParser
- Inherits:
-
Object
- Object
- GetText::ErubiParser
- Defined in:
- lib/gettext/tools/parser/erubi.rb
Class Method Summary collapse
-
.init(config) ⇒ Object
Sets some preferences to parse ERB files.
-
.parse(path, options = {}) ⇒ Array<POEntry>
Parses eRuby script located at
path
. -
.target?(file) ⇒ Boolean
:nodoc:.
Instance Method Summary collapse
- #detect_encoding(content) ⇒ Object
-
#initialize(path, options = {}) ⇒ ErubiParser
constructor
A new instance of ErubiParser.
-
#parse ⇒ Array<POEntry>
Extracts messages from @path.
Constructor Details
#initialize(path, options = {}) ⇒ ErubiParser
Returns a new instance of ErubiParser.
53 54 55 56 |
# File 'lib/gettext/tools/parser/erubi.rb', line 53 def initialize(path, ={}) @path = path @options = end |
Class 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"].
25 26 27 28 29 |
# File 'lib/gettext/tools/parser/erubi.rb', line 25 def init(config) config.each{|k, v| @config[k] = v } end |
.parse(path, options = {}) ⇒ Array<POEntry>
Parses eRuby script located at path
.
This is a short cut method. It equals to new(path,
options).parse
.
45 46 47 48 |
# File 'lib/gettext/tools/parser/erubi.rb', line 45 def parse(path, ={}) parser = new(path, ) parser.parse end |
.target?(file) ⇒ Boolean
:nodoc:
31 32 33 34 35 36 |
# File 'lib/gettext/tools/parser/erubi.rb', line 31 def target?(file) # :nodoc: @config[:extnames].each do |v| return true if File.extname(file) == v end false end |
Instance Method Details
#detect_encoding(content) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/gettext/tools/parser/erubi.rb', line 73 def detect_encoding(content) if /#.*coding: (\S*)/ =~ content.lines.first $1.upcase else content.encoding end end |
#parse ⇒ Array<POEntry>
Extracts messages from @path.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gettext/tools/parser/erubi.rb', line 61 def parse content = IO.read(@path) encoding = detect_encoding(content) content.force_encoding(encoding) erb = Erubi::Engine.new(content) src = erb.src RubyParser.new(@path, @options).parse_source(src) end |