redbreast 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a61b421737d7f28ab41362cb78ad00e3fd2246588e6346938dbe3589c82320e7
4
- data.tar.gz: ca241430323a6822e1b1943e67ebf1dddec6ea663e26fde0cd3d792d97f30f17
3
+ metadata.gz: 55140102c283d2812b099b0ec63dc475d12faef4beac0cc12d39cca5b87c2f61
4
+ data.tar.gz: 70704e2afa3b62adc8693d87cdf47891e255abdaf0b416cc11ae4190acd9d634
5
5
  SHA512:
6
- metadata.gz: 5cdb3304c7d176836430c1ec41826071a8544f171b0f9004f87a5a11da2bb7a817e79cfc28ca4662a44f5084b85bdf83f491a831a930b94b80e009610bcc1f0a
7
- data.tar.gz: a3257f6b265ed44b1f1a7fe12326002838e3f25c063001051c2b550ff716898621491157e4948855706f52fe748ff5ded3560db968e4fa40b1c986ce9815c5f3
6
+ metadata.gz: b7945675763fad73af01dcdd6018dbd032d782449f028f0e0d7d289cf028c4b7ce6d4ae5f129a2b47755e14a31b93cbc9bf1f6b6fe33e544558145635d5c6a78
7
+ data.tar.gz: 51d20e13ab388b0e2bd71a696bda633eed452f4d2be7b6e0179ffd0d6b7f2dffe056e7f0f144c6fdf47272c0168e0b7e95afb369f269c493c8c52531b74546eb
data/lib/redbreast.rb CHANGED
@@ -27,18 +27,24 @@ require 'redbreast/crawlers/color_crawler'
27
27
  require 'redbreast/serializers/serializer'
28
28
  require 'redbreast/serializers/objc_serializer'
29
29
  require 'redbreast/serializers/swift_serializer'
30
+ require 'redbreast/serializers/swiftui_serializer'
30
31
 
31
32
  # Template generators
32
33
  require 'redbreast/template_generators/objc_template_generator'
33
34
  require 'redbreast/template_generators/swift_template_generator'
35
+ require 'redbreast/template_generators/swiftui_template_generator'
34
36
  require 'redbreast/template_generators/images/objc_images_template_generator'
35
37
  require 'redbreast/template_generators/images/swift_images_template_generator'
38
+ require 'redbreast/template_generators/images/swiftui_images_template_generator'
36
39
  require 'redbreast/template_generators/colors/objc_colors_template_generator'
37
40
  require 'redbreast/template_generators/colors/swift_colors_template_generator'
41
+ require 'redbreast/template_generators/colors/swiftui_colors_template_generator'
38
42
  require 'redbreast/template_generators/tests/colors/objc_colors_tests_template_generator'
39
43
  require 'redbreast/template_generators/tests/colors/swift_colors_tests_template_generator'
44
+ require 'redbreast/template_generators/tests/colors/swiftui_colors_tests_template_generator'
40
45
  require 'redbreast/template_generators/tests/images/objc_images_tests_template_generator'
41
46
  require 'redbreast/template_generators/tests/images/swift_images_tests_template_generator'
47
+ require 'redbreast/template_generators/tests/images/swiftui_images_tests_template_generator'
42
48
 
43
49
  # Error Handler
44
50
  require 'redbreast/error_handler'
@@ -39,6 +39,9 @@ module Redbreast
39
39
  when 'swift'
40
40
  serializer = Redbreast::Serializer::Swift
41
41
  template_generator = Redbreast::TemplateGenerator::Color::Swift
42
+ when 'swiftui'
43
+ serializer = Redbreast::Serializer::SwiftUI
44
+ template_generator = Redbreast::TemplateGenerator::Color::SwiftUI
42
45
  end
43
46
  serializer.new(color_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: true)
44
47
  end
@@ -41,6 +41,9 @@ module Redbreast
41
41
  when 'swift'
42
42
  serializer = Redbreast::Serializer::Swift
43
43
  template_generator = Redbreast::TemplateGenerator::ColorTest::Swift
