KMQToolKitGem 0.1.0 → 0.2.0

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: c5352c3f79c80929eef89773c0766314eaec0a01
4
- data.tar.gz: f341741164d2584ad54c6deec511574dbd5f17c0
3
+ metadata.gz: ab99c279f432ce664950842eb51f94f3553f0999
4
+ data.tar.gz: bf4558127b9a6e68087211dc5333f11f682f497a
5
5
  SHA512:
6
- metadata.gz: 9afb54d8846f530d84d998993d4bd072d7ebcce41269ab5ea7305869ffb42dbb2a0976de4ea2a0b62fc841fbda8b9fbc1f660b0635603c077152082f6a2c408d
7
- data.tar.gz: 9c1a8293727ac9890352184c95658610a30dd5133b739a1746c3a59287c7d08714505d3b0fb82e1a50361393021cbb8c849c8c7f42497a74795a1dcfc26e312e
6
+ metadata.gz: 2963329ca86df4129149c3b8ceab262527f2b95d90a5ddd1436addf55d37978f99214f2962ebaa5b513f4590249e343f68d2bed7d94a1a2f7efb24c40212e482
7
+ data.tar.gz: 203fc7a266150edd0ed9d4b8873042cfaf2698f69048f16d612b0b6d12891a15b7cda8462a92b804f24fbdf68d758ad9d1f7c58048fe3fd55dedd447a48e5ea7
@@ -1,6 +1,7 @@
1
1
  require 'thor'
2
2
  require 'plist'
3
3
  require_relative 'error_plist_generator'
4
+ require_relative 'color_plist_generator'
4
5
 
5
6
  module KMQToolKitCodeGen
6
7
 
@@ -28,9 +29,15 @@ module KMQToolKitCodeGen
28
29
  # Color plist code generation
29
30
  # ---------------------------
30
31
  desc "colorgen PLIST", "This will generate files based on provided color plist"
31
- method_options :prefix => :string, :path => :string
32
+ method_options :prefix => :string, :path => :string, :key => :string
32
33
  def colorgen(plist)
33
- puts "Hello World"
34
+ prefix = options[:prefix] || ""
35
+ base_path = options[:path] || "./"
36
+ plist_key = options[:key] || ""
37
+ plist_hash = plist_key.split(".").inject(Plist::parse_xml(plist)) { |hash, key| hash[key] }
38
+
39
+ generator = ColorPlistGenerator.new plist_hash, prefix, base_path
40
+ generator.generate_color_names
34
41
  end
35
42
 
36
43
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'helper'
2
+ require 'ostruct'
3
+
4
+ class ColorPlistGenerator
5
+ attr_reader :plist_hash, :prefix, :base_path
6
+
7
+ def initialize(plist_hash, prefix, base_path)
8
+ @plist_hash = plist_hash
9
+ @prefix = prefix
10
+ @base_path = base_path
11
+ check
12
+ end
13
+
14
+ def generate_color_names
15
+ color_names = @plist_hash.keys.collect do |name|
16
+ name.slice(0, 1).capitalize + name.slice(1..-1)
17
+ end
18
+ create_color_name_file(color_names, 'h')
19
+ create_color_name_file(color_names, 'm')
20
+ end
21
+
22
+ def create_color_name_file(names, type)
23
+ file_name = "UIColor+#{@prefix}ColorName.#{type}"
24
+ template_path = "#{Dir.pwd}/templates/UIColor+ColorName.#{type}.erb"
25
+ absolute_file_path = "#{@base_path}/#{file_name}"
26
+ variables = OpenStruct.new(names: names, prefix: @prefix)
27
+ Helper.write_to_file(absolute_file_path, template_path, variables.instance_eval{ binding })
28
+ end
29
+
30
+ def check
31
+ if !@plist_hash.is_a?(Hash)
32
+ raise RuntimeError, "Invalid plist format"
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module KMQToolKitGem
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>colors</key>
6
+ <dict>
7
+ <key>sampleColor2</key>
8
+ <dict>
9
+ <key>color</key>
10
+ <string>#cccccc</string>
11
+ <key>alpha</key>
12
+ <integer>200</integer>
13
+ </dict>
14
+ <key>sampleColor1</key>
15
+ <string>#000000</string>
16
+ </dict>
17
+ </dict>
18
+ </plist>
@@ -0,0 +1,7 @@
1
+ #import <UIKit/UIKit.h>
2
+ <% names.each do |name| %>
3
+ extern NSString *const <%= prefix %>Color<%= name %>;
4
+ <% end %>
5
+ @interface UIColor (<%= prefix %>ColorName)
6
+
7
+ @end
@@ -0,0 +1,7 @@
1
+ #import "UIColor+<%= prefix %>ColorName.h"
2
+ <% names.each do |name| %>
3
+ NSString *const <%= prefix %>Color<%= name %> = @"<%= name %>";
4
+ <% end %>
5
+ @implementation UIColor (<%= prefix %>ColorName)
6
+
7
+ @end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: KMQToolKitGem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weinan Qiu
@@ -102,14 +102,18 @@ files:
102
102
  - bin/setup
103
103
  - lib/KMQToolKitGem.rb
104
104
  - lib/KMQToolKitGem/cli.rb
105
+ - lib/KMQToolKitGem/color_plist_generator.rb
105
106
  - lib/KMQToolKitGem/error_plist_generator.rb
106
107
  - lib/KMQToolKitGem/helper.rb
107
108
  - lib/KMQToolKitGem/version.rb
109
+ - sample/colors.plist
108
110
  - sample/errors.plist
109
111
  - templates/NSError+ErrorCode.h.erb
110
112
  - templates/NSError+ErrorCode.m.erb
111
113
  - templates/NSError+ErrorDomain.h.erb
112
114
  - templates/NSError+ErrorDomain.m.erb
115
+ - templates/UIColor+ColorName.h.erb
116
+ - templates/UIColor+ColorName.m.erb
113
117
  homepage: https://github.com/davidiamyou/KMQToolKitGem
114
118
  licenses:
115
119
  - MIT