redbreast 0.1.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.DS_Store +0 -0
- data/.rubocop.yml +5 -0
- data/README.md +102 -4
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/exe/redbreast +9 -7
- data/lib/.DS_Store +0 -0
- data/lib/redbreast.rb +25 -18
- data/lib/redbreast/.DS_Store +0 -0
- data/lib/redbreast/commands/color_generator.rb +54 -0
- data/lib/redbreast/commands/color_test_generator.rb +57 -0
- data/lib/redbreast/commands/configuration_installer.rb +29 -29
- data/lib/redbreast/commands/image_generator.rb +49 -47
- data/lib/redbreast/commands/image_test_generator.rb +57 -0
- data/lib/redbreast/commands/setup.rb +139 -91
- data/lib/redbreast/crawlers/color_crawler.rb +38 -0
- data/lib/redbreast/crawlers/image_crawler.rb +30 -10
- data/lib/redbreast/error_handler.rb +7 -6
- data/lib/redbreast/helpers/general.rb +73 -63
- data/lib/redbreast/helpers/hash.rb +8 -8
- data/lib/redbreast/helpers/terminal.rb +2 -3
- data/lib/redbreast/io/config.rb +14 -15
- data/lib/redbreast/serializers/objc_serializer.rb +66 -19
- data/lib/redbreast/serializers/serializer.rb +17 -16
- data/lib/redbreast/serializers/swift_serializer.rb +91 -2
- data/lib/redbreast/template_generators/.DS_Store +0 -0
- data/lib/redbreast/template_generators/colors/objc_colors_template_generator.rb +35 -0
- data/lib/redbreast/template_generators/colors/swift_colors_template_generator.rb +22 -0
- data/lib/redbreast/template_generators/images/objc_images_template_generator.rb +27 -41
- data/lib/redbreast/template_generators/images/swift_images_template_generator.rb +16 -21
- data/lib/redbreast/template_generators/objc_template_generator.rb +19 -19
- data/lib/redbreast/template_generators/swift_template_generator.rb +9 -10
- data/lib/redbreast/template_generators/tests/colors/objc_colors_tests_template_generator.rb +35 -0
- data/lib/redbreast/template_generators/tests/colors/swift_colors_tests_template_generator.rb +27 -0
- data/lib/redbreast/template_generators/tests/images/objc_images_tests_template_generator.rb +36 -0
- data/lib/redbreast/template_generators/tests/images/swift_images_tests_template_generator.rb +27 -0
- data/lib/redbreast/version.rb +1 -1
- data/redbreast.gemspec +21 -22
- metadata +39 -15
- data/lib/redbreast/commands/test_generator.rb +0 -56
- data/lib/redbreast/template_generators/tests/objc_tests_template_generator.rb +0 -39
- data/lib/redbreast/template_generators/tests/swift_tests_template_generator.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e655bee32f96732f77f8b5f88d0bb1fdade6fd1c142758aafc6b17afb771457
|
4
|
+
data.tar.gz: 82ecee365aa0bc210b45dca522bfd868468950d38babfe1abb3f787125746f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 327a93d2fe2ecc30185cbda0d1b8bbc4a9a17f0e7a99f5fed9547d050e438d9881fb9d4aee2cf4ed99456333f4fafd9984bbe78b86567ade1ac570b9e1d0807b
|
7
|
+
data.tar.gz: ea2cdc2572af400207fc6e9f12804cf66858ea1a90dac2abc748686f76a456b67fecbc2a9e7929f4baa5c936c3191d723d32f286c3c2227860ae39d1faa8cfaa
|
data/.DS_Store
CHANGED
Binary file
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -18,20 +18,118 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install redbreast
|
20
20
|
|
21
|
+
## Description
|
22
|
+
|
23
|
+
Redbreast is a gem used for generating extensions (categories) of UIImage or UIColor. In Swift it creates computed properties of images or colors that are in your assets folder. While in Objective-C it creates static methods that returns UIImage or UIColor object.
|
24
|
+
|
25
|
+
### Example ###
|
26
|
+
|
27
|
+
In this example we will show how will your extensions (catergories) look like after using Redbreast.
|
28
|
+
|
29
|
+
Lets say this is how your *Images.xcassets* folder looks like:
|
30
|
+
|
31
|
+
```
|
32
|
+
Images.xcassets
|
33
|
+
└── App // namespaced
|
34
|
+
│ └── Admin // namespaced
|
35
|
+
│ │ └── Report.imageset
|
36
|
+
│ │ └── User.imageset
|
37
|
+
│ └── Course
|
38
|
+
│ └── Assignment.imageset
|
39
|
+
│
|
40
|
+
└── AppLogo.imageset
|
41
|
+
│
|
42
|
+
└── Arrows
|
43
|
+
└── DownArrow.imageset
|
44
|
+
```
|
45
|
+
|
46
|
+
*App* and *Admin* are namespaced folders while *Course* and *Arrows* are not. If a folder is namespaced, enum with that folder name will appear in the exension and path to that image will contain folder name. In the other case, folders are ignored and images belong to the last namespaced folder.
|
47
|
+
|
48
|
+
Redbreast will generate a file similar to this one varying on app name (more in Usage chapter). As you can see *Arrows* folder is not namespaced so there isn't an enum called *Arrows*. Because of this *downArrow* is in root of extension and is accessed by writing `UIImage.downArrow`. *Report* image is in two namespaced folders (*App* and *Admin*) so path for it is *App/Admin* and it located inside both enums. *Report* is accessed by `UIImage.App.Admin.report`.
|
49
|
+
|
50
|
+
```swift
|
51
|
+
extension UIImage {
|
52
|
+
|
53
|
+
static var appLogo: UIImage { return UIImage(named: "AppLogo", in: .main, compatibleWith: nil)! }
|
54
|
+
static var downArrow: UIImage { return UIImage(named: "DownArrow", in: .main, compatibleWith: nil)! }
|
55
|
+
|
56
|
+
enum App {
|
57
|
+
|
58
|
+
enum Admin {
|
59
|
+
static var report: UIImage { return UIImage(named: "App/Admin/Report", in: .main, compatibleWith: nil)! }
|
60
|
+
static var user: UIImage { return UIImage(named: "App/Admin/User", in: .main, compatibleWith: nil)! }
|
61
|
+
}
|
62
|
+
|
63
|
+
static var assignment: UIImage { return UIImage(named: "App/Assignment", in: .main, compatibleWith: nil)! }
|
64
|
+
}
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
In Objective-C .h and .m files are generated. Because enums don't exist in Objc folder names are used in method name instead. Everything else is the same as in Swift.
|
69
|
+
```objc
|
70
|
+
@implementation UIImage (ApplicationName)
|
71
|
+
|
72
|
+
+ (UIImage *)appLogo
|
73
|
+
{
|
74
|
+
return [UIImage imageNamed:@"AppLogo" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
|
75
|
+
}
|
76
|
+
|
77
|
+
+ (UIImage *)downArrow
|
78
|
+
{
|
79
|
+
return [UIImage imageNamed:@"DownArrow" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
|
80
|
+
}
|
81
|
+
|
82
|
+
+ (UIImage *)appAdminReport
|
83
|
+
{
|
84
|
+
return [UIImage imageNamed:@"App/Admin/Report" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
|
85
|
+
}
|
86
|
+
|
87
|
+
+ (UIImage *)appAdminUser
|
88
|
+
{
|
89
|
+
return [UIImage imageNamed:@"App/Admin/User" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
|
90
|
+
}
|
91
|
+
|
92
|
+
+ (UIImage *)appAssignment
|
93
|
+
{
|
94
|
+
return [UIImage imageNamed:@"App/Assignment" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
|
95
|
+
}
|
96
|
+
|
97
|
+
@end
|
98
|
+
```
|
99
|
+
|
100
|
+
For more examples checkout the sample project.
|
101
|
+
|
21
102
|
## Usage
|
22
103
|
|
23
|
-
|
104
|
+
### Init
|
24
105
|
|
25
|
-
|
106
|
+
After installing redbreast run `redbreast init` to create `redbreast.yml` file. This file is used for generating your extensions.
|
107
|
+
In the init you will be prompted to:
|
26
108
|
|
27
|
-
|
109
|
+
* Choose a language in which colors/images will be generated.
|
110
|
+
* Input the application name (optional)
|
111
|
+
* Input bundle names (default is main)
|
112
|
+
* Choose whether you want to generate images, colors or both
|
113
|
+
* Input the path to assets folder
|
114
|
+
* Input the path where the files will be created
|
115
|
+
* Choose to create tests for generated assets
|
28
116
|
|
29
|
-
|
117
|
+
### Generate
|
118
|
+
|
119
|
+
When you finish creating `redbreast.yml` file, run `redbreast generate` and all needed files will be generated.
|
120
|
+
|
121
|
+
### Install
|
122
|
+
|
123
|
+
Command `redbreast install` will setup a file generator in your project and whenever you build it, it will create new image/color names.
|
30
124
|
|
31
125
|
## Contributing
|
32
126
|
|
33
127
|
Bug reports and pull requests are welcome on GitHub at https://github.com/infinum/redbreast. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
128
|
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
+
|
35
133
|
|
36
134
|
## License
|
37
135
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'redbreast'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "redbreast"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/exe/redbreast
CHANGED
@@ -12,7 +12,7 @@ program :description, 'An iOS client for safe and strong resources.'
|
|
12
12
|
command :init do |c|
|
13
13
|
c.syntax = 'redbreast init'
|
14
14
|
c.description = 'Sets up a redbreast.yml config for selected project.'
|
15
|
-
c.action do
|
15
|
+
c.action do
|
16
16
|
Redbreast::ErrorHandler.rescuable do
|
17
17
|
Redbreast::Command::Setup.init
|
18
18
|
end
|
@@ -21,21 +21,23 @@ end
|
|
21
21
|
|
22
22
|
command :generate do |c|
|
23
23
|
c.syntax = 'redbreast generate'
|
24
|
-
c.description = 'Generate images strong reference files.'
|
25
|
-
c.action do
|
24
|
+
c.description = 'Generate images and colors strong reference files.'
|
25
|
+
c.action do
|
26
26
|
Redbreast::ErrorHandler.rescuable do
|
27
|
+
Redbreast::Command::ColorGenerator.init
|
27
28
|
Redbreast::Command::ImageGenerator.init
|
28
|
-
Redbreast::Command::
|
29
|
+
Redbreast::Command::ColorTestGenerator.init
|
30
|
+
Redbreast::Command::ImageTestGenerator.init
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
35
|
command :install do |c|
|
34
36
|
c.syntax = 'redbreast install'
|
35
|
-
c.description = 'Sets up file generator in your xcproject build phases. Whenewer you run a buld, new image names will be created'
|
36
|
-
c.action do
|
37
|
+
c.description = 'Sets up file generator in your xcproject build phases. Whenewer you run a buld, new image/color names will be created'
|
38
|
+
c.action do
|
37
39
|
Redbreast::ErrorHandler.rescuable do
|
38
40
|
Redbreast::Command::ConfigurationInstaller.init
|
39
41
|
end
|
40
42
|
end
|
41
|
-
end
|
43
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/redbreast.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
# Parsing
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
4
5
|
|
5
6
|
# Helpers
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require 'redbreast/helpers/terminal'
|
8
|
+
require 'redbreast/helpers/general'
|
9
|
+
require 'redbreast/helpers/hash'
|
9
10
|
|
10
11
|
# Commands
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
12
|
+
require 'redbreast/commands/setup'
|
13
|
+
require 'redbreast/commands/image_generator'
|
14
|
+
require 'redbreast/commands/color_generator'
|
15
|
+
require 'redbreast/commands/image_test_generator'
|
16
|
+
require 'redbreast/commands/color_test_generator'
|
17
|
+
require 'redbreast/commands/configuration_installer'
|
15
18
|
|
16
19
|
# File Accessors
|
17
|
-
require
|
20
|
+
require 'redbreast/io/config'
|
18
21
|
|
19
22
|
# Crawlers
|
20
|
-
require
|
23
|
+
require 'redbreast/crawlers/image_crawler'
|
24
|
+
require 'redbreast/crawlers/color_crawler'
|
21
25
|
|
22
26
|
# Serializers
|
23
27
|
require 'redbreast/serializers/serializer'
|
@@ -29,16 +33,19 @@ require 'redbreast/template_generators/objc_template_generator'
|
|
29
33
|
require 'redbreast/template_generators/swift_template_generator'
|
30
34
|
require 'redbreast/template_generators/images/objc_images_template_generator'
|
31
35
|
require 'redbreast/template_generators/images/swift_images_template_generator'
|
32
|
-
require 'redbreast/template_generators/
|
33
|
-
require 'redbreast/template_generators/
|
36
|
+
require 'redbreast/template_generators/colors/objc_colors_template_generator'
|
37
|
+
require 'redbreast/template_generators/colors/swift_colors_template_generator'
|
38
|
+
require 'redbreast/template_generators/tests/colors/objc_colors_tests_template_generator'
|
39
|
+
require 'redbreast/template_generators/tests/colors/swift_colors_tests_template_generator'
|
40
|
+
require 'redbreast/template_generators/tests/images/objc_images_tests_template_generator'
|
41
|
+
require 'redbreast/template_generators/tests/images/swift_images_tests_template_generator'
|
34
42
|
|
35
43
|
# Error Handler
|
36
|
-
require
|
44
|
+
require 'redbreast/error_handler'
|
37
45
|
|
38
46
|
# Version
|
39
|
-
require
|
40
|
-
|
47
|
+
require 'redbreast/version'
|
41
48
|
|
49
|
+
# Program used for creating images and colors
|
42
50
|
module Redbreast
|
43
|
-
|
44
|
-
end
|
51
|
+
end
|
Binary file
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Redbreast
|
2
|
+
module Command
|
3
|
+
# Class for generating color files
|
4
|
+
class ColorGenerator
|
5
|
+
include Helper::Terminal
|
6
|
+
include Helper::General
|
7
|
+
|
8
|
+
def self.init
|
9
|
+
new.call
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
return if bundles.first[:outputSourcePathColors].nil?
|
14
|
+
|
15
|
+
prompt.say('Generating color resources...')
|
16
|
+
generate_color_sources(bundles, programming_language, app_name)
|
17
|
+
success('Color resources generated!')
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_color_sources(bundles, programming_language, app_name)
|
23
|
+
bundles.each do |bundle|
|
24
|
+
color_names = pull_asset_names(bundle[:assetsSearchPath])
|
25
|
+
write_colors(color_names, bundle, programming_language, app_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Serializing data
|
30
|
+
|
31
|
+
def write_colors(color_names, bundle, programming_language, app_name)
|
32
|
+
output_path = bundle[:outputSourcePathColors]
|
33
|
+
return if output_path.to_s.empty?
|
34
|
+
|
35
|
+
case programming_language.downcase
|
36
|
+
when 'objc'
|
37
|
+
serializer = Redbreast::Serializer::ObjC
|
38
|
+
template_generator = Redbreast::TemplateGenerator::Color::ObjC
|
39
|
+
when 'swift'
|
40
|
+
serializer = Redbreast::Serializer::Swift
|
41
|
+
template_generator = Redbreast::TemplateGenerator::Color::Swift
|
42
|
+
end
|
43
|
+
serializer.new(color_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Pulling data
|
47
|
+
|
48
|
+
def pull_asset_names(assetsSearchPath)
|
49
|
+
Redbreast::Crawler::Color
|
50
|
+
.color_names_uniq(assetsSearchPath)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Redbreast
|
2
|
+
module Command
|
3
|
+
# Class for creating color tests
|
4
|
+
class ColorTestGenerator
|
5
|
+
include Helper::Terminal
|
6
|
+
include Helper::General
|
7
|
+
|
8
|
+
def self.init
|
9
|
+
new.call
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
filtered_bundles = bundles.select { |bundle| bundle[:outputTestPathColors] }
|
14
|
+
return if filtered_bundles.empty?
|
15
|
+
|
16
|
+
prompt.say('Generating color test resources...')
|
17
|
+
generate_test_sources(bundles, programming_language, app_name)
|
18
|
+
success('Color test resources generated!')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def generate_test_sources(bundles, programming_language, app_name)
|
24
|
+
bundles.each do |bundle|
|
25
|
+
color_names = pull_asset_names(bundle[:assetsSearchPath])
|
26
|
+
write_tests(color_names, bundle, programming_language, app_name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Serializing data
|
31
|
+
|
32
|
+
def write_tests(color_names, bundle, programming_language, app_name)
|
33
|
+
output_path = bundle[:outputTestPathColors]
|
34
|
+
|
35
|
+
return if output_path.to_s.empty?
|
36
|
+
|
37
|
+
case programming_language.downcase
|
38
|
+
when 'objc'
|
39
|
+
serializer = Redbreast::Serializer::ObjC
|
40
|
+
template_generator = Redbreast::TemplateGenerator::ColorTest::ObjC
|
41
|
+
when 'swift'
|
42
|
+
serializer = Redbreast::Serializer::Swift
|
43
|
+
template_generator = Redbreast::TemplateGenerator::ColorTest::Swift
|
44
|
+
end
|
45
|
+
serializer.new(color_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: true)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# Pulling data
|
50
|
+
|
51
|
+
def pull_asset_names(assetsSearchPath)
|
52
|
+
Redbreast::Crawler::Color
|
53
|
+
.color_names_uniq(assetsSearchPath)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,37 +1,37 @@
|
|
1
1
|
require 'xcodeproj'
|
2
2
|
|
3
3
|
module Redbreast
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def fetch_project()
|
24
|
-
path = Dir.glob("*.xcodeproj").first
|
25
|
-
raise ".xcodeproj file not found" if path.nil?
|
26
|
-
project = Xcodeproj::Project.open(path)
|
27
|
-
end
|
4
|
+
module Command
|
5
|
+
# Class for installing configuration
|
6
|
+
class ConfigurationInstaller
|
7
|
+
include Helper::Terminal
|
8
|
+
include Helper::General
|
9
|
+
def self.init
|
10
|
+
new.call
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
prompt.say('Adding generation script to xcode buid phases...')
|
15
|
+
project = fetch_project
|
16
|
+
configure_target project.targets.first
|
17
|
+
project.save
|
18
|
+
success('Build phase setup!')
|
19
|
+
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
def fetch_project
|
24
|
+
path = Dir.glob('*.xcodeproj').first
|
25
|
+
raise '.xcodeproj file not found' if path.nil?
|
26
|
+
|
27
|
+
Xcodeproj::Project.open(path)
|
28
|
+
end
|
33
29
|
|
30
|
+
def configure_target(target)
|
31
|
+
puts target.build_phases.class
|
32
|
+
phase = target.new_shell_script_build_phase('Redbreast generate')
|
33
|
+
phase.shell_script = "PATH=$PATH:~/.rbenv/shims\nredbreast generate"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
end
|