44
+ when 'swiftui'
45
+ serializer = Redbreast::Serializer::SwiftUI
46
+ template_generator = Redbreast::TemplateGenerator::ColorTest::SwiftUI
44
47
  end
45
48
  serializer.new(color_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: true)
46
49
 
@@ -39,6 +39,9 @@ module Redbreast
39
39
  when 'swift'
40
40
  serializer = Redbreast::Serializer::Swift
41
41
  template_generator = Redbreast::TemplateGenerator::Image::Swift
42
+ when 'swiftui'
43
+ serializer = Redbreast::Serializer::SwiftUI
44
+ template_generator = Redbreast::TemplateGenerator::Image::SwiftUI
42
45
  end
43
46
  serializer.new(image_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: false)
44
47
 
@@ -41,6 +41,9 @@ module Redbreast
41
41
  when 'swift'
42
42
  serializer = Redbreast::Serializer::Swift
43
43
  template_generator = Redbreast::TemplateGenerator::ImageTest::Swift
44
+ when 'swiftui'
45
+ serializer = Redbreast::Serializer::SwiftUI
46
+ template_generator = Redbreast::TemplateGenerator::ImageTest::SwiftUI
44
47
  end
45
48
  serializer.new(image_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: false)
46
49
 
@@ -56,7 +56,7 @@ module Redbreast
56
56
  # Language
57
57
 
58
58
  def language_prompt
59
- languages = { 'Swift' => 'swift', 'Objective-C' => 'objc' }
59
+ languages = { 'Swift' => 'swift', 'SwiftUI' => 'swiftui', 'Objective-C' => 'objc', }
60
60
  prompt.select('Choose a language: ', languages)
61
61
  end
62
62
 
@@ -76,6 +76,8 @@ module Redbreast
76
76
  prompt.ask(prompt_text, default: 'mainBundle')
77
77
  when 'swift'
78
78
  prompt.ask(prompt_text, default: 'main')
79
+ when 'swiftui'
80
+ prompt.ask(prompt_text, default: 'main')
79
81
  end
80
82
  end
81
83
 
@@ -85,6 +87,8 @@ module Redbreast
85
87
  "[NSBundle #{bundle_name}]"
86
88
  when 'swift'
87
89
  ".#{bundle_name}"
90
+ when 'swiftui'
91
+ ".#{bundle_name}"
88
92
  end
89
93
  end
90
94
 
@@ -97,6 +101,8 @@ module Redbreast
97
101
  prompt.ask(prompt_text, default: './Common/Categories/Images')
98
102
  when 'swift'
99
103
  prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtension.swift')
104
+ when 'swiftui'
105
+ prompt.ask(prompt_text, default: './Common/Extensions/ImageExtension.swift')
100
106
  end
101
107
  end
102
108
 
@@ -109,6 +115,8 @@ module Redbreast
109
115
  prompt.ask(prompt_text, default: './Common/Categories/Colors')
110
116
  when 'swift'
111
117
  prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtension.swift')
118
+ when 'swiftui'
119
+ prompt.ask(prompt_text, default: './Common/Extensions/ColorExtension.swift')
112
120
  end
113
121
  end
114
122
 
@@ -125,6 +133,8 @@ module Redbreast
125
133
  prompt.ask(prompt_text, default: './Common/Categories/ImagesTest')
126
134
  when 'swift'
127
135
  prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtensionTest.swift')
136
+ when 'swiftui'
137
+ prompt.ask(prompt_text, default: './Common/Extensions/ImageExtensionTest.swift')
128
138
  end
129
139
  end
130
140
 
@@ -135,6 +145,8 @@ module Redbreast
135
145
  prompt.ask(prompt_text, default: './Common/Categories/ColorsTest')
136
146
  when 'swift'
137
147
  prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtensionTest.swift')
148
+ when 'swiftui'
149
+ prompt.ask(prompt_text, default: './Common/Extensions/ColorExtensionTest.swift')
138
150
  end
139
151
  end
140
152
 
@@ -144,6 +156,8 @@ module Redbreast
144
156
  nil
145
157
  when 'swift'
