Class: I18nliner::Processors::RubyProcessor

Inherits:
AbstractProcessor show all
Defined in:
lib/i18nliner/processors/ruby_processor.rb

Direct Known Subclasses

ErbProcessor

Constant Summary collapse

CONTROLLER_PATH =
%r{\A(.*/)?app/controllers/(.*)_controller\.rb\z}

Instance Attribute Summary

Attributes inherited from AbstractProcessor

#file_count, #translation_count

Instance Method Summary collapse

Methods inherited from AbstractProcessor

#check_file, #check_files, default_pattern, #files, inherited, #initialize, #noop_checker

Constructor Details

This class inherits a constructor from I18nliner::Processors::AbstractProcessor

Instance Method Details

#check_contents(source, scope = Scope.new) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/i18nliner/processors/ruby_processor.rb', line 11

def check_contents(source, scope = Scope.new)
  return if source !~ Extractors::RubyExtractor.pattern
  sexps = RubyParser.new.parse(pre_process(source))
  extractor = Extractors::RubyExtractor.new(sexps, scope)
  extractor.each_translation do |key, value|
    @translation_count += 1
    @translations.line = extractor.current_line
    @translations[key] = value
  end
end

#pre_process(source) ⇒ Object



43
44
45
# File 'lib/i18nliner/processors/ruby_processor.rb', line 43

def pre_process(source)
  source
end

#scope_for(path) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/i18nliner/processors/ruby_processor.rb', line 28

def scope_for(path)
  scope = path.dup
  if scope.sub!(CONTROLLER_PATH, '\2')
    scope = scope.gsub(/\/_?/, '.')
    ControllerScope.new(scope, :allow_relative => true, :context => self)
  else
    Scope.root
  end
end

#source_for(file) ⇒ Object



22
23
24
# File 'lib/i18nliner/processors/ruby_processor.rb', line 22

def source_for(file)
  File.read(file)
end