redbreast 0.1.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +5 -0
  4. data/README.md +102 -4
  5. data/Rakefile +3 -3
  6. data/bin/console +3 -3
  7. data/exe/redbreast +17 -5
  8. data/lib/.DS_Store +0 -0
  9. data/lib/redbreast.rb +25 -17
  10. data/lib/redbreast/.DS_Store +0 -0
  11. data/lib/redbreast/commands/color_generator.rb +54 -0
  12. data/lib/redbreast/commands/color_test_generator.rb +57 -0
  13. data/lib/redbreast/commands/configuration_installer.rb +37 -0
  14. data/lib/redbreast/commands/image_generator.rb +49 -47
  15. data/lib/redbreast/commands/image_test_generator.rb +57 -0
  16. data/lib/redbreast/commands/setup.rb +139 -91
  17. data/lib/redbreast/crawlers/color_crawler.rb +38 -0
  18. data/lib/redbreast/crawlers/image_crawler.rb +30 -10
  19. data/lib/redbreast/error_handler.rb +7 -6
  20. data/lib/redbreast/helpers/general.rb +73 -63
  21. data/lib/redbreast/helpers/hash.rb +8 -8
  22. data/lib/redbreast/helpers/terminal.rb +2 -3
  23. data/lib/redbreast/io/config.rb +14 -15
  24. data/lib/redbreast/serializers/objc_serializer.rb +66 -19
  25. data/lib/redbreast/serializers/serializer.rb +17 -16
  26. data/lib/redbreast/serializers/swift_serializer.rb +90 -2
  27. data/lib/redbreast/template_generators/.DS_Store +0 -0
  28. data/lib/redbreast/template_generators/colors/objc_colors_template_generator.rb +35 -0
  29. data/lib/redbreast/template_generators/colors/swift_colors_template_generator.rb +22 -0
  30. data/lib/redbreast/template_generators/images/objc_images_template_generator.rb +27 -41
  31. data/lib/redbreast/template_generators/images/swift_images_template_generator.rb +16 -21
  32. data/lib/redbreast/template_generators/objc_template_generator.rb +19 -19
  33. data/lib/redbreast/template_generators/swift_template_generator.rb +9 -10
  34. data/lib/redbreast/template_generators/tests/colors/objc_colors_tests_template_generator.rb +35 -0
  35. data/lib/redbreast/template_generators/tests/colors/swift_colors_tests_template_generator.rb +27 -0
  36. data/lib/redbreast/template_generators/tests/images/objc_images_tests_template_generator.rb +36 -0
  37. data/lib/redbreast/template_generators/tests/images/swift_images_tests_template_generator.rb +27 -0
  38. data/lib/redbreast/version.rb +1 -1
  39. data/redbreast.gemspec +22 -22
  40. metadata +54 -15
  41. data/lib/redbreast/commands/test_generator.rb +0 -56
  42. data/lib/redbreast/template_generators/tests/objc_tests_template_generator.rb +0 -39
  43. data/lib/redbreast/template_generators/tests/swift_tests_template_generator.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: acb449e6185cec29a8b5db4b37b9c2d1171a8cee
4
- data.tar.gz: ed1ca1fae6e110d58b10bf64368a3292fa60d213
2
+ SHA256:
3
+ metadata.gz: a61b421737d7f28ab41362cb78ad00e3fd2246588e6346938dbe3589c82320e7
4
+ data.tar.gz: ca241430323a6822e1b1943e67ebf1dddec6ea663e26fde0cd3d792d97f30f17
5
5
  SHA512:
6
- metadata.gz: caeabd7ec6255affe9e59c2e5c56bd9bba1ada4bc0ae62a8294385df7cd141fedcdbe7995ed56b607b71f0215f7fec6668c9f4007914a2971551a22693ced72f
7
- data.tar.gz: 89e95780148d0e1ce307d1ac2965c96612663a9c1ac7910b3acfa686f4efd2a65033f5ac95930e6cba0c5d0879554e47cd232947e51ee947861a8e388d807e7e
6
+ metadata.gz: 5cdb3304c7d176836430c1ec41826071a8544f171b0f9004f87a5a11da2bb7a817e79cfc28ca4662a44f5084b85bdf83f491a831a930b94b80e009610bcc1f0a
7
+ data.tar.gz: a3257f6b265ed44b1f1a7fe12326002838e3f25c063001051c2b550ff716898621491157e4948855706f52fe748ff5ded3560db968e4fa40b1c986ce9815c5f3
data/.DS_Store CHANGED
Binary file
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Layout/LineLength:
2
+ Max: 100
3
+
4
+ Style/WordArray:
5
+ EnforcedStyle: brackets
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
- TODO: Write usage instructions here
104
+ ### Init
24
105
 
25
- ## Development
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
- 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.
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
- 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).
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "redbreast"
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 "irb"
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 |_args, options|
15
+ c.action do
16
16
  Redbreast::ErrorHandler.rescuable do
17
17
  Redbreast::Command::Setup.init
18
18
  end
@@ -21,11 +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 |_args, options|
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::TestGenerator.init
29
+ Redbreast::Command::ColorTestGenerator.init
30
+ Redbreast::Command::ImageTestGenerator.init
29
31
  end
30
32
  end
