hemera 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 16fdb9e56405f23e529e4a8138f7acc39b78e91811f76b7902ed41ac13bca1dc
4
- data.tar.gz: 5d309219ec3c3020dfcc042acb3305de848dc0a2a03b0d800df4a00955f84632
3
+ metadata.gz: 74c81fc14b8105c9152c240b0fd1a86789aa5a98323cc6927567787096db32a5
4
+ data.tar.gz: ca196b1b0c7048a12bff91511a5a92d9c0e22fdc6a5d627d06bccd153440ccc3
5
5
  SHA512:
6
- metadata.gz: 6e860a3aaeeb5e6ec563c02553ce65b6cb0d3447eac19f3a2754ba86e8ddb1179bb37d1b877e22203a86680bb69812e10687c9e57fb30477fdae07ba7b738ec8
7
- data.tar.gz: 3a321f2afe973a6bd91aff2c1931c496078d8ec12f5bfaa4228597782600e50c7619367fd9e9a0008a46d23ee9e5b708f2d0a0fbee8f486659872a0087b2d656
6
+ metadata.gz: a6ad4566d9f99d7ac4b6c20b7127a36b87c1eacf19f84aecdf58528a681b2c659d82264d1f2a736c20ec7fc78c54d44d142086989fbee4832a8d9bc68a6aee59
7
+ data.tar.gz: 0bc05792d9f0149db8c9b3cf97073a340a4d8e007e389603cc5faf63932dd28d4928b0450a824a849d82c85724443e5e034e6c99bd929b116b884058ca560d24
@@ -3,6 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5.1
5
5
  before_install:
6
- - gem install bundler -v 1.16.1
6
+ - gem install bundler
7
7
  script:
8
8
  - bundle exec rake
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hemera (0.4.0)
4
+ hemera (0.5.0)
5
5
  gli (~> 2.18)
6
6
 
7
7
  GEM
@@ -112,4 +112,4 @@ DEPENDENCIES
112
112
  rspec (~> 3.0)
113
113
 
114
114
  BUNDLED WITH
115
- 1.17.1
115
+ 1.17.2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Hemera
2
2
 