146
158
  prompt.ask("Please enter a name that will be used for testable import in #{bundle} bundle?", default: "#{app_name}", required: true)
159
+ when 'swiftui'
160
+ prompt.ask("Please enter a name that will be used for testable import in #{bundle} bundle?", default: "#{app_name}", required: true)
147
161
  end
148
162
  end
149
163
 
@@ -2,7 +2,7 @@ module Redbreast
2
2
  module IO
3
3
  # Used for reading and writing to config file
4
4
  class Config
5
- CONFIG_FILE_PATH = "#{Dir.pwd}/.redbrest.yml"
5
+ CONFIG_FILE_PATH = "#{Dir.pwd}/.redbreast.yml"
6
6
 
7
7
  class << self
8
8
  def write(data)
@@ -23,6 +23,7 @@ module Redbreast
23
23
  vars, arr = generate_variables(names: names, spacing: spacing, indentation: indentation, variable: variable, bundle: bundle, text: text, array: arr)
24
24
 
25
25
  arr = arr.uniq
26
+ #text += indentation.empty? && text.empty? ? "\n" : ''
26
27
  arr.each do |enum_name|
27
28
  names_new = []
28
29
  names_new_enum = []
@@ -44,7 +45,7 @@ module Redbreast
44
45
 
45
46
  text += "\n" + spacing + '}' + "\n"
46
47
  end
47
- text = vars
48
+ text + vars
48
49
  end
49
50
 
50
51
  def generate_extension(extended_class, app_name)
@@ -0,0 +1,107 @@
1
+ require_relative 'serializer'
2
+
3
+ module Redbreast
4
+ module Serializer
5
+ # Used to save swift files
6
+ class SwiftUI < Base
7
+ include Helper::General
8
+
9
+ def save(output_source_path:, template_generator:, generate_colors:)
10
+ directory = File.dirname(output_source_path)
11
+ FileUtils.mkdir_p directory unless File.exist? directory
12
+
13
+ file = ERB.new(template_generator.template, nil, '-').result(binding)
14
+ File.write(output_source_path, file)
15
+ end
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
+ #text += indentation.empty? && text.empty? ? "\n" : ''
27
+ arr.each do |enum_name|
28
+ names_new = []
29
+ names_new_enum = []
30
+ new_enum_name = enum_name
31
+
32
+ text += "\n" + spacing + 'enum ' + enum_name + ' {'
33
+ 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)
34
+
35
+ if !names_new_enum.empty? && new_enum_name == enum_name
36
+ indentation += indentation.empty? || indentation[-1] == '/' ? '' : '/'
37
+ text += "\n" + generate_file_swift(names: names_new_enum, spacing: spacing + "\t", indentation: indentation + enum_name, variable: variable, bundle: bundle)
38
+ end
39
+
40
+ unless names_new.empty?
41
+
42
+ indentation += indentation.empty? || indentation[-1] == '/' ? '' : '/'
43
+ text += generate_file_swift(names: names_new, spacing: spacing + "\t", indentation: indentation + enum_name, variable: variable, bundle: bundle)
44
+ end
45
+
46
+ text += "\n" + spacing + '}' + "\n"
47
+ end
48
+ text + vars
49
+ end
50
+
51
+ def generate_extension(extended_class, app_name)
52
+ text = 'extension ' + extended_class + " {\n"
53
+
54
+ return text if app_name.nil? || app_name.empty?
55
+
56
+ text + "\tenum " + app_name + " {}\n}\n\nextension " + extended_class + '.' + app_name + " {"
57
+ end
58
+
59
+ def create_swift_test_cases(names:, declaration:, app_name:)
60
+ text = ''
61
+ app_name_text = app_name.nil? || app_name.empty? ? '' : app_name + '.'
62
+
63
+ names.each do |name|
64
+ temp_array = name.split('/')
65
+ variable = temp_array.pop
66
+ additional_text = temp_array.count.zero? ? '' : '.'
67
+ text += "\t\t" + declaration + app_name_text + temp_array.join('.') + additional_text + clean_variable_name(variable)
68
+ text += name == names.last ? '' : "\n"
69
+ end
70
+
71
+ text
72
+ end
73
+
74
+ def generate_variables(names:, spacing:, indentation:, bundle:, variable:, text:, array:)
75
+ names.each do |name|
76
+ temp_arr = name.split('/')
77
+
78
+ if temp_arr.length != 1
79
+ array.push(temp_arr.first)
80
+ else
81
+ name_prefix = indentation.empty? ? '' : '/'
82
+ text += "\n" + spacing + variable % [clean_variable_name(name), indentation + name_prefix + name, bundle[:reference]]
83
+ end
84
+ end
85
+
86
+ [text, array]
87
+ end
88
+
89
+ def separate_variables_from_folders(names:, enum_name:, new_enum_name:, names_new_enum:, names_new:)
90
+ names.each do |name|
91
+ temp_arr = name.split('/')
92
+
93
+ next if temp_arr.length == 1
94
+
95
+ if temp_arr.length > 2
96
+ names_new_enum.push(temp_arr.drop(1).join('/')) if temp_arr.first == new_enum_name
97
+ next
98
+ end
99
+
100
+ names_new.push(temp_arr.drop(1).join('/')) if temp_arr[0] == enum_name
101
+ end
102
+
103
+ [names_new, names_new_enum]
104
+ end
105
+ end
106
+ end
107
+ end
@@ -10,7 +10,8 @@ module Redbreast
10
10
  <<~TEMPLATE
