solara 0.8.0 → 0.10.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5686de4e3afa52cdec8223d3e990d10b3056c4a72d2332a4c376b674966aac
|
4
|
+
data.tar.gz: 740cbc01a18278920f9722b94f0987c10c55602ee727badb945db19866ee741a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 706950176d1fd66f1e10efa9b83d991f444e018bd9cb0282eb74d133a2181fa081a606c91db12f2f9d7e6ce9ae1829e147481949b94acd79d5930263339c9399
|
7
|
+
data.tar.gz: '08f25956658174869cc3a71223c842a58323448177dce4c5dbb07f6808f2e76105eaec0d3120e6dfe16865c08f4ada4bf11465c2732dd2351e1eec60c11d8af4'
|
@@ -14,131 +14,131 @@ class SwiftCodeGenerator
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
17
|
+
def generate_class(json_obj, class_name, list_items = nil)
|
18
|
+
@registry.register(class_name, class_name)
|
19
|
+
class_name = @registry.get_class_name(class_name, class_name)
|
20
|
+
return if @generated_classes.any? { |c| c.include?("struct #{class_name}") }
|
21
|
+
|
22
|
+
properties = []
|
23
|
+
static_values = []
|
24
|
+
instance_values = []
|
25
|
+
|
26
|
+
json_obj.each do |key, value|
|
27
|
+
nested_class_name = "#{class_name}#{StringCase.capitalize(key)}"
|
28
|
+
@registry.register(nested_class_name, nested_class_name)
|
29
|
+
nested_class_name = @registry.get_class_name(nested_class_name, nested_class_name)
|
30
|
+
|
31
|
+
type = determine_type(value, nested_class_name, "#{class_name}.#{key}")
|
32
|
+
|
33
|
+
if value.is_a?(Hash)
|
34
|
+
generate_class(value, nested_class_name)
|
35
|
+
static_values << "private static let #{key}Value = #{nested_class_name}.shared"
|
36
|
+
instance_values << "#{key}: #{nested_class_name}.shared"
|
37
|
+
elsif value.is_a?(Array) && !value.empty? && value.first.is_a?(Hash)
|
38
|
+
generate_class(value.first, nested_class_name, value)
|
39
|
+
type = "[#{nested_class_name}]"
|
40
|
+
static_values << "private static let #{key}Value = #{nested_class_name}.instances"
|
41
|
+
instance_values << "#{key}: #{nested_class_name}.instances"
|
42
|
+
else
|
43
|
+
static_values << "private static let #{key}Value = #{swift_value(value)}"
|
44
|
+
instance_values << "#{key}: #{key}Value"
|
45
|
+
end
|
46
|
+
|
47
|
+
properties << "let #{key}: #{type}"
|
48
|
+
end
|
49
|
+
|
50
|
+
static_instances = if list_items
|
51
|
+
items_code = list_items.map.with_index do |item, index|
|
52
|
+
values = item.map do |key, value|
|
53
|
+
if value.is_a?(Hash)
|
54
|
+
nested_class_name = "#{class_name}#{StringCase.capitalize(key)}"
|
55
|
+
@registry.register(nested_class_name, nested_class_name)
|
56
|
+
nested_class_name = @registry.get_class_name(nested_class_name, nested_class_name)
|
57
|
+
"#{key}: #{nested_class_name}.shared"
|
58
|
+
elsif value.is_a?(Array) && !value.empty? && value.first.is_a?(Hash)
|
59
|
+
nested_class_name = "#{class_name}#{StringCase.capitalize(key)}"
|
60
|
+
@registry.register(nested_class_name, nested_class_name)
|
61
|
+
nested_class_name = @registry.get_class_name(nested_class_name, nested_class_name)
|
62
|
+
"#{key}: #{nested_class_name}.instances"
|
63
|
+
else
|
64
|
+
"#{key}: #{swift_value(value)}"
|
65
|
+
end
|
66
|
+
end.join(",\n ")
|
67
|
+
" private static let instance#{index + 1} = #{class_name}(\n #{values}\n )"
|
68
|
+
end.join("\n")
|
69
|
+
|
70
|
+
instances_list = (1..list_items.length).map { |i| "instance#{i}" }.join(", ")
|
71
|
+
|
72
|
+
<<~SWIFT
|
73
|
+
#{items_code}
|
74
|
+
|
75
|
+
static let instances: [#{class_name}] = [#{instances_list}]
|
76
|
+
SWIFT
|
42
77
|
else
|
43
|
-
|
44
|
-
|
78
|
+
<<~SWIFT
|
79
|
+
private static var _shared: #{class_name}?
|
80
|
+
|
81
|
+
#{static_values.join("\n ")}
|
82
|
+
|
83
|
+
static var shared: #{class_name} {
|
84
|
+
if _shared == nil {
|
85
|
+
_shared = #{class_name}(
|
86
|
+
#{instance_values.join(",\n ")}
|
87
|
+
)
|
88
|
+
}
|
89
|
+
return _shared!
|
90
|
+
}
|
91
|
+
SWIFT
|
45
92
|
end
|
46
93
|
|
47
|
-
|
94
|
+
class_code = <<~SWIFT
|
95
|
+
struct #{class_name} {
|
96
|
+
#{properties.join("\n ")}
|
97
|
+
|
98
|
+
#{static_instances}
|
99
|
+
}
|
100
|
+
SWIFT
|
101
|
+
|
102
|
+
@generated_classes << class_code
|
48
103
|
end
|
49
104
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
instances_list = (1..list_items.length).map { |i| "instance#{i}" }.join(", ")
|
71
|
-
|
72
|
-
<<~SWIFT
|
73
|
-
#{items_code}
|
74
|
-
|
75
|
-
static let instances: [#{class_name}] = [#{instances_list}]
|
76
|
-
SWIFT
|
77
|
-
else
|
78
|
-
<<~SWIFT
|
79
|
-
private static var _shared: #{class_name}?
|
80
|
-
|
81
|
-
#{static_values.join("\n ")}
|
82
|
-
|
83
|
-
static var shared: #{class_name} {
|
84
|
-
if _shared == nil {
|
85
|
-
_shared = #{class_name}(
|
86
|
-
#{instance_values.join(",\n ")}
|
87
|
-
)
|
88
|
-
}
|
89
|
-
return _shared!
|
90
|
-
}
|
91
|
-
SWIFT
|
92
|
-
end
|
93
|
-
|
94
|
-
class_code = <<~SWIFT
|
95
|
-
struct #{class_name} {
|
96
|
-
#{properties.join("\n ")}
|
97
|
-
|
98
|
-
#{static_instances}
|
99
|
-
}
|
100
|
-
SWIFT
|
101
|
-
|
102
|
-
@generated_classes << class_code
|
103
|
-
end
|
105
|
+
def determine_type(value, class_name, registry_key)
|
106
|
+
base_type = if value.is_a?(String) && ColorDetector.new(value).color?
|
107
|
+
"UIColor"
|
108
|
+
elsif value.is_a?(String)
|
109
|
+
"String"
|
110
|
+
elsif value.is_a?(Integer)
|
111
|
+
"Int"
|
112
|
+
elsif value.is_a?(Float)
|
113
|
+
"Double"
|
114
|
+
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
115
|
+
"Bool"
|
116
|
+
elsif value.is_a?(Array)
|
117
|
+
item_type = value.empty? ? "Any" : determine_type(value.first, class_name, "#{registry_key}[]")
|
118
|
+
"[#{item_type}]"
|
119
|
+
elsif value.is_a?(Hash)
|
120
|
+
class_name
|
121
|
+
else
|
122
|
+
"Any"
|
123
|
+
end
|
104
124
|
|
105
|
-
|
106
|
-
|
107
|
-
"UIColor"
|
108
|
-
elsif value.is_a?(String)
|
109
|
-
"String"
|
110
|
-
elsif value.is_a?(Integer)
|
111
|
-
"Int"
|
112
|
-
elsif value.is_a?(Float)
|
113
|
-
"Double"
|
114
|
-
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
115
|
-
"Bool"
|
116
|
-
elsif value.is_a?(Array)
|
117
|
-
item_type = value.empty? ? "Any" : determine_type(value.first, class_name, "#{registry_key}[]")
|
118
|
-
"[#{item_type}]"
|
119
|
-
elsif value.is_a?(Hash)
|
120
|
-
class_name
|
121
|
-
else
|
122
|
-
"Any"
|
123
|
-
end
|
124
|
-
|
125
|
-
@registry.get_type(value, base_type)
|
126
|
-
end
|
125
|
+
@registry.get_type(value, base_type)
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
128
|
+
def swift_value(value)
|
129
|
+
if value.is_a?(String) && ColorDetector.new(value).color?
|
130
|
+
hex = value.gsub('#', '')
|
131
|
+
r = "Double(0x#{hex[0,2]}) / 255.0"
|
132
|
+
g = "Double(0x#{hex[2,2]}) / 255.0"
|
133
|
+
b = "Double(0x#{hex[4,2]}) / 255.0"
|
134
|
+
a = hex.length == 8 ? "Double(0x#{hex[6,2]}) / 255.0" : "1.0"
|
135
|
+
return "UIColor(red: #{r}, green: #{g}, blue: #{b}, alpha: #{a})"
|
136
|
+
end
|
137
|
+
return "\"#{value}\"" if value.is_a?(String)
|
138
|
+
return value.to_s if value.is_a?(Integer) || value.is_a?(Float)
|
139
|
+
return value.to_s.downcase if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
140
|
+
return "[#{value.map { |v| swift_value(v) }.join(", ")}]" if value.is_a?(Array)
|
141
|
+
return "nil" if value.nil?
|
142
|
+
value.to_s
|
136
143
|
end
|
137
|
-
|
138
|
-
return value.to_s if value.is_a?(Integer) || value.is_a?(Float)
|
139
|
-
return value.to_s.downcase if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
140
|
-
return "[#{value.map { |v| swift_value(v) }.join(", ")}]" if value.is_a?(Array)
|
141
|
-
return "nil" if value.nil?
|
142
|
-
value.to_s
|
143
|
-
end
|
144
|
-
end
|
144
|
+
end
|
@@ -53,8 +53,31 @@ project.ext {
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
+
def write_if_needed(file_path, new_content)
|
57
|
+
return unless File.exist?(file_path)
|
58
|
+
|
59
|
+
current_content = File.read(file_path)
|
60
|
+
if normalize_content(new_content) != normalize_content(current_content)
|
61
|
+
File.write(file_path, new_content)
|
62
|
+
Solara.logger.debug("Updated #{file_path}")
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
Solara.logger.debug("No changes needed for #{file_path}")
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
def normalize_content(content)
|
71
|
+
# Remove empty lines and normalize whitespace
|
72
|
+
content.lines
|
73
|
+
.map(&:strip)
|
74
|
+
.reject(&:empty?)
|
75
|
+
.join("\n")
|
76
|
+
end
|
77
|
+
|
56
78
|
def update_gradle(gradle_file, gradle_content)
|
57
79
|
properties_loader = @is_kotlin_gradle ? KOTLIN_PROPERTIES_LOADER : GROOVY_PROPERTIES_LOADER
|
80
|
+
original_content = gradle_content.dup
|
58
81
|
|
59
82
|
if @is_kotlin_gradle
|
60
83
|
# Add imports for Kotlin
|
@@ -91,8 +114,10 @@ project.ext {
|
|
91
114
|
)
|
92
115
|
|
93
116
|
gradle_content.sub!(android_block_regex, updated_android_block)
|
94
|
-
|
95
|
-
|
117
|
+
|
118
|
+
if write_if_needed(gradle_file, gradle_content)
|
119
|
+
Solara.logger.debug("Updated #{gradle_file} (#{@is_kotlin_gradle ? 'Kotlin' : 'Groovy'}) to use brand.properties")
|
120
|
+
end
|
96
121
|
end
|
97
122
|
|
98
123
|
def add_source_sets(gradle_file)
|
@@ -124,8 +149,7 @@ project.ext {
|
|
124
149
|
end
|
125
150
|
end
|
126
151
|
|
127
|
-
|
128
|
-
Solara.logger.debug("Source sets configuration updated successfully.")
|
152
|
+
write_if_needed(gradle_file, modified_content)
|
129
153
|
end
|
130
154
|
|
131
155
|
def generate_source_sets(source_sets_string)
|
@@ -182,12 +206,7 @@ project.ext {
|
|
182
206
|
modified_content.sub!(/(\s*android\s*\{)/) { "#{$1}\n #{new_config.strip}" }
|
183
207
|
end
|
184
208
|
|
185
|
-
|
186
|
-
File.write(gradle_file, modified_content)
|
187
|
-
Solara.logger.debug("Keystore configuration updated successfully.")
|
188
|
-
else
|
189
|
-
Solara.logger.debug("No changes were necessary for keystore configuration.")
|
190
|
-
end
|
209
|
+
write_if_needed(gradle_file, modified_content)
|
191
210
|
end
|
192
211
|
|
193
212
|
def generate_keystore_config
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Malek Kamel
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: thor
|