locraft 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 585cc878bec06aabeb780f92d6fdd1fabb16daf0
4
- data.tar.gz: 6589e550e52cbb96f59b79e35af0928a11fdeb94
3
+ metadata.gz: bdf343f6f36939651039593e5dfb560ac7c9ec59
4
+ data.tar.gz: 7c005f83fb385fc1b14374d9e8737b76bd7380f0
5
5
  SHA512:
6
- metadata.gz: 4fcc07735e43f7ffd3e2ded9ea69b817b9e1d088cfaf78b5817710862665b9023aa03a127818809e0a8fad7065d222a9eba6790a02765133c1e186f39fd274f0
7
- data.tar.gz: 1026ace142c16d6f13621f584ba3b28107cc1f3f329fb7ca8fe9451cc1bccc923153a9421ba8fdfb78d54225d52146d82779a0fb1533e395cbddbed751213f35
6
+ metadata.gz: e23ce904dd832c5047e931708f9b3d0123f2a7852252634236724bc566645f9619cdd617a3c69bfba5f22b77bbe7e20ab4894ab56f09d3f9d5a4ec31331dbabe
7
+ data.tar.gz: 9bcb8f395b64df18c6270c12f4fb169d6c34419503095dbad02b6346be5095a4e1d0f4df64005e50635939221eb3011325b7296968f652573f147ca1627065c3
@@ -1,7 +1,7 @@
1
1
  module Locraft
2
- STRINGS_EXTENSION = '.strings'
3
- SWIFT = 'swift'
4
- OBJC = 'objc'
2
+ STRINGS_EXTENSION = '.strings'.freeze
3
+ SWIFT = 'swift'.freeze
4
+ OBJC = 'objc'.freeze
5
5
 
6
6
  class Config
7
7
  attr_accessor :langs
@@ -22,7 +22,7 @@ module Locraft
22
22
 
23
23
  # fill automatically in load_from method
24
24
  attr_accessor :from_file
25
-
25
+
26
26
  def initialize
27
27
  self.default_lang = 'English'
28
28
  self.gdoc_sheet = 0
@@ -1,8 +1,8 @@
1
1
  require_relative 'config'
2
2
  require_relative 'csv_parser'
3
- require_relative 'info_plist_generator'
4
- require_relative 'constants_generator'
5
- require_relative 'strings_generator'
3
+ require_relative 'generators/info_plist_generator'
4
+ require_relative 'generators/constants_generator'
5
+ require_relative 'generators/strings_generator'
6
6
  require_relative 'google_drive_wrapper'
7
7
 
8
8
  module Locraft
@@ -34,7 +34,11 @@ module Locraft
34
34
 
35
35
  def generate_constant(localizations_hash)
36
36
  localizations = localizations_hash[@config.default_lang]
37
- ConstantsGenerator.new(@config, localizations).generate
37
+ if @config.dev_lang.equal? OBJC
38
+ ObjcConstantsGenerator.new(@config, localizations).generate
39
+ else
40
+ SwiftConstantsGenerator.new(@config, localizations).generate
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -0,0 +1,46 @@
1
+ require_relative '../config'
2
+ require 'fileutils'
3
+
4
+ module Locraft
5
+ class ConstantsGenerator
6
+ include FileUtils
7
+
8
+ def initialize(config, localizations)
9
+ @config = config
10
+ @localizations = localizations
11
+ end
12
+
13
+ def generate
14
+ raise NotImplementedError
15
+ end
16
+
17
+ def write_file_content(file, content)
18
+ File.open(file, 'w+') do |f|
19
+ f.puts files_header + "\n"
20
+ f.puts content
21
+ end
22
+ end
23
+
24
+ def files_name
25
+ @config.dev_prefix + @config.macro_file
26
+ end
27
+
28
+ def constants_keys
29
+ @localizations.select(&:valid?).map do |l|
30
+ { key: l.key, const: constant_from(l.key) }
31
+ end
32
+ end
33
+
34
+ def constant_from(_key)
35
+ raise NotImplementedError
36
+ end
37
+
38
+ def files_header
39
+ resource_file('macro_files_header.txt')
40
+ end
41
+
42
+ def resource_file(file)
43
+ File.read(File.expand_path("../../resources/#{file}", __FILE__))
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
- require_relative 'config'
2
- require_relative 'localization'
1
+ require_relative '../config'
2
+ require_relative '../localization'
3
3
  require 'fileutils'