11
11
  import UIKit
12
12
 
13
- //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
13
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
14
+ // swiftlint:disable file_length type_body_length line_length superfluous_disable_command
14
15
  <%= generate_extension('UIColor', app_name) %>
15
16
  <%= generate_file_swift(names: asset_names, variable: 'static var %s: UIColor { return UIColor(named: "%s", in: %s, compatibleWith: nil)! }', bundle: bundle) %>
16
17
  }
@@ -0,0 +1,23 @@
1
+ require_relative '../swiftui_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Color
6
+ # Used for creating colors in swift.
7
+ class SwiftUI < TemplateGenerator::SwiftUI
8
+ include ERB::Util
9
+ def template
10
+ <<~TEMPLATE
11
+ import SwiftUI
12
+
13
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
14
+ // swiftlint:disable file_length type_body_length line_length superfluous_disable_command
15
+ <%= generate_extension('Color', app_name) %>
16
+ <%= generate_file_swift(names: asset_names, variable: 'static var %s: Color { Color("%s", bundle: %s) }', bundle: bundle) %>
17
+ }
18
+ TEMPLATE
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -11,7 +11,8 @@ module Redbreast
11
11
  <<~TEMPLATE
12
12
  import UIKit
13
13
 
14
- //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
14
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ // swiftlint:disable file_length type_body_length line_length superfluous_disable_command
15
16
  <%= generate_extension('UIImage', app_name) %>
16
17
  <%= generate_file_swift(names: asset_names, variable: 'static var %s: UIImage { return UIImage(named: "%s", in: %s, compatibleWith: nil)! }', bundle: bundle) %>
17
18
  }
@@ -0,0 +1,24 @@
1
+ require_relative '../swiftui_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Image
6
+ # Used for creating images in swift.
7
+ class SwiftUI < TemplateGenerator::SwiftUI
8
+ include ERB::Util
9
+
10
+ def template
11
+ <<~TEMPLATE
12
+ import SwiftUI
13
+
14
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ // swiftlint:disable file_length type_body_length line_length superfluous_disable_command
16
+ <%= generate_extension('Image', app_name) %>
17
+ <%= generate_file_swift(names: asset_names, variable: 'static var %s: Image { Image("%s", bundle: %s) }', bundle: bundle) %>
18
+ }
19
+ TEMPLATE
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Redbreast
2
+ module TemplateGenerator
3
+ # Class for creating SwiftUI templates
4
+ class SwiftUI
5
+ include ERB::Util
6
+ def template
7
+ raise NotImplementedError, 'Abstract Method'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -12,7 +12,7 @@ module Redbreast
12
12
  import XCTest
13
13
  @testable import <%= bundle[:testableImport] %>
14
14
 
