Class: AwesomeTranslations::Handlers::FileHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/awesome_translations/handlers/file_handler.rb

Instance Method Summary collapse

Methods inherited from BaseHandler

#add_translations_for_hash, #enabled?, #translations_for_hash_recursive

Instance Method Details

#groupsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/awesome_translations/handlers/file_handler.rb', line 2

def groups
  ArrayEnumerator.new do |yielder|
    erb_inspector.files.each do |file|
      id = file.file_path.gsub(/[^A-z0-9]/, "_")

      group = AwesomeTranslations::Group.new(
        id: id,
        handler: self,
        data: {
          name: file.file_path,
          root_path: file.root_path,
          full_path: file.full_path,
          file_path: file.file_path
        }
      )

      yielder << group if translations_for_group(group).any?
    end
  end
end

#translations_for_group(group) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/awesome_translations/handlers/file_handler.rb', line 23

def translations_for_group(group)
  ArrayEnumerator.new do |yielder|
    translations_found = {}

    file = erb_inspector.file(group.data.fetch(:root_path), group.data.fetch(:file_path))
    file.translations.each do |translation|
      next if translations_found.key?(translation.full_key)

      translations_found[translation.full_key] = true
      yielder << translation.model
    end
  end
end