3
3
  [![contact us](https://img.shields.io/discord/490015137181466645.svg)](https://discordapp.com/invite/RF2rWZ)
4
+ [![Gem Version](https://badge.fury.io/rb/hemera.svg)](https://badge.fury.io/rb/hemera)
4
5
  [![Build Status](https://travis-ci.org/JianweiWangs/Hemera.svg?branch=master)](https://travis-ci.org/JianweiWangs/Hemera)
5
6
  [![codecov](https://codecov.io/gh/JianweiWangs/Hemera/branch/master/graph/badge.svg)](https://codecov.io/gh/JianweiWangs/Hemera)
6
7
 
@@ -55,7 +56,7 @@ SYNOPSIS
55
56
  COMMANDS
56
57
  img, i - generate img code
57
58
  ```
58
- ![command_meta](resource/meta_command.gif)
59
+ ![command_meta](resource_md/meta_command.gif)
59
60
 
60
61
  use xcode subcommand can open/clean workspace
61
62
 
@@ -21,6 +21,8 @@ module Hemera
21
21
  @class_name = output_file_name
22
22
  @path = path
23
23
  @images = image_model_of_names
24
+ @bundle = path[/[A-Z, a-z, 0-9]+(?=\.bundle)/]
25
+ @bundle_path = path.gsub(@bundle + '.bundle', '') if @bundle
24
26
  end
25
27
 
26
28
  def find_paths_of_png(path = @path)
@@ -52,18 +54,17 @@ module Hemera
52
54
  end
53
55
 
54
56
  def generate(is_swift = true)
55
- puts 'generating 😊'
56
57
  if is_swift
57
- swift_file_path = @path + '/' + @class_name + '.swift'
58
+ swift_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.swift'
58
59
  puts " #{swift_file_path} generating!"
59
60
  File.open(swift_file_path, 'w') do |f|
60
- f.puts SwiftImageGenerator.new(@class_name, @images).swift_file
61
+ f.puts SwiftImageGenerator.new(@class_name, @images, @bundle).swift_file
61
62
  end
62
63
  else
63
- interface_file_path = @path + '/' + @class_name + '.h'
64
- implementent_file_path = @path + '/' + @class_name + '.m'
64
+ interface_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.h'
65
+ implementent_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.m'
65
66
  puts " #{interface_file_path} and #{implementent_file_path} generating!"
66
- objc_image_generator = ObjCImageGenerator.new(@class_name, @images)
67
+ objc_image_generator = ObjCImageGenerator.new(@class_name, @images, @bundle)
67
68
  File.open(interface_file_path, 'w') do |f|
68
69
  f.puts objc_image_generator.interface_file
69
70
  end
@@ -2,9 +2,10 @@ require 'erb'
2
2
  module Hemera
3
3
  module Generator
4
4
  class ObjCImageGenerator
5
- def initialize(class_name, images)
5
+ def initialize(class_name, images, bundle_name)
6
6
  @class_name = class_name
7
7
  @images = images
8
+ @bundle_name = bundle_name
8
9
  end
9
10
 
10
11
  def interface_file
@@ -14,7 +15,6 @@ module Hemera
14
15
  def implementent_file
15
16
  ERB.new(File.read(File.expand_path('template/image.m.erb', __dir__))).result(binding)
16
17
  end
17
-
18
18
  end
19
19
  end
20
20
  end
@@ -2,9 +2,10 @@ require 'erb'
2
2
  module Hemera
3
3
  module Generator
4
4
  class SwiftImageGenerator
5
- def initialize(struct_name, images)
5
+ def initialize(struct_name, images, bundle_name)
6
6
  @struct_name = struct_name
7
7
  @images = images
8
+ @bundle_name = bundle_name
8
9
  end
9
10
 
10
11
  def swift_file
@@ -7,6 +7,21 @@
7
7
 
8
8
  <%= "#import \"#{@class_name}.h\"" %>
9
9
 
10
+ <%= "@implementation UIImage (#{@class_name})" %>
11
+
12
+ <%= "+ (UIImage *)#{@class_name.downcase}_imageNamed:(NSString *)name {" %>
13
+ <% unless @bundle_name %>
14
+ <%= "\treturn [UIImage imageNamed:name];" %>
15
+ <% else %>
16
+ <%= "\tNSBundle *bundle = [NSBundle bundleForClass:self];"%>
17
+ <%= "\tNSURL *URL = [bundle URLForResource:@\"#{@bundle_name}\" withExtension:@\"bundle\"];"%>
18
+ <%= "\tNSBundle *resourceBundle = [NSBundle bundleWithURL:URL];" %>
19
+ <%= "\treturn [self imageNamed:name inBundle:resourceBundle compatibleWithTraitCollection:nil];"%>
20
+ <% end %>available
21
+ <%= "}" %>
22
+
23
+ @end
24
+
10
25
  <%= "@interface #{@class_name} ()" %>
11
26
 
12
27
  @property (nonatomic, readwrite) UIImage *light;
@@ -19,10 +34,10 @@
19
34
  <% for @image in @images %>
20
35
  <%= "+ (#{@class_name} *)#{@image.name} {"%>
21
36
  <%= "\t#{@class_name} *model = [#{@class_name} new];" %>
22
- <%= "\tmodel.light = [UIImage imageNamed:@\"#{@image.name_light}\"];" %>
23
- <%= "\tmodel.dark = [UIImage imageNamed:@\"#{@image.name_dark}\"];" %>
37
+ <%= "\tmodel.light = [UIImage #{@class_name.downcase}_imageNamed:@\"#{@image.name_light}\"];" %>
38
+ <%= "\tmodel.dark = [UIImage #{@class_name.downcase}_imageNamed:@\"#{@image.name_dark}\"];" %>
24
39
  <%= "\treturn model;" %>
25
40
  <%= "}" %>
26
41
  <% end %>
27
- @end
42
+ <%= "@end" %>
28
43
 
@@ -6,12 +6,28 @@
6
6
  */
7
7
 
8
8
  import UIKit
9
+
10
+ extension UIImage {
11
+ <%= "\tpublic convenience init?(#{@struct_name.downcase} name: String) {"%>
12
+ <% unless @bundle_name %>
13
+ <%= "\treturn UIImage(named: name)" %>
14
+ <% else %>
15
+ <%= "\t\tlet bundle = Bundle(for: #{@struct_name}.Helper.self)" %>
16
+ <%= "\t\tlet url = bundle.url(forResource: \"#{@bundle_name}\", withExtension: \"bundle\")" %>
17
+ <%= "\t\tguard let availableURL = url else { return nil }" %>
18
+ <%= "\t\tlet resourceBundle = Bundle(url: availableURL)" %>
19
+ <%= "\t\tself.init(named: name, in: resourceBundle, compatibleWith: nil)" %>
20
+ <% end %>
21
+ }
22
+ }
23
+
9
24
  struct <%= @struct_name %> {
25
+ fileprivate class Helper {}
10
26
  private(set) lazy var dark: UIImage = {
11
- return UIImage(named: darkName)!
27
+ return UIImage(<%= "#{@struct_name.downcase}" %>: darkName)!
12
28
  }()
13
29
  private(set) lazy var light: UIImage = {
14
- return UIImage(named: lightName)!
30
+ return UIImage(<%= "#{@struct_name.downcase}" %>: lightName)!
15
31
  }()
16
32
  private let darkName: String
17
33
  private let lightName: String
@@ -24,4 +40,5 @@ struct <%= @struct_name %> {
24
40
  <%= "\treturn #{@struct_name}(darkName: \"#{@image.name_dark}\", lightName:\"#{@image.name_light}\")" %>
25
41
  <%= "}()" %>
26
42
  <% end %>
27
- }
43
+ }
44
+
@@ -1,3 +1,3 @@
1
1
  module Hemera
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hemera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JianweiWangs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-17 00:00:00.000000000 Z
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,22 +28,22 @@ dependencies:
28
28
  name: cocoapods
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.5'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
33
  version: 1.5.0
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.5'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.5'
44
41
  - - ">="
45
42
  - !ruby/object:Gem::Version
46
43
  version: 1.5.0
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -155,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.7.6
158
+ rubygems_version: 3.0.1
160
159
  signing_key:
161
160
  specification_version: 4
162
161
  summary: development tool