15
- //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
16
16
  class <%= File.basename(bundle[:outputTestPathColors], ".*") %>: XCTestCase {
17
17
 
18
18
  func testIfColorsArePresent() {
@@ -0,0 +1,27 @@
1
+ require 'redbreast/template_generators/swiftui_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module ColorTest
6
+ # Used for creating color tests in swift.
7
+ class SwiftUI < TemplateGenerator::SwiftUI
8
+ include ERB::Util
9
+ def template
10
+ <<~TEMPLATE
11
+ import SwiftUI
12
+ import XCTest
13
+ @testable import <%= bundle[:testableImport] %>
14
+
15
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
16
+ class <%= File.basename(bundle[:outputTestPathColors], ".*") %>: XCTestCase {
17
+
18
+ func testIfColorsArePresent() {
19
+ <%= create_swift_test_cases(names: asset_names, declaration: '_ = Color.', app_name: app_name) %>
20
+ }
21
+ }
22
+ TEMPLATE
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -12,7 +12,7 @@ module Redbreast
12
12
  import XCTest
13
13
  @testable import <%= bundle[:testableImport] %>
14
14
 
15
- //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
16
16
  class <%= File.basename(bundle[:outputTestPathImages], ".*") %>: XCTestCase {
17
17
 
18
18
  func testIfImagesArePresent() {
@@ -0,0 +1,27 @@
1
+ require 'redbreast/template_generators/swiftui_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module ImageTest
6
+ # Used for creating image tests in swift.
7
+ class SwiftUI < TemplateGenerator::SwiftUI
8
+ include ERB::Util
9
+ def template
10
+ <<~TEMPLATE
11
+ import SwiftUI
12
+ import XCTest
13
+ @testable import <%= bundle[:testableImport] %>
14
+
15
+ // THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
16
+ class <%= File.basename(bundle[:outputTestPathImages], ".*") %>: XCTestCase {
17
+
18
+ func testIfImagesArePresent() {
19
+ <%= create_swift_test_cases(names: asset_names, declaration: '_ = Image.', app_name: app_name) %>
20
+ }
21
+ }
22
+ TEMPLATE
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Redbreast
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redbreast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maroje
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-21 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,17 +162,23 @@ files:
162
162
  - lib/redbreast/serializers/objc_serializer.rb
163
163
  - lib/redbreast/serializers/serializer.rb
164
164
  - lib/redbreast/serializers/swift_serializer.rb
165
+ - lib/redbreast/serializers/swiftui_serializer.rb
165
166
  - lib/redbreast/template_generators/.DS_Store
166
167
  - lib/redbreast/template_generators/colors/objc_colors_template_generator.rb
167
168
  - lib/redbreast/template_generators/colors/swift_colors_template_generator.rb
169
+ - lib/redbreast/template_generators/colors/swiftui_colors_template_generator.rb
168
170
  - lib/redbreast/template_generators/images/objc_images_template_generator.rb
169
171
  - lib/redbreast/template_generators/images/swift_images_template_generator.rb
172
+ - lib/redbreast/template_generators/images/swiftui_images_template_generator.rb
170
173
  - lib/redbreast/template_generators/objc_template_generator.rb
171
174
  - lib/redbreast/template_generators/swift_template_generator.rb
175
+ - lib/redbreast/template_generators/swiftui_template_generator.rb
172
176
  - lib/redbreast/template_generators/tests/colors/objc_colors_tests_template_generator.rb
173
177
  - lib/redbreast/template_generators/tests/colors/swift_colors_tests_template_generator.rb
178
+ - lib/redbreast/template_generators/tests/colors/swiftui_colors_tests_template_generator.rb
174
179
  - lib/redbreast/template_generators/tests/images/objc_images_tests_template_generator.rb
175
180
  - lib/redbreast/template_generators/tests/images/swift_images_tests_template_generator.rb
181
+ - lib/redbreast/template_generators/tests/images/swiftui_images_tests_template_generator.rb
176
182
  - lib/redbreast/version.rb
177
183
  - redbreast.gemspec
178
184
  homepage: https://github.com/infinum/redbreast