redbreast 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -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
@@ -0,0 +1,57 @@
1
+ module Redbreast
2
+ module Command
3
+ # Class for generating image tests
4
+ class ImageTestGenerator
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[:outputTestPathImages] }
14
+ return if filtered_bundles.empty?
15
+
16
+ prompt.say('Generating images test resources...')
17
+ generate_test_sources(bundles, programming_language, app_name)
18
+ success('Images 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
+ image_names = pull_asset_names(bundle[:assetsSearchPath])
26
+ write_tests(image_names, bundle, programming_language, app_name)
27
+ end
28
+ end
29
+
30
+ # Serializing data
31
+
32
+ def write_tests(image_names, bundle, programming_language, app_name)
33
+ output_path = bundle[:outputTestPathImages]
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::ImageTest::ObjC
41
+ when 'swift'
42
+ serializer = Redbreast::Serializer::Swift
43
+ template_generator = Redbreast::TemplateGenerator::ImageTest::Swift
44
+ end
45
+ serializer.new(image_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: false)
46
+
47
+ end
48
+
49
+ # Pulling data
50
+
51
+ def pull_asset_names(assetsSearchPath)
52
+ Redbreast::Crawler::Image
53
+ .image_names_uniq(assetsSearchPath)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,116 +2,163 @@ require 'commander/blank'
2
2
  require 'commander/command'
3
3
 
4
4
  module Redbreast
5
- module Command
6
- class Setup
7
- include Helper::Terminal
8
- include Helper::General
9
- include Helper::HashHelper
10
-
11
- def self.init(options = Commander::Command::Options.new)
12
- new(options).call
13
- end
14
-
15
- def initialize(options = Commander::Command::Options.new)
16
- @options = options
17
- end
18
-
19
- def call
20
- language = language_prompt
21
- bundle_names = bundle_names_prompt(language).split(" ")
22
- bundles = bundle_names.map do |bundle|
23
- reference = bundle_reference(bundle, language)
24
- assets_search_path = assets_search_path_prompt(bundle)
25
- output_source_path = images_sources_path_prompt(bundle, language)
26
- include_tests = create_tests_path_prompt?(bundle)
27
- fields = {
28
- name: bundle,
29
- reference: reference,
30
- assetsSearchPath: assets_search_path,
31
- outputSourcePath: output_source_path,
32
- outputTestPath: include_tests ? tests_path_prompt(bundle, language) : nil,
33
- testableImport: include_tests ? testable_import_prompt(bundle, language) : nil
34
- }
35
- compact fields
36
- end
37
- config = {
38
- language: language,
39
- bundles: bundles
5
+ module Command
6
+ # Class for setting up the program
7
+ class Setup
8
+ include Helper::Terminal
9
+ include Helper::General
10
+ include Helper::HashHelper
11
+
12
+ def self.init(options = Commander::Command::Options.new)
13
+ new(options).call
14
+ end
15
+
16
+ def initialize(options = Commander::Command::Options.new)
17
+ @options = options
18
+ end
19
+
20
+ def call
21
+ language = language_prompt
22
+ app_name = app_name_prompt
23
+ bundle_names = bundle_names_prompt(language).split(' ')
24
+ assets_types = assets_types_prompt
25
+ bundles = bundle_names.map do |bundle|
26
+ reference = bundle_reference(bundle, language)
27
+ assets_search_path = assets_search_path_prompt(bundle)
28
+ output_source_path_images = assets_types == 1 ? nil : images_sources_path_prompt(bundle, language)
29
+ output_source_path_colors = assets_types.zero? ? nil : colors_sources_path_prompt(bundle, language)
30
+ include_tests = create_tests_path_prompt?(bundle)
31
+ output_test_path_images = assets_types != 1 && include_tests ? images_tests_path_prompt(bundle, language) : nil
32
+ output_test_path_colors = assets_types != 0 && include_tests ? colors_tests_path_prompt(bundle, language) : nil
33
+ fields = {
34
+ name: bundle,
35
+ reference: reference,
36
+ assetsSearchPath: assets_search_path,
37
+ outputSourcePathImages: output_source_path_images,
38
+ outputSourcePathColors: output_source_path_colors,
39
+ outputTestPathImages: output_test_path_images,
40
+ outputTestPathColors: output_test_path_colors,
41
+ testableImport: include_tests ? testable_import_prompt(bundle, language) : nil
40
42
  }
41
- Redbreast::IO::Config.write(config)
42
- success
43
- end
44
-
45
- private
46
-
47
- # Language
48
-
49
- def language_prompt
50
- languages = {'Swift' => 'swift', 'Objective-C' => 'objc'}
51
- prompt.select('Choose a language: ', languages)
43
+ compact fields
52
44
  end
53
-
54
- # Assets source path
45
+ config = {
46
+ language: language,
47
+ bundles: bundles,
48
+ app_name: app_name
49
+ }
50
+ Redbreast::IO::Config.write(config)
51
+ success
52
+ end
53
+
54
+ private
55
+
56
+ # Language
57
+
58
+ def language_prompt
59
+ languages = { 'Swift' => 'swift', 'Objective-C' => 'objc' }
60
+ prompt.select('Choose a language: ', languages)
61
+ end
62
+
63
+ # Assets source path
64
+
65
+ def assets_search_path_prompt(bundle)
66
+ prompt_text = "Please enter assets folder search paths for bundle #{bundle}?"
67
+ prompt.ask(prompt_text, default: '**/*.xcassets')
68
+ end
55
69
 
56
- def assets_search_path_prompt(bundle)
57
- prompt.ask("Please enter assets folder search paths for bundle #{bundle}?", default: '**/*.xcassets')
70
+ # Bundle names promt
71
+
72
+ def bundle_names_prompt(language)
73
+ prompt_text = 'Please enter bundle names that you use separated by spaces'
74
+ case language
75
+ when 'objc'
76
+ prompt.ask(prompt_text, default: 'mainBundle')
77
+ when 'swift'
78
+ prompt.ask(prompt_text, default: 'main')
58
79
  end
80
+ end
59
81
 
60
- # Bundle names promt
61
-
62
- def bundle_names_prompt(language)
63
- case language
64
- when "objc"
65
- prompt.ask('Please enter bundle names that you use separated by spaces', default: 'mainBundle')
66
- when "swift"
67
- prompt.ask('Please enter bundle names that you use separated by spaces', default: 'main')
68
- end
82
+ def bundle_reference(bundle_name, language)
83
+ case language
84
+ when 'objc'
85
+ "[NSBundle #{bundle_name}]"
86
+ when 'swift'
87
+ ".#{bundle_name}"
69
88
  end
89
+ end
90
+
91
+ # Images source path
70
92
 
71
- def bundle_reference(bundle_name, language)
72
- case language
73
- when "objc"
74
- "[NSBundle #{bundle_name}]"
75
- when "swift"
76
- ".#{bundle_name}"
77
- end
93
+ def images_sources_path_prompt(bundle, language)
94
+ prompt_text = "Where would you like to store images resources files for bundle #{bundle}?"
95
+ case language
96
+ when 'objc'
97
+ prompt.ask(prompt_text, default: './Common/Categories/Images')
98
+ when 'swift'
99
+ prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtension.swift')
78
100
  end
101
+ end
79
102
 
80
- # Images source path
103
+ # Colors source path
81
104
 
82
- def images_sources_path_prompt(bundle, language)
83
- case language
84
- when "objc"
85
- prompt.ask("Where would you like to store images resources files for bundle #{bundle}?", default: './Common/Categories/Images')
86
- when "swift"
87
- prompt.ask("Where would you like to store images resources files for bundle #{bundle}?", default: './Common/Extensions/UIImageExtension.swift')
88
- end
105
+ def colors_sources_path_prompt(bundle, language)
106
+ prompt_text = "Where would you like to store colors resources files for bundle #{bundle}?"
107
+ case language
108
+ when 'objc'
109
+ prompt.ask(prompt_text, default: './Common/Categories/Colors')
110
+ when 'swift'
111
+ prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtension.swift')
89
112
  end
113
+ end
90
114
 
91
- # Tests
115
+ # Tests
116
+
117
+ def create_tests_path_prompt?(bundle)
118
+ prompt.yes?("Would you like to create tests for bundle #{bundle}?")
119
+ end
92
120
 
93
- def create_tests_path_prompt?(bundle)
94
- prompt.yes?("Would you like to create tests for bundle #{bundle}?")
121
+ def images_tests_path_prompt(bundle, language)
122
+ prompt_text = "Where would you like to store tests for bundle #{bundle}?"
123
+ case language
124
+ when 'objc'
125
+ prompt.ask(prompt_text, default: './Common/Categories/ImagesTest')
126
+ when 'swift'
127
+ prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtensionTest.swift')
95
128
  end
129
+ end
96
130
 
97
- def tests_path_prompt(bundle, language)
98
- case language
99
- when "objc"
100
- prompt.ask("Where would you like to store tests for bundle #{bundle}?", default: './Common/Categories/ImagesTest')
101
- when "swift"
102
- prompt.ask("Where would you like to store tests for bundle #{bundle}?", default: './Common/Extensions/UIImageExtensionTest.swift')
103
- end
131
+ def colors_tests_path_prompt(bundle, language)
132
+ prompt_text = "Where would you like to store tests for bundle #{bundle}?"
133
+ case language
134
+ when 'objc'
135
+ prompt.ask(prompt_text, default: './Common/Categories/ColorsTest')
136
+ when 'swift'
137
+ prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtensionTest.swift')
104
138
  end
139
+ end
105
140
 
106
- def testable_import_prompt(bundle, language)
107
- case language
108
- when "objc"
109
- nil
110
- when "swift"
111
- prompt.ask("Please enter testable import name for bundle #{bundle}?", required: true)
112
- end
141
+ def testable_import_prompt(bundle, language)
142
+ case language
143
+ when 'objc'
144
+ nil
145
+ when 'swift'
146
+ prompt.ask("Please enter testable import name for bundle #{bundle}?", required: true)
113
147
  end
148
+ end
149
+
150
+ # Application name propmt
151
+
152
+ def app_name_prompt
153
+ prompt.ask('Please enter application name')
154
+ end
155
+
156
+ # Assets type prompt
114
157
 
158
+ def assets_types_prompt
159
+ types = { 'Images' => 0, 'Colors' => 1, 'Both' => 2 }
160
+ prompt.select('Choose a type: ', types)
115
161
  end
116
162
  end
117
- end
163
+ end
164
+ end
@@ -0,0 +1,38 @@
1
+ module Redbreast
2
+ module Crawler
3
+ # Class used for finding colors
4
+ class Color
5
+ def self.color_names_uniq(assets_search_path)
6
+ Dir.glob(assets_search_path).flat_map do |asset_folder|
7
+ Dir.glob("#{asset_folder}/**/*.colorset").map do |color_name|
8
+ name_to_split = color_name
9
+ split_name = name_to_split.split('.xcassets/')
10
+ current_color_name = split_name[0] + '.xcassets/'
11
+ current_iterating_name = split_name[0] + '.xcassets/'
12
+
13
+ split_name[1].split('/').each do |folder|
14
+ if folder.include? '.colorset'
15
+ current_color_name += folder
16
+ next
17
+ end
18
+
19
+ current_iterating_name += folder + '/'
20
+
21
+ Dir.glob("#{current_iterating_name}*.json").map do |path_name|
22
+ File.open path_name do |file|
23
+ unless file.find { |line| line =~ /provides/ }.nil?
24
+ current_color_name += folder + '/'
25
+ next
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ current_color_name.split('.xcassets/')[-1].chomp('.colorset')
32
+ end
33
+ end
34
+ .uniq
35
+ end
36
+ end
37
+ end
38
+ end