class I18nExtract::Extractor

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/i18n_extract/extractor.rb, line 24
def initialize path
  @path = path
  @buffer = Parser::Source::Buffer.new(@path)
  @buffer.source = File.read(@path)
  @parser = BetterHtml::Parser.new(@buffer)
end

Public Instance Methods

extract() click to toggle source
# File lib/i18n_extract/extractor.rb, line 31
def extract
  children = @parser.ast

  HTMLIterator.descendants(children).reject { |node|
    node.children.reject{|child| !child.is_a?(String) }.map(&:strip).join('').empty?
  }.to_a
end
validate!() click to toggle source
# File lib/i18n_extract/extractor.rb, line 39
def validate!
  res = extract
  res.each do |node|
    raise ExtractError.new(node, "Found hard coded string") unless node.children.join('').blank?
  end
end