redbreast 0.1.0 → 1.0.2
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 +17 -5
- data/lib/.DS_Store +0 -0
- data/lib/redbreast.rb +25 -17
- 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 +37 -0
- 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 +90 -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 +22 -22
- metadata +54 -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,10 +1,10 @@
|
|
1
|
-
|
2
1
|
module Redbreast
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
module Helper
|
3
|
+
# Module used for creating compact dictionaries
|
4
|
+
module HashHelper
|
5
|
+
def compact(dictionary)
|
6
|
+
dictionary.delete_if { |_k, v| v.nil? }
|
7
|
+
end
|
9
8
|
end
|
10
|
-
end
|
9
|
+
end
|
10
|
+
end
|
@@ -2,8 +2,8 @@ require 'tty-prompt'
|
|
2
2
|
|
3
3
|
module Redbreast
|
4
4
|
module Helper
|
5
|
+
# Module used for communicatin with user via terminal
|
5
6
|
module Terminal
|
6
|
-
|
7
7
|
def success(message = 'Success!')
|
8
8
|
prompt.ok(message)
|
9
9
|
end
|
@@ -11,7 +11,6 @@ module Redbreast
|
|
11
11
|
def prompt
|
12
12
|
@prompt ||= TTY::Prompt.new(interrupt: :exit)
|
13
13
|
end
|
14
|
-
|
15
14
|
end
|
16
15
|
end
|
17
|
-
end
|
16
|
+
end
|
data/lib/redbreast/io/config.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
module Redbreast
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
2
|
+
module IO
|
3
|
+
# Used for reading and writing to config file
|
4
|
+
class Config
|
5
|
+
CONFIG_FILE_PATH = "#{Dir.pwd}/.redbrest.yml"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def write(data)
|
9
|
+
File.open(CONFIG_FILE_PATH, 'w') { |file| YAML.dump(data, file) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def read
|
13
|
+
YAML.load_file(CONFIG_FILE_PATH)
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
end
|
19
|
-
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,27 +1,74 @@
|
|
1
|
-
require_relative 'serializer'
|
1
|
+
require_relative 'serializer'
|
2
2
|
|
3
3
|
module Redbreast
|
4
4
|
module Serializer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
5
|
+
# Used for saving and creating ObjC files
|
6
|
+
class ObjC < Base
|
7
|
+
include Helper::General
|
8
|
+
|
9
|
+
def save(output_source_path:, template_generator:, generate_colors:)
|
10
|
+
FileUtils.mkdir_p output_source_path unless File.exist? output_source_path
|
11
|
+
|
12
|
+
file_base_name = generate_colors ? 'UIColor' : 'UIImage'
|
13
|
+
name = app_name.nil? ? 'Common' : app_name
|
14
|
+
|
15
|
+
if template_generator.h_template
|
16
|
+
write(output_source_path, template_generator.h_template, "#{file_base_name}+#{name}.h")
|
17
|
+
end
|
18
|
+
|
19
|
+
return unless template_generator.m_template
|
20
|
+
|
21
|
+
write(output_source_path, template_generator.m_template, "#{file_base_name}+#{name}.m")
|
22
|
+
end
|
23
|
+
|
24
|
+
def write(output_source_path, template, file_name)
|
25
|
+
file = ERB.new(template, nil, '-').result(binding)
|
26
|
+
File.write(File.join(output_source_path, file_name), file)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_objc_test_cases(names:, variable:)
|
30
|
+
text = ''
|
31
|
+
names.each do |name|
|
32
|
+
temp_array = name.split('/')
|
33
|
+
variable_name = temp_array.length == 1 ? clean_variable_name(name) : temp_array.unshift(temp_array.shift.downcase).join('')
|
34
|
+
text += variable % variable_name
|
23
35
|
end
|
36
|
+
text
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_m_file_objc(names:, variable_declaration:, variable_implementation:, bundle_name:)
|
40
|
+
text = ''
|
41
|
+
|
42
|
+
names.each do |name|
|
43
|
+
temp_arr = name.split('/')
|
44
|
+
|
45
|
+
variable_name = temp_arr.length == 1 ? clean_variable_name(name) : temp_arr.unshift(temp_arr.shift.downcase).join('')
|
46
|
+
text += variable_declaration % variable_name + variable_implementation % [name, bundle_name[:reference]]
|
47
|
+
text += name == names.last ? '' : "\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
text
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_h_file_objc(names:, variable:)
|
54
|
+
text = ''
|
55
|
+
|
56
|
+
names.each do |name|
|
57
|
+
temp_arr = name.split('/')
|
58
|
+
variable_name = temp_arr.length == 1 ? clean_variable_name(name) : temp_arr.unshift(temp_arr.shift.downcase).join('')
|
59
|
+
text += variable % variable_name
|
60
|
+
end
|
61
|
+
|
62
|
+
text
|
63
|
+
end
|
64
|
+
|
65
|
+
def generate_category(type, class_name, app_name)
|
66
|
+
text = "@#{type} #{class_name} ("
|
67
|
+
|
68
|
+
return text += 'Common)\n' if app_name.nil? || app_name.empty?
|
24
69
|
|
70
|
+
text + app_name + ")\n"
|
71
|
+
end
|
25
72
|
end
|
26
73
|
end
|
27
74
|
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module Redbreast
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
2
|
+
module Serializer
|
3
|
+
# Used for initializing a serializer which will save files for respective languages
|
4
|
+
class Base
|
5
|
+
include ERB::Util
|
6
|
+
attr_accessor :asset_names, :bundle
|
7
|
+
|
8
|
+
def initialize(asset_names, bundle, app_name)
|
9
|
+
@asset_names = asset_names
|
10
|
+
@bundle = bundle
|
11
|
+
@app_name = app_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def save(*)
|
15
|
+
raise NotImplementedError, 'Abstract Method'
|
16
|
+
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require_relative 'serializer'
|
1
|
+
require_relative 'serializer'
|
2
2
|
|
3
3
|
module Redbreast
|
4
4
|
module Serializer
|
5
|
+
# Used to save swift files
|
5
6
|
class Swift < Base
|
6
7
|
include Helper::General
|
7
8
|
|
8
|
-
def save(output_source_path
|
9
|
+
def save(output_source_path:, template_generator:, generate_colors:)
|
9
10
|
directory = File.dirname(output_source_path)
|
10
11
|
FileUtils.mkdir_p directory unless File.exist? directory
|
11
12
|
|
@@ -13,6 +14,93 @@ module Redbreast
|
|
13
14
|
File.write(output_source_path, file)
|
14
15
|
end
|
15
16
|
|
17
|
+
def generate_file_swift(names:, spacing: "\t", indentation: '', variable:, bundle:)
|
18
|
+
return if names.empty?
|
19
|
+
|
20
|
+
text = ''
|
21
|
+
arr = []
|
22
|
+
|
23
|
+
vars, arr = generate_variables(names: names, spacing: spacing, indentation: indentation, variable: variable, bundle: bundle, text: text, array: arr)
|
24
|
+
|
25
|
+
arr = arr.uniq
|
26
|
+
arr.each do |enum_name|
|
27
|
+
names_new = []
|
28
|
+
names_new_enum = []
|
29
|
+
new_enum_name = enum_name
|
30
|
+
|
31
|
+
text += "\n" + spacing + 'enum ' + enum_name + ' {'
|
32
|
+
names_new, names_new_enum = separate_variables_from_folders(names: names, enum_name: enum_name, new_enum_name: new_enum_name, names_new_enum: names_new_enum, names_new: names_new)
|
33
|
+
|
34
|
+
if !names_new_enum.empty? && new_enum_name == enum_name
|
35
|
+
indentation += indentation.empty? || indentation[-1] == '/' ? '' : '/'
|
36
|
+
text += "\n" + generate_file_swift(names: names_new_enum, spacing: spacing + "\t", indentation: indentation + enum_name, variable: variable, bundle: bundle)
|
37
|
+
end
|
38
|
+
|
39
|
+
unless names_new.empty?
|
40
|
+
|
41
|
+
indentation += indentation.empty? || indentation[-1] == '/' ? '' : '/'
|
42
|
+
text += generate_file_swift(names: names_new, spacing: spacing + "\t", indentation: indentation + enum_name, variable: variable, bundle: bundle)
|
43
|
+
end
|
44
|
+
|
45
|
+
text += "\n" + spacing + '}' + "\n"
|
46
|
+
end
|
47
|
+
text = vars
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_extension(extended_class, app_name)
|
51
|
+
text = 'extension ' + extended_class + " {\n"
|
52
|
+
|
53
|
+
return text if app_name.nil? || app_name.empty?
|
54
|
+
|
55
|
+
text + "\tenum " + app_name + " {}\n}\n\nextension " + extended_class + '.' + app_name + " {"
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_swift_test_cases(names:, declaration:, app_name:)
|
59
|
+
text = ''
|
60
|
+
app_name_text = app_name.nil? || app_name.empty? ? '' : app_name + '.'
|
61
|
+
|
62
|
+
names.each do |name|
|
63
|
+
temp_array = name.split('/')
|
64
|
+
variable = temp_array.pop
|
65
|
+
additional_text = temp_array.count.zero? ? '' : '.'
|
66
|
+
text += "\t\t" + declaration + app_name_text + temp_array.join('.') + additional_text + clean_variable_name(variable)
|
67
|
+
text += name == names.last ? '' : "\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
text
|
71
|
+
end
|
72
|
+
|
73
|
+
def generate_variables(names:, spacing:, indentation:, bundle:, variable:, text:, array:)
|
74
|
+
names.each do |name|
|
75
|
+
temp_arr = name.split('/')
|
76
|
+
|
77
|
+
if temp_arr.length != 1
|
78
|
+
array.push(temp_arr.first)
|
79
|
+
else
|
80
|
+
name_prefix = indentation.empty? ? '' : '/'
|
81
|
+
text += "\n" + spacing + variable % [clean_variable_name(name), indentation + name_prefix + name, bundle[:reference]]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
[text, array]
|
86
|
+
end
|
87
|
+
|
88
|
+
def separate_variables_from_folders(names:, enum_name:, new_enum_name:, names_new_enum:, names_new:)
|
89
|
+
names.each do |name|
|
90
|
+
temp_arr = name.split('/')
|
91
|
+
|
92
|
+
next if temp_arr.length == 1
|
93
|
+
|
94
|
+
if temp_arr.length > 2
|
95
|
+
names_new_enum.push(temp_arr.drop(1).join('/')) if temp_arr.first == new_enum_name
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
names_new.push(temp_arr.drop(1).join('/')) if temp_arr[0] == enum_name
|
100
|
+
end
|
101
|
+
|
102
|
+
[names_new, names_new_enum]
|
103
|
+
end
|
16
104
|
end
|
17
105
|
end
|
18
106
|
end
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../objc_template_generator'
|
2
|
+
|
3
|
+
module Redbreast
|
4
|
+
module TemplateGenerator
|
5
|
+
module Color
|
6
|
+
# Used for creating colors in objective-c.
|
7
|
+
class ObjC < TemplateGenerator::ObjC
|
8
|
+
include ERB::Util
|
9
|
+
def h_template
|
10
|
+
<<~TEMPLATE
|
11
|
+
|
12
|
+
#import <UIKit/UIKit.h>
|
13
|
+
|
14
|
+
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
15
|
+
<%= generate_category('interface', 'UIColor', app_name) %>
|
16
|
+
<%= generate_h_file_objc(names: asset_names, variable: '+ (UIColor *)%s;\n')%>
|
17
|
+
@end
|
18
|
+
TEMPLATE
|
19
|
+
end
|
20
|
+
|
21
|
+
def m_template
|
22
|
+
<<~TEMPLATE
|
23
|
+
|
24
|
+
#import <UIKit/UIKit.h>
|
25
|
+
|
26
|
+
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
27
|
+
<%= generate_category('implementation', 'UIColor', app_name) %>
|
28
|
+
<%= generate_m_file_objc(names: asset_names, variable_declaration: '+ (UIColor *)%s\n{', variable_implementation: '\n\treturn [UIColor colorNamed:@"%s" inBundle:%s compatibleWithTraitCollection:nil];\n}\n', bundle_name: bundle) %>
|
29
|
+
@end
|
30
|
+
TEMPLATE
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../swift_template_generator'
|
2
|
+
|
3
|
+
module Redbreast
|
4
|
+
module TemplateGenerator
|
5
|
+
module Color
|
6
|
+
# Used for creating colors in swift.
|
7
|
+
class Swift < TemplateGenerator::Swift
|
8
|
+
include ERB::Util
|
9
|
+
def template
|
10
|
+
<<~TEMPLATE
|
11
|
+
import UIKit
|
12
|
+
|
13
|
+
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
14
|
+
<%= generate_extension('UIColor', app_name) %>
|
15
|
+
<%= generate_file_swift(names: asset_names, variable: 'static var %s: UIColor { return UIColor(named: "%s", in: %s, compatibleWith: nil)! }', bundle: bundle) %>
|
16
|
+
}
|
17
|
+
TEMPLATE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,49 +1,35 @@
|
|
1
1
|
require_relative '../objc_template_generator'
|
2
2
|
|
3
3
|
module Redbreast
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#import <UIKit/UIKit.h>
|
13
|
-
|
14
|
-
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@end
|
22
|
-
|
23
|
-
TEMPLATE
|
24
|
-
end
|
25
|
-
|
26
|
-
def m_template()
|
27
|
-
<<-TEMPLATE
|
28
|
-
|
29
|
-
#import <UIKit/UIKit.h>
|
30
|
-
|
31
|
-
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
32
|
-
@implementation UIImage (<%= File.basename(bundle[:outputSourcePath]) %>)
|
33
|
-
|
34
|
-
<%- image_names.each do |name| -%>
|
35
|
-
+(instancetype)<%= clean_variable_name(name) %>
|
36
|
-
{
|
37
|
-
[UIImage imageNamed:@"<%= name %>" inBundle:<%= bundle[:reference] %> compatibleWithTraitCollection:nil];
|
38
|
-
}
|
39
|
-
<%- end -%>
|
4
|
+
module TemplateGenerator
|
5
|
+
module Image
|
6
|
+
# Used for creating images in objective-c.
|
7
|
+
class ObjC < TemplateGenerator::ObjC
|
8
|
+
include ERB::Util
|
9
|
+
def h_template
|
10
|
+
<<~TEMPLATE
|
11
|
+
|
12
|
+
#import <UIKit/UIKit.h>
|
13
|
+
|
14
|
+
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
15
|
+
<%= generate_category('interface', 'UIImage', app_name) %>
|
16
|
+
<%= generate_h_file_objc(names: asset_names, variable: '+ (UIColor *)%s;\n')%>
|
17
|
+
@end
|
18
|
+
TEMPLATE
|
19
|
+
end
|
40
20
|
|
41
|
-
|
21
|
+
def m_template
|
22
|
+
<<~TEMPLATE
|
42
23
|
|
43
|
-
|
44
|
-
end
|
24
|
+
#import <UIKit/UIKit.h>
|
45
25
|
|
46
|
-
|
26
|
+
//THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
|
27
|
+
<%= generate_category('implementation', 'UIImage', app_name) %>
|
28
|
+
<%= generate_m_file_objc(names: asset_names, variable_declaration: '+ (UIImage *)%s\n{', variable_implementation: '\n\treturn [UIColor imageNamed:@"%s" inBundle:%s compatibleWithTraitCollection:nil];\n}\n', bundle_name: bundle) %>
|
29
|
+
@end
|
30
|
+
TEMPLATE
|
47
31
|
end
|
32
|
+
end
|
48
33
|
end
|
49
|
-
end
|
34
|
+
end
|
35
|
+
end
|