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



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

def const_template
  "static var %<const>s: String {\n    return localized(\"%<key>s\")\n}\n"
end

#constant_from(key) ⇒ Object



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

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

#fileObject



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

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