Class: GettextI18nRails::BaseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext_i18n_rails/base_parser.rb

Direct Known Subclasses

HamlParser, SlimParser

Class Method Summary collapse

Class Method Details

.librariesObject



15
16
17
# File 'lib/gettext_i18n_rails/base_parser.rb', line 15

def self.libraries
  [extension]
end

.load_libraryObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gettext_i18n_rails/base_parser.rb', line 19

def self.load_library
  return true if @library_loaded

  loaded = libraries.detect do |library|
    if Gem::Specification.find_all_by_name(library).any?
      require library
      true
    else
      false
    end
  end

  unless loaded
    puts "No #{extension} library could be found: #{libraries.join(" or ")}"

    return false
  end

  require 'gettext/tools/parser/ruby'
  @library_loaded = loaded
end

.parse(file, options = {}, _msgids = []) ⇒ Object



9
10
11
12
13
# File 'lib/gettext_i18n_rails/base_parser.rb', line 9

def self.parse(file, options = {}, _msgids = [])
  return _msgids unless load_library
  code = convert_to_code(File.read(file))
  GetText::RubyParser.new(file, options).parse_source(code)
end

.target?(file) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/gettext_i18n_rails/base_parser.rb', line 5

def self.target?(file)
  File.extname(file) == ".#{extension}"
end