xcmultilingual 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64cef45b2ed34b83b9d27a5b275016bebea677ae
4
- data.tar.gz: 7b79f35464e520cd309dc9008f1da898bc631e9f
3
+ metadata.gz: 80dd2cbcb739918e3734f51840bf3b0164a58ce8
4
+ data.tar.gz: e1becbf16ff9b941cf28b31c56f9ce9295760669
5
5
  SHA512:
6
- metadata.gz: bdbeb8630fcfd7d08374158fa7cd243e31783e79207d79be1201a55eb9bd2e189dfed794bd1a6fd27ed951046152356f9aedfe68274f20365261d60d188566da
7
- data.tar.gz: 26e1c30196de411d1501c28fb104ae072e147d051e13e8a51a7e9e5c1c018fa79edaf0ccaf356785a4ace28840b3c4034cbddbec3aac41409921213f50304685
6
+ metadata.gz: 987a6e66a6b0dbb402adcfc3a1fa2d6d5c2a80dd22ca067f8efdf208e051bddca39397224bfc84bea309ab75d6663ab9ea84adcf957bf88b4d5ec4c16841a025
7
+ data.tar.gz: 66b8bc6153b88c37565b9f6e10693b6b96a7add952e16605dc1e06293f322d1bd334811ca66c2d798d1d6164a2335cd1d3af951e96271994c9d48f3c141765df
@@ -2,7 +2,7 @@
2
2
  // Multilingual.swift
3
3
  // xcmultilingual
4
4
  //
5
- // Created by xcmultilingual on 2015-07-12 19:40:59 +0900.
5
+ // Created by xcmultilingual.
6
6
  //
7
7
  //
8
8
 
@@ -0,0 +1,44 @@
1
+ //
2
+ // <%= @filename %>
3
+ // xcmultilingual - Custom
4
+ //
5
+ // Created by xcmultilingual.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct <%= @name %> {
12
+ <% @bundle_data.each do |bundle| -%>
13
+ <% nsbundle = bundle.name ? "Multilingual.bundle(\"#{bundle.relative_path}\")" : "NSBundle.mainBundle()" -%>
14
+ <% bundle_name = bundle.name.nil? ? "" : bundle.name.capitalize -%>
15
+ <% bundle.tables.each do |table| -%>
16
+ <% class_name = bundle_name + table.name -%>
17
+ enum <%= class_name %>: String {
18
+ <% table.keys.each do |key| -%>
19
+ case <%= key %> = "<%= key %>"
20
+ <% end # keys -%>
21
+
22
+ func string() -> String {
23
+ return NSLocalizedString(rawValue, tableName: "<%= table.name %>", bundle: <%= nsbundle %>, value: "\(rawValue)", comment: "")
24
+ }
25
+
26
+ static func keys() -> [String] {
27
+ return ["<%= table.keys.join("\", \"") %>"]
28
+ }
29
+
30
+ static func localizations() -> [String] {
31
+ return <%= class_name %>.keys().map { <%= class_name %>(rawValue: $0)!.string() }
32
+ }
33
+ }
34
+
35
+ <%- end # table -%>
36
+ <%- end # bundle -%>
37
+
38
+ private static func bundle(relativePath: String) -> NSBundle {
39
+ var components = (__FILE__ as String).pathComponents
40
+ components.removeLast()
41
+ let bundlePath = join("/", components) + "/" + relativePath
42
+ return NSBundle(path: bundlePath) ?? NSBundle.mainBundle()
43
+ }
44
+ }
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xcmultilingual (0.1.1)
4
+ xcmultilingual (0.1.2)
5
5
  thor
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -137,6 +137,7 @@ Easy!
137
137
 
138
138
  options:
139
139
  - `-name` or `-n`: Change Localization struct name. Default is Multilingual.
140
+ - `-template` or `-t`: Use custom template for generating swift file. You can copy original and change where you want!
140
141
  - `--verbose`: Output execution logs
141
142
 
142
143
  **help:** Write `update` after help and show update options' help.
@@ -7,8 +7,8 @@ module Xcmultilingual
7
7
  class_option :verbose, :type => :boolean
8
8
 
9
9
  desc "update DESTINATION", "update xcmultilingual swift file"
10
- # option :destination, :aliases => "-d", :required => true, :desc => "generating file destination"
11
10
  option :name, :aliases => "-n", :default => "Multilingual", :desc => "Localization struct name"
11
+ option :template_path, :aliases => "-t", :desc => "User generated template file path"
12
12
  def update(destination)
13
13
  parser = Parser.new(destination)
14
14
  parser.verbose = options[:verbose] || false
@@ -16,6 +16,7 @@ module Xcmultilingual
16
16
 
17
17
  writer = Writer.new(destination, bundle_data)
18
18
  writer.name = options[:name]
19
+ writer.template_path = options[:template_path] if options[:template_path]
19
20
  writer.verbose = options[:verbose] || false
20
21
  writer.write
21
22
 
@@ -1,3 +1,3 @@
1
1
  module Xcmultilingual
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -2,11 +2,12 @@ require 'erb'
2
2
 
3
3
  module Xcmultilingual
4
4
  class Writer
5
- attr_accessor :name, :verbose
5
+ attr_accessor :name, :template_path, :verbose
6
6
 
7
7
  def initialize(destination, bundle_data)
8
8
  @destination = destination
9
9
  @bundle_data = bundle_data
10
+ @template_path = template_path()
10
11
  @filename = File.basename(@destination)
11
12
  end
12
13
 
@@ -20,8 +21,8 @@ module Xcmultilingual
20
21
  end
21
22
 
22
23
  File.open("#{@destination}", "w") do |file|
23
- template_file = templates_file(default_templates_dir)
24
- body = ERB.new(File.open(template_file).read, nil, '-').result(binding)
24
+ path = File.expand_path(@template_path)
25
+ body = ERB.new(File.open(path).read, nil, '-').result(binding)
25
26
  file.write(body)
26
27
  end
27
28
  puts "+ END UPDATING\n\n" if @verbose
@@ -29,12 +30,8 @@ module Xcmultilingual
29
30
 
30
31
  private
31
32
 
32
- def default_templates_dir
33
- File.dirname(__FILE__) + '/templates'
34
- end
35
-
36
- def templates_file(dir)
37
- dir + "/swift.erb"
33
+ def template_path()
34
+ File.dirname(__FILE__) + '/templates/swift.erb'
38
35
  end
39
36
  end
40
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcmultilingual
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoki Morita
@@ -177,6 +177,7 @@ files:
177
177
  - DemoApp/Pods/Target Support Files/Pods/Pods.debug.xcconfig
178
178
  - DemoApp/Pods/Target Support Files/Pods/Pods.modulemap
179
179
  - DemoApp/Pods/Target Support Files/Pods/Pods.release.xcconfig
180
+ - DemoApp/custom_template.erb
180
181
  - Gemfile
181
182
  - Gemfile.lock
182
183
  - LICENSE