redbreast 0.1.2 → 1.0.0

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 +9 -7
  8. data/lib/.DS_Store +0 -0
  9. data/lib/redbreast.rb +25 -18
  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 +29 -29
  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 -92
  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 -7
  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 +93 -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 +21 -22
  40. metadata +35 -11
  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: 28335747641b4f238124171e835adccda21ebcdf
4
- data.tar.gz: 9c10192572608e34b0666c9b0cbad98f137cd200
2
+ SHA256:
3
+ metadata.gz: 1b87d5ad0784aec595012ad081b5b1bb4e269010f61f4e7ceef1357a28f294f0
4
+ data.tar.gz: 927b1b4b0f14e681f704f6e0265345db2a0bfa0e42f20807b317f32ba6a6c157
5
5
  SHA512:
6
- metadata.gz: 1ae134219d98faad33b54171cef764ffb1069b8f7520931f9e5f24c6577d9d7251abcd7ad5bb4447109be58636a4a47e257220963ae7786eb9069998434947f4
7
- data.tar.gz: 7839bccb9fffebe8aeba5acdc45a0090f35474f3c68618a343fbfe38effe77f85d4affcbb5e9e53b61ea0a8f3886be9dbcb83d0cfb1d442a42a92cbaead78fe3
6
+ metadata.gz: 4be80f6303152194ae46f3dc222a1704a3c59e56f2fc916595eef3a6edb35b46b513caf522ff526460b59d4f87b776ba8c876e4c649eaa1ef8db16bd58b03f8c
7
+ data.tar.gz: a5645a6f368a39e1a2e7bfbfbe3a2899c91219b3e5119a7decd60e4291b93f4ab34290565557adc9ae6e4c33f1288146f79bded9d52ca8d126c5c9d98df0b746
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,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 |_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
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 |_args, options|
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
- 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"
14
- require "redbreast/commands/configuration_installer"
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 "redbreast/io/config"
20
+ require 'redbreast/io/config'
18
21
 
19
22
  # Crawlers
20
- require "redbreast/crawlers/image_crawler"
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/tests/objc_tests_template_generator'
33
- 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'
34
42
 
35
43
  # Error Handler
36
- require "redbreast/error_handler"
44
+ require 'redbreast/error_handler'
37
45
 
38
46
  # Version
39
- require "redbreast/version"
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
- module Command
5
- class ConfigurationInstaller
6
- include Helper::Terminal
7
- include Helper::General
8
-
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
- 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
- def configure_target(target)
30
- phase = target.new_shell_script_build_phase("Redbreast generate")
31
- phase.shell_script = "redbreast generate"
32
- end
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