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
@@ -1,53 +1,55 @@
|
|
1
1
|
module Redbreast
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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,115 +2,163 @@ require 'commander/blank'
|
|
2
2
|
require 'commander/command'
|
3
3
|
|
4
4
|
module Redbreast
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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, app_name, language) : nil
|
39
42
|
}
|
40
|
-
|
41
|
-
success
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
# Language
|
47
|
-
|
48
|
-
def language_prompt
|
49
|
-
languages = {'Swift' => 'swift', 'Objective-C' => 'objc'}
|
50
|
-
prompt.select('Choose a language: ', languages)
|
43
|
+
compact fields
|
51
44
|
end
|
52
|
-
|
53
|
-
|
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
|
54
69
|
|
55
|
-
|
56
|
-
|
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')
|
57
79
|
end
|
80
|
+
end
|
58
81
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
when "swift"
|
66
|
-
prompt.ask('Please enter bundle names that you use separated by spaces', default: 'main')
|
67
|
-
end
|
82
|
+
def bundle_reference(bundle_name, language)
|
83
|
+
case language
|
84
|
+
when 'objc'
|
85
|
+
"[NSBundle #{bundle_name}]"
|
86
|
+
when 'swift'
|
87
|
+
".#{bundle_name}"
|
68
88
|
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Images source path
|
69
92
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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')
|
77
100
|
end
|
101
|
+
end
|
78
102
|
|
79
|
-
|
103
|
+
# Colors source path
|
80
104
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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')
|
88
112
|
end
|
113
|
+
end
|
89
114
|
|
90
|
-
|
115
|
+
# Tests
|
116
|
+
|
117
|
+
def create_tests_path_prompt?(bundle)
|
118
|
+
prompt.yes?("Would you like to create tests for bundle #{bundle}?")
|
119
|
+
end
|
91
120
|
|
92
|
-
|
93
|
-
|
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')
|
94
128
|
end
|
129
|
+
end
|
95
130
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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')
|
103
138
|
end
|
139
|
+
end
|
104
140
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
141
|
+
def testable_import_prompt(bundle, app_name, language)
|
142
|
+
case language
|
143
|
+
when 'objc'
|
144
|
+
nil
|
145
|
+
when 'swift'
|
146
|
+
prompt.ask("Please enter a name that will be used for testable import in #{bundle} bundle?", default: "#{app_name}", required: true)
|
112
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
|
113
157
|
|
158
|
+
def assets_types_prompt
|
159
|
+
types = { 'Images' => 0, 'Colors' => 1, 'Both' => 2 }
|
160
|
+
prompt.select('Choose a type: ', types)
|
114
161
|
end
|
115
162
|
end
|
116
|
-
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
|