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

.load_libraryObject



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

def self.load_library
  return true if @library_loaded

  begin
    require "#{::Rails.root.to_s}/vendor/plugins/#{extension}/lib/#{extension}"
  rescue LoadError
    begin
      require extension # From gem
    rescue LoadError
      puts "A #{extension} file was found, but #{extension} library could not be found, so nothing will be parsed..."
      return false
    end
  end

  require 'gettext_i18n_rails/ruby_gettext_extractor'
  @library_loaded = true
end

.parse(file, msgids = []) ⇒ Object



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

def self.parse(file, msgids = [])
  return msgids unless load_library
  code = convert_to_code(File.read(file))
  RubyGettextExtractor.parse_string(code, file, msgids)
rescue Racc::ParseError => e
  $stderr.puts "file ignored: ruby_parser cannot read #{extension} files with 1.9 syntax --- #{file}: (#{e.message.strip})"
  return msgids
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