redbreast 1.0.4 → 1.1.0

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: 0fd59963c4cad4dc5c196f5c305d2a8a84c2ccbccebece9548732c0ecbec3511
4
- data.tar.gz: ef90116d1dd445f13be400d7f8dad518992d7b8df6d9927d9842de8580a7ca75
3
+ metadata.gz: 4e4247b8ea9785ed5c37e2d0a46ded030dfeff01c64ceeee4d144d803b23c411
4
+ data.tar.gz: 2509327fc0ebeb80b802a5e633c4d88b1e416831f3e8ed1fba75f32914148d43
5
5
  SHA512:
6
- metadata.gz: '0949245f9456ec294b8823ead66b1c44aff96b3c4b590cb5c3a57027ef478ad113edbe447325380fb1367a590e7e00704bcaa5dce919b7efeece459a04dce5f7'
7
- data.tar.gz: 84a54ee62f8d1a5e7138e296727fbf58b029c7e5f35cf7ab91c1d2f51d7f21b88b7c561d3247543ab60a09522a6f02b923efc3e397359aa91422c3b0454b59ac
6
+ metadata.gz: 937c6973d5e526e7f516226ece7a23682fecf9f0bd24eefc59b1c13083562a623a66a422846a71d6a79e3dfbb3fea198922252ec3977258dfcf8b40c946b1c04
7
+ data.tar.gz: 6e8f426eee7cd8ec036e866f546c4f87e702143edef687fdbc6af51766f479ef2dc0d98c162b3e458696c6f53aafffc61a349ec98f624d2c02d4ef187517e45d
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/UIColorExtension.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
 
@@ -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
@@ -0,0 +1,22 @@
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
+ <%= generate_extension('Color', app_name) %>
15
+ <%= generate_file_swift(names: asset_names, variable: 'static var %s: Color { Color("%s", bundle: %s) }', bundle: bundle) %>
16
+ }
17
+ TEMPLATE
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
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
+ <%= generate_extension('Image', app_name) %>
16
+ <%= generate_file_swift(names: asset_names, variable: 'static var %s: Image { Image("%s", bundle: %s) }', bundle: bundle) %>
17
+ }
18
+ TEMPLATE
19
+ end
20
+ end
21
+ end
22
+ end
23
+ 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
@@ -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
@@ -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.4'
2
+ VERSION = '1.1.0'
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.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maroje
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-07-05 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
@@ -195,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
201
  - !ruby/object:Gem::Version
196
202
  version: '0'
197
203
  requirements: []
198
- rubygems_version: 3.0.6
204
+ rubygems_version: 3.1.4
199
205
  signing_key:
200
206
  specification_version: 4
201
207
  summary: A CLI for safe and strongly typed resources