Class: Locraft::ObjcConstantsGenerator
Constant Summary
collapse
- OBJC_CONST_TEMPLATE_H =
'extern NSString *const __nonnull %<const>s;'.freeze
- OBJC_CONST_TEMPLATE_M =
'NSString *const %<const>s = @"%<key>s";'.freeze
Instance Method Summary
collapse
#constants_keys, #files_header, #files_name, #initialize, #resource_file, #write_file_content
Instance Method Details
#constant_from(key) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 27
def constant_from(key)
parts = key.split(/\W/).reject(&:empty?).map do |p|
p[0] = p[0].capitalize
p
end
"k#{@config.dev_prefix}#{parts.join}Localized"
end
|
#generate ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 8
def generate
destination_dir = @config.relative_macro_destination
mkdir_p destination_dir unless Dir.exist?(destination_dir)
write_file_content("#{destination_dir}/#{files_name}.h", h_file)
write_file_content("#{destination_dir}/#{files_name}.m", m_file)
puts 'constants files was created for [objc] language'
end
|
#h_file ⇒ Object
22
23
24
25
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 22
def h_file
content = constants_keys.map { |d| OBJC_CONST_TEMPLATE_H % d }.join("\n")
resource_file('objc_h_macro_template.txt') % content
end
|
#m_file ⇒ Object
16
17
18
19
20
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 16
def m_file
content = %(#import "#{files_name}.h"\n\n)
content += constants_keys.map { |d| OBJC_CONST_TEMPLATE_M % d }.join("\n")
resource_file('objc_m_macro_template.txt') % content
end
|