Class: Locraft::SwiftConstantsGenerator

Inherits:
ConstantsGenerator show all
Defined in:
lib/locraft/generators/swift_constants_generator.rb

Instance Method Summary collapse

Methods inherited from ConstantsGenerator

#constants_keys, #files_header, #files_name, #initialize, #resource_file, #write_file_content

Constructor Details

This class inherits a constructor from Locraft::ConstantsGenerator

Instance Method Details

#const_templateObject



18
19
20
21
22
23
24
# File 'lib/locraft/generators/swift_constants_generator.rb', line 18

def const_template
  <<EOF
static var %{const}: String {
    return localized("%{key}")
}
EOF
end

#constant_from(key) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/locraft/generators/swift_constants_generator.rb', line 26

def constant_from(key)
  parts = key.split(/\W/).select { |p| !p.empty? }
  parts.map! do |p|
    p[0] = p[0].capitalize if p != parts[0]
    p
  end
  parts.join
end

#fileObject



13
14
15
16
# File 'lib/locraft/generators/swift_constants_generator.rb', line 13

def file
  content = constants_keys.map { |d| const_template % d }.join("\n")
  resource_file('swift_macro_template.txt') % content
end

#generateObject



5
6
7
8
9
10
# File 'lib/locraft/generators/swift_constants_generator.rb', line 5

def generate
  destination_dir = @config.relative_macro_destination
  mkdir_p destination_dir unless Dir.exist?(destination_dir)
  write_file_content("#{destination_dir}/#{files_name}.swift", file)
  puts 'constants files was created for [swift] language'
end