solara 0.7.4 → 0.8.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 +4 -4
- data/solara/lib/core/scripts/code_generator/swift_code_generator.rb +120 -120
- data/solara/lib/solara/version.rb +1 -1
- metadata +5 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fab777e1d69e66685057160bd2e985538210106df8a397be359fd0185f802614
|
4
|
+
data.tar.gz: 26d2c512ddf0a43810b2c4bf5ab53d804aa37be2a82eb46a6eab40f2aaf0517a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 204e786990bda9915a0d30c27a02b62d3c1f381be578d051a58bc1230075e68aea5ca0a95783c305f12cebd20e1f393393e893158f88c4af2554e0b17591f8ed
|
7
|
+
data.tar.gz: cd30fcc67754e010bea2c10dc9d3bd86ee7b62c4ad12f8bf4fa74f0bef853b5c0542ec8f12277ce7115111d6783eebf8405e576880dfc14f54260f5d0c3c7e6d
|
@@ -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
|
-
|
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
|
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"
|
77
42
|
else
|
78
|
-
|
79
|
-
|
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
|
43
|
+
static_values << "private static let #{key}Value = #{swift_value(value)}"
|
44
|
+
instance_values << "#{key}: #{key}Value"
|
92
45
|
end
|
93
46
|
|
94
|
-
|
95
|
-
struct #{class_name} {
|
96
|
-
#{properties.join("\n ")}
|
97
|
-
|
98
|
-
#{static_instances}
|
99
|
-
}
|
100
|
-
SWIFT
|
101
|
-
|
102
|
-
@generated_classes << class_code
|
47
|
+
properties << "let #{key}: #{type}"
|
103
48
|
end
|
104
49
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
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
|
124
104
|
|
125
|
-
|
126
|
-
|
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
|
124
|
+
|
125
|
+
@registry.get_type(value, base_type)
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
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})"
|
143
136
|
end
|
144
|
-
|
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
|
143
|
+
end
|
144
|
+
end
|
metadata
CHANGED
@@ -1,14 +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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Malek Kamel
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-08 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: thor
|
@@ -72,14 +71,14 @@ dependencies:
|
|
72
71
|
requirements:
|
73
72
|
- - "~>"
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
74
|
+
version: 1.27.0
|
76
75
|
type: :runtime
|
77
76
|
prerelease: false
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
79
78
|
requirements:
|
80
79
|
- - "~>"
|
81
80
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
81
|
+
version: 1.27.0
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
83
|
name: cgi
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -358,7 +357,6 @@ homepage: https://github.com/yourusername/solara
|
|
358
357
|
licenses:
|
359
358
|
- MIT
|
360
359
|
metadata: {}
|
361
|
-
post_install_message:
|
362
360
|
rdoc_options: []
|
363
361
|
require_paths:
|
364
362
|
- solara/lib
|
@@ -373,8 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
373
371
|
- !ruby/object:Gem::Version
|
374
372
|
version: '0'
|
375
373
|
requirements: []
|
376
|
-
rubygems_version: 3.5
|
377
|
-
signing_key:
|
374
|
+
rubygems_version: 3.6.5
|
378
375
|
specification_version: 4
|
379
376
|
summary: Solara is a Ruby library that simplifies the management of white label apps
|
380
377
|
for Flutter, iOS, Android, and Web.
|