Class: GetTextSlim::Parser
- Inherits:
-
Object
- Object
- GetTextSlim::Parser
- Defined in:
- lib/gettext-slim/parser.rb
Class Method Summary collapse
-
.init(config) ⇒ Object
Sets some preferences to parse Slim files.
-
.parse(path, options = {}) ⇒ Array<POEntry>
Parses Slim file located at
path. -
.target?(file) ⇒ Boolean
:nodoc:.
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Array<POEntry>
Extracts messages from @path.
Constructor Details
#initialize(path, options = {}) ⇒ Parser
Returns a new instance of Parser.
57 58 59 60 |
# File 'lib/gettext-slim/parser.rb', line 57 def initialize(path, ={}) @path = path @options = end |
Class Method Details
.init(config) ⇒ Object
Sets some preferences to parse Slim files.
- config: a Hash of the config. It can takes some values below:
- :extnames: An Array of target files extension. Default is [".slim"].
29 30 31 32 33 |
# File 'lib/gettext-slim/parser.rb', line 29 def init(config) config.each do |key, value| @config[key] = value end end |
.parse(path, options = {}) ⇒ Array<POEntry>
Parses Slim file located at path.
This is a short cut method. It equals to new(path,
options).parse.
49 50 51 52 |
# File 'lib/gettext-slim/parser.rb', line 49 def parse(path, ={}) parser = new(path, ) parser.parse end |
.target?(file) ⇒ Boolean
:nodoc:
35 36 37 38 39 40 |
# File 'lib/gettext-slim/parser.rb', line 35 def target?(file) # :nodoc: @config[:extnames].each do |extname| return true if File.extname(file) == extname end false end |
Instance Method Details
#parse ⇒ Array<POEntry>
Extracts messages from @path.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gettext-slim/parser.rb', line 65 def parse content = File.open(@path, "rb", &:read) encoding = detect_encoding(content) || content.encoding content.force_encoding(encoding) template = Slim::Template.new(@path) do content end source = template.precompiled_template ruby_parser = GetText::RubyParser.new(@path, @options) ruby_parser.parse_source(source) end |