4
4
 
5
5
  module Locraft
@@ -0,0 +1,35 @@
1
+ require_relative 'constants_generator'
2
+
3
+ module Locraft
4
+ class ObjcConstantsGenerator < ConstantsGenerator
5
+ OBJC_CONST_TEMPLATE_H = 'extern NSString *const __nonnull %{const};'.freeze
6
+ OBJC_CONST_TEMPLATE_M = 'NSString *const %{const} = @"%{key}";'.freeze
7
+
8
+ def generate
9
+ destination_dir = @config.relative_macro_destination
10
+ mkdir_p destination_dir unless Dir.exist?(destination_dir)
11
+ write_file_content("#{destination_dir}/#{files_name}.h", h_file)
12
+ write_file_content("#{destination_dir}/#{files_name}.m", m_file)
13
+ puts 'constants files was created for [objc] language'
14
+ end
15
+
16
+ def m_file
17
+ content = %(#import "#{files_name}.h"\n\n)
18
+ content += constants_keys.map { |d| OBJC_CONST_TEMPLATE_M % d }.join("\n")
19
+ resource_file('objc_m_macro_template.txt') % content
20
+ end
21
+
22
+ def h_file
23
+ content = constants_keys.map { |d| OBJC_CONST_TEMPLATE_H % d }.join("\n")
24
+ resource_file('objc_h_macro_template.txt') % content
25
+ end
26
+
27
+ def constant_from(key)
28
+ parts = key.split(/\W/).select { |p| !p.empty? }.map do |p|
29
+ p[0] = p[0].capitalize
30
+ p
31
+ end
32
+ "k#{@config.dev_prefix}#{parts.join}Localized"
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
- require_relative 'config'
2
- require_relative 'localization'
1
+ require_relative '../config'
2
+ require_relative '../localization'
3
3
  require 'fileutils'
4
4
 
5
5
  module Locraft
@@ -25,7 +25,7 @@ module Locraft
25
25
  end
26
26
 
27
27
  def strings_file_with(localizations)
28
- localizations.select { |l| l.valid? }.map(&:to_line).join("\n")
28
+ localizations.select(&:valid?).map(&:to_line).join("\n")
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'constants_generator'
2
+
3
+ module Locraft
4
+ class SwiftConstantsGenerator < ConstantsGenerator
5
+ def generate
6
+ destination_dir = @config.relative_macro_destination
7
+ mkdir_p destination_dir unless Dir.exist?(destination_dir)
8
+ write_file_content("#{destination_dir}/#{files_name}.swift", file)
9
+ puts 'constants files was created for [swift] language'
10
+ end
11
+
12
+
13
+ def file
14
+ content = constants_keys.map { |d| const_template % d }.join("\n")
15
+ resource_file('swift_macro_template.txt') % content
16
+ end
17
+
18
+ def const_template
19
+ <<EOF
20
+ static var %{const}: String {
21
+ return localized("%{key}")
22
+ }
23
+ EOF
24
+ end
25
+
26
+ def constant_from(key)
27
+ parts = key.split(/\W/).select { |p| !p.empty? }
28
+ parts.map! do |p|
29
+ p[0] = p[0].capitalize if p != parts[0]
30
+ p
31
+ end
32
+ parts.join
33
+ end
34
+ end
35
+ end
@@ -1,7 +1,7 @@
1
1
  module Locraft
2
2
 
3
- SAMPLE_CONFIG_DIR = 'locraft'
4
- SAMPLE_CONFIG_FILE = 'locraft.config'
3
+ SAMPLE_CONFIG_DIR = 'locraft'.freeze
4
+ SAMPLE_CONFIG_FILE = 'locraft.config'.freeze
5
5
 
6
6
  class Initializer
7
7
  def self.init
@@ -10,7 +10,7 @@ module Locraft
10
10
  warn 'ERROR: Initialization failed. There is already exists some locraft.config.'
11
11
  else
12
12
  Dir.mkdir(SAMPLE_CONFIG_DIR) unless Dir.exist?(SAMPLE_CONFIG_DIR)
13
- File.write(SAMPLE_CONFIG_FILE, config)
13
+ File.write(File.join(SAMPLE_CONFIG_DIR, SAMPLE_CONFIG_FILE), config)
14
14
  end
15
15
  end
16
16
 
@@ -0,0 +1,3 @@
1
+ @import Foundation;
2
+
3
+ %s
@@ -8,20 +8,26 @@ Locraft::Config.new do |conf|
8
8
  # @!optional
9
9
  ############
10
10
  conf.langs = {
11
- 'English' => 'en',
12
- 'Russian' => 'ru'
11
+ 'English' => 'en',
12
+ 'Russian' => 'ru'
13
13
  } # default: { 'English' => 'en', 'Russian' => 'ru' }
14
14
  conf.default_lang = 'English' # default: 'English'
15
15
  conf.gdoc_sheet = 0 # default: 0
16
16
  conf.gdoc_keys_column = 'Keys' # default: 'Keys'
17
17
  conf.gdoc_comments_column = 'Comments' # default: 'Comments'
18
- conf.dev_lang = OBJC # OBJC or SWIFT, default: OBJC
18
+ conf.dev_lang = SWIFT # OBJC or SWIFT, default: SWIFT
19
19
  conf.dev_prefix = 'XYZ' # default: 'XYZ'
20
20
  conf.keys_map = {}
21
21
  conf.macro_file = 'LocalizedConstants' # default: 'LocalizedConstants'
22
22
  conf.macro_destination = './' # default: './'
23
+
24
+ # strings destination directory
25
+ # related to this file, default: './Localizations'
26
+ conf.strings_destination = './Localizations'
23
27
  conf.strings_basename = 'Localizable' # default: 'Localizable'
24
- conf.strings_destination = './Localizations' # strings destination directory related to this file, default: './Localizations'
28
+
29
+ # info plist destination directory
30
+ # related to this file, default: './Localizations'
31
+ conf.info_plist_destination = './Localizations'
25
32
  conf.info_plist_basename = 'InfoPlist' # default: 'InfoPlist'
26
- conf.info_plist_destination = './Localizations' # info plist destination directory related to this file, default: './Localizations'
27
33
  end
@@ -0,0 +1,10 @@
1
+ import Foundation
2
+
3
+ struct Localized {
4
+ private static func localized(_ key: String, comment: String = "") -> String {
5
+ return NSLocalizedString(key, comment: comment)
6
+ }
7
+
8
+ %s
9
+ }
10
+
data/lib/locraft.rb CHANGED
@@ -3,6 +3,8 @@ require_relative 'locraft/localization'
3
3
  require_relative 'locraft/initializer'
4
4
  require_relative 'locraft/runner'
5
5
  require_relative 'locraft/extractor'
6
- require_relative 'locraft/info_plist_generator'
7
- require_relative 'locraft/constants_generator'
8
- require_relative 'locraft/strings_generator'
6
+ require_relative 'locraft/generators/info_plist_generator'
7
+ require_relative 'locraft/generators/constants_generator'
8
+ require_relative 'locraft/generators/swift_constants_generator'
9
+ require_relative 'locraft/generators/objc_constants_generator'
10
+ require_relative 'locraft/generators/strings_generator'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sroik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -91,17 +91,22 @@ files:
91
91
  - bin/locraft
92
92
  - lib/locraft.rb
93
93
  - lib/locraft/config.rb
94
- - lib/locraft/constants_generator.rb
95
94
  - lib/locraft/csv_parser.rb
96
95
  - lib/locraft/extractor.rb
96
+ - lib/locraft/generators/constants_generator.rb
97
+ - lib/locraft/generators/info_plist_generator.rb
98
+ - lib/locraft/generators/objc_constants_generator.rb
99
+ - lib/locraft/generators/strings_generator.rb
100
+ - lib/locraft/generators/swift_constants_generator.rb
97
101
  - lib/locraft/google_drive_wrapper.rb
98
- - lib/locraft/info_plist_generator.rb
99
102
  - lib/locraft/initializer.rb
100
103
  - lib/locraft/localization.rb
101
- - lib/locraft/resources/constants_files_header.txt
104
+ - lib/locraft/resources/macro_files_header.txt
105
+ - lib/locraft/resources/objc_h_macro_template.txt
106
+ - lib/locraft/resources/objc_m_macro_template.txt
102
107
  - lib/locraft/resources/sample_locraft.config
108
+ - lib/locraft/resources/swift_macro_template.txt
103
109
  - lib/locraft/runner.rb
104
- - lib/locraft/strings_generator.rb
105
110
  homepage: https://github.com/app-craft/locraft
106
111
  licenses:
107
112
  - MIT
@@ -122,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
127
  version: '0'
123
128
  requirements: []
124
129
  rubyforge_project:
125
- rubygems_version: 2.6.10
130
+ rubygems_version: 2.6.11
126
131
  signing_key:
127
132
  specification_version: 4
128
133
  summary: locraft
@@ -1,73 +0,0 @@
1
- require_relative 'config'
2
- require 'fileutils'
3
-
4
- module Locraft
5
- class ConstantsGenerator
6
- include FileUtils
7
-
8
- OBJC_CONST_TEMPLATE_H = 'extern NSString *const __nonnull %{const};'
9
- OBJC_CONST_TEMPLATE_M = 'NSString *const %{const} = @"%{key}";'
10
- SWIFT_CONST_TEMPLATE = 'let %{const}: String = "%{key}"'
11
-
12
- def initialize(config, localizations)
13
- @config = config
14
- @localizations = localizations
15
- end
16
-
17
- def generate
18
- destination_dir = @config.relative_macro_destination
19
- mkdir_p destination_dir unless Dir.exist?(destination_dir)
20
- if @config.dev_lang.equal?(OBJC)
21
- write_to("#{destination_dir}/#{files_name}.h", h_file)
22
- write_to("#{destination_dir}/#{files_name}.m", m_file)
23
- else
24
- write_to("#{destination_dir}/#{files_name}.swift", swift_file)
25
- end
26
- puts "constants files was created for [#{@config.dev_lang}] language"
27
- end
28
-
29
- def write_to(file, content)
30
- File.open(file, 'w+') do |f|
31
- f.puts files_header + "\n"
32
- f.puts content
33
- end
34
- end
35
-
36
- def files_header
37
- File.read(File.expand_path('../resources/constants_files_header.txt', __FILE__))
38
- end
39
-
40
- def files_name
41
- @config.dev_prefix + @config.macro_file
42
- end
43
-
44
- def m_file
45
- file = %(#import "#{files_name}.h"\n)
46
- file + constants_keys.map { |d| OBJC_CONST_TEMPLATE_M % d }.join("\n")
47
- end
48
-
49
- def h_file
50
- file = "@import Foundation;\n"
51
- file + constants_keys.map { |d| OBJC_CONST_TEMPLATE_H % d }.join("\n")
52
- end
53
-
54
- def swift_file
55
- file = "import Foundation\n"
56
- file + constants_keys.map { |d| SWIFT_CONST_TEMPLATE % d }.join("\n")
57
- end
58
-
59
- def constants_keys
60
- @localizations.select(&:valid?).map do |l|
61
- { key: l.key, const: constant_from(l.key) }
62
- end
63
- end
64
-
65
- def constant_from(key)
66
- parts = key.split(/\W/).select { |p| !p.empty? }.map do |p|
67
- p[0] = p[0].capitalize
68
- p
69
- end
70
- "k#{@config.dev_prefix}#{parts.join}Localized"
71
- end
72
- end
73
- end