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_with, #files_header, #files_name, #write_file_content
Methods inherited from Generator
#initialize
Instance Method Details
#constant_from(key) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 32
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(localizations_hash) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 12
def generate(localizations_hash)
localizations = localizations_hash[@config.default_lang]
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(localizations))
write_file_content("#{destination_dir}/#{files_name}.m", m_file(localizations))
puts 'constants files was created for [objc] language'
end
|
#h_file(localizations) ⇒ Object
27
28
29
30
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 27
def h_file(localizations)
content = constants_keys_with(localizations).map { |d| OBJC_CONST_TEMPLATE_H % d }.join("\n")
Utils.resource_file('objc_h_macro_template.txt') % content
end
|
#m_file(localizations) ⇒ Object
21
22
23
24
25
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 21
def m_file(localizations)
content = %(#import "#{files_name}.h"\n\n)
content += constants_keys_with(localizations).map { |d| OBJC_CONST_TEMPLATE_M % d }.join("\n")
Utils.resource_file('objc_m_macro_template.txt') % content
end
|
#valid? ⇒ Boolean
8
9
10
|
# File 'lib/locraft/generators/objc_constants_generator.rb', line 8
def valid?
!@config.relative_macro_destination.nil?
end
|