Class: Locraft::SwiftConstantsGenerator
Instance Method Summary
collapse
#constants_keys, #files_header, #files_name, #initialize, #resource_file, #write_file_content
Instance Method Details
#const_template ⇒ Object
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
|
#file ⇒ Object
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
|
#generate ⇒ Object
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
|