31
- end
33
+ end
34
+
35
+ command :install do |c|
36
+ c.syntax = 'redbreast install'
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
39
+ Redbreast::ErrorHandler.rescuable do
40
+ Redbreast::Command::ConfigurationInstaller.init
41
+ end
42
+ end
43
+ end
data/lib/.DS_Store ADDED
Binary file
data/lib/redbreast.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  # Parsing
2
- require "yaml"
3
- require "erb"
2
+
3
+ require 'yaml'
4
+ require 'erb'
4
5
 
5
6
  # Helpers
6
- require "redbreast/helpers/terminal"
7
- require "redbreast/helpers/general"
8
- require "redbreast/helpers/hash"
7
+ require 'redbreast/helpers/terminal'
8
+ require 'redbreast/helpers/general'
9
+ require 'redbreast/helpers/hash'
9
10
 
10
11
  # Commands
11
- require "redbreast/commands/setup"
12
- require "redbreast/commands/image_generator"
13
- require "redbreast/commands/test_generator"
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'
14
18
 
15
19
  # File Accessors
16
- require "redbreast/io/config"
20
+ require 'redbreast/io/config'
17
21
 
18
22
  # Crawlers
19
- require "redbreast/crawlers/image_crawler"
23
+ require 'redbreast/crawlers/image_crawler'
24
+ require 'redbreast/crawlers/color_crawler'
20
25
 
21
26
  # Serializers
22
27
  require 'redbreast/serializers/serializer'
@@ -28,16 +33,19 @@ require 'redbreast/template_generators/objc_template_generator'
28
33
  require 'redbreast/template_generators/swift_template_generator'
29
34
  require 'redbreast/template_generators/images/objc_images_template_generator'
30
35
  require 'redbreast/template_generators/images/swift_images_template_generator'
31
- require 'redbreast/template_generators/tests/objc_tests_template_generator'
32
- require 'redbreast/template_generators/tests/swift_tests_template_generator'
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'
33
42
 
34
43
  # Error Handler
35
- require "redbreast/error_handler"
44
+ require 'redbreast/error_handler'
36
45
 
37
46
  # Version
38
- require "redbreast/version"
39
-
47
+ require 'redbreast/version'
40
48
 
49
+ # Program used for creating images and colors
41
50
  module Redbreast
42
-
43
- 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
@@ -0,0 +1,37 @@
1
+ require 'xcodeproj'
2
+
3
+ module Redbreast
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
20
+
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
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
+ end
35
+ end
36
+ end
37
+ end
@@ -1,53 +1,55 @@
1
1
  module Redbreast
2
- module Command
3
- class ImageGenerator
4
- include Helper::Terminal
5
- include Helper::General
6
-
7
- def self.init
8
- new.call
9
- end
10
-
11
- def call
12
- prompt.say("Generating image resources...")
13
- generate_image_sources(bundles, programming_language)
14
- success("Image resources generated!")
15
- end
16
-
17
- private
18
-
19
- def generate_image_sources(bundles, programming_language)
20
- bundles.each do |bundle|
21
- image_names = pull_asset_names(bundle[:assetsSearchPath])
22
-
23
- write_images(image_names, bundle, programming_language)
24
- end
25
- end
26
-
27
- # Serializing data
28
-
29
- def write_images(image_names, bundle, programming_language)
30
- output_path = bundle[:outputSourcePath]
31
- return if output_path.to_s.empty?
32
- case programming_language.downcase
33
- when "objc"
34
- serializer = Redbreast::Serializer::ObjC
35
- template_generator = Redbreast::TemplateGenerator::Image::ObjC
36
- when "swift"
37
- serializer = Redbreast::Serializer::Swift
38
- template_generator = Redbreast::TemplateGenerator::Image::Swift
39
- end
40
- serializer.new(image_names, bundle).save(output_path, template_generator.new)
2
+ module Command
3
+ # Class for creating images
4
+ class ImageGenerator
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[:outputSourcePathImages].nil?
14
+
15
+ prompt.say('Generating image resources...')
16
+ generate_image_sources(bundles, programming_language, app_name)
17
+ success('Image resources generated!')
18
+ end
19
+
20
+ private
21
+
22
+ def generate_image_sources(bundles, programming_language, app_name)
23
+ bundles.each do |bundle|
24
+ image_names = pull_asset_names(bundle[:assetsSearchPath])
25
+ write_images(image_names, bundle, programming_language, app_name)
41
26
  end
42
-
43
- # Pulling data
44
-
45
- def pull_asset_names(assetsSearchPath)
46
- Redbreast::Crawler::Image
47
- .image_names_uniq(assetsSearchPath)
27
+ end
28
+
29
+ # Serializing data
30
+
31
+ def write_images(image_names, bundle, programming_language, app_name)
32
+ output_path = bundle[:outputSourcePathImages]
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::Image::ObjC
39
+ when 'swift'
40
+ serializer = Redbreast::Serializer::Swift
41
+ template_generator = Redbreast::TemplateGenerator::Image::Swift
48
42
  end
49
-
43
+ serializer.new(image_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: false)
44
+
45
+ end
46
+
47
+ # Pulling data
48
+
49
+ def pull_asset_names(assetsSearchPath)
50
+ Redbreast::Crawler::Image
51
+ .image_names_uniq(assetsSearchPath)
50
52
  end
51
53
  end
52
54
  end
53
-
55
+ end