Sha256: f98b87d1a9ea372b74217e9e155380687aa8e1bf25ed604c6247934448338e08

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# Used to find translations in the Rails app by inspecting .erb- and .haml-files.
class AwesomeTranslations::ErbInspector
  autoload :FileInspector, "#{File.dirname(__FILE__)}/erb_inspector/file_inspector"
  autoload :TranslationInspector, "#{File.dirname(__FILE__)}/erb_inspector/translation_inspector"

  def initialize(args = {})
    if args[:dirs]
      @dirs = args[:dirs]
    else
      @dirs = AwesomeTranslations.config.paths_to_translate
    end
  end

  # Yields all relevant .erb- and .haml-files.
  def files
    Enumerator.new do |yielder|
      @dirs.each do |dir|
        scan_dir("", dir, yielder)
      end
    end
  end

private

  def scan_dir(path, root_path, yielder)
    Dir.foreach("#{root_path}/#{path}") do |file|
      next if file == "." || file == ".."
      file_path = "#{path}"
      file_path << "/" unless file_path.empty?
      file_path << file

      full_path = "#{root_path}/#{file_path}"
      ext = File.extname(file_path)

      if File.directory?(full_path)
        scan_dir(file_path, root_path, yielder)
      elsif ext == ".erb" || ext == ".haml"
        yielder << AwesomeTranslations::ErbInspector::FileInspector.new(
          file_path: file_path,
          root_path: root_path
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
awesome_translations-0.0.4 lib/awesome_translations/erb_inspector.rb
awesome_translations-0.0.3 lib/awesome_translations/erb_inspector.rb
awesome_translations-0.0.2 lib/awesome_translations/erb_inspector.rb