stylegen 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +14 -14
- data/README.md +5 -1
- data/lib/stylegen/cli/template.yaml +5 -0
- data/lib/stylegen/colors/base_elevated_color.rb +2 -0
- data/lib/stylegen/colors/color.rb +14 -4
- data/lib/stylegen/data.rb +11 -3
- data/lib/stylegen/generator.rb +7 -109
- data/lib/stylegen/{schema.json → resources/schema.json} +15 -1
- data/lib/stylegen/template.rb +157 -0
- data/lib/stylegen/validator.rb +1 -1
- data/lib/stylegen/version.rb +1 -1
- data/stylegen.gemspec +1 -1
- data/test/test_color.rb +14 -5
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3c7f3c64e0c2b99ca8ab6fa2f200f4a47af401b9e1c2547983eaed4f6a339e
|
4
|
+
data.tar.gz: 870d75d1e851c2cf8d1f8958f0eed6ceff39b2537d28f81e199a6cb8f683caee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e18ecf6503daef89a5cc9fdc9f4fda1a90a2872ff701f750d924a2e3d4f4efedc3ca74cd9a4803fd4b3ee2001defc877e07d40feada9cfa96c845fa3c0e79d2
|
7
|
+
data.tar.gz: 8365c8bad165c4f518502185e5f639c5e9beebe664c6018d2ea9ec1175bc6f720fa8dc6fc21b879fb76a9dea59e1e071222a360f0235519fcae5a72a087e5440
|
data/.github/workflows/ci.yml
CHANGED
@@ -21,10 +21,7 @@ jobs:
|
|
21
21
|
steps:
|
22
22
|
- uses: actions/checkout@v2
|
23
23
|
- name: Set up Ruby
|
24
|
-
|
25
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
-
# uses: ruby/setup-ruby@v1
|
27
|
-
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
24
|
+
uses: ruby/setup-ruby@v1
|
28
25
|
with:
|
29
26
|
ruby-version: ${{ matrix.ruby-version }}
|
30
27
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## v0.4.0
|
5
|
+
### Added
|
6
|
+
- Added support for color descriptions.
|
7
|
+
|
8
|
+
## v0.3.1
|
9
|
+
### Changed
|
10
|
+
- Increased precision of HEX color conversion to avoid truncation.
|
11
|
+
|
12
|
+
## v0.3.0
|
13
|
+
### Added
|
14
|
+
- SwiftUI support.
|
15
|
+
|
16
|
+
## v0.2.0
|
17
|
+
### Added
|
18
|
+
- `stylegen init` command.
|
19
|
+
|
20
|
+
## v0.1.0
|
21
|
+
- Initial release.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stylegen (0.
|
4
|
+
stylegen (0.4.0)
|
5
5
|
dry-inflector (~> 0.2.0)
|
6
6
|
gli (~> 2.1)
|
7
7
|
json_schemer (~> 0.2.0)
|
@@ -9,38 +9,38 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
ast (2.4.
|
12
|
+
ast (2.4.2)
|
13
13
|
dry-inflector (0.2.0)
|
14
14
|
ecma-re-validator (0.3.0)
|
15
15
|
regexp_parser (~> 2.0)
|
16
|
-
gli (2.20.
|
16
|
+
gli (2.20.1)
|
17
17
|
hana (1.3.7)
|
18
|
-
json_schemer (0.2.
|
18
|
+
json_schemer (0.2.18)
|
19
19
|
ecma-re-validator (~> 0.3)
|
20
20
|
hana (~> 1.3)
|
21
21
|
regexp_parser (~> 2.0)
|
22
22
|
uri_template (~> 0.7)
|
23
|
-
minitest (5.14.
|
23
|
+
minitest (5.14.4)
|
24
24
|
parallel (1.20.1)
|
25
|
-
parser (3.0.
|
25
|
+
parser (3.0.1.1)
|
26
26
|
ast (~> 2.4.1)
|
27
27
|
rainbow (3.0.0)
|
28
28
|
rake (13.0.3)
|
29
|
-
regexp_parser (2.
|
30
|
-
rexml (3.2.
|
31
|
-
rubocop (1.
|
29
|
+
regexp_parser (2.1.1)
|
30
|
+
rexml (3.2.5)
|
31
|
+
rubocop (1.14.0)
|
32
32
|
parallel (~> 1.10)
|
33
33
|
parser (>= 3.0.0.0)
|
34
34
|
rainbow (>= 2.2.2, < 4.0)
|
35
35
|
regexp_parser (>= 1.8, < 3.0)
|
36
36
|
rexml
|
37
|
-
rubocop-ast (>= 1.
|
37
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
38
38
|
ruby-progressbar (~> 1.7)
|
39
39
|
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
-
rubocop-ast (1.
|
41
|
-
parser (>=
|
42
|
-
rubocop-minitest (0.
|
43
|
-
rubocop (>= 0.
|
40
|
+
rubocop-ast (1.5.0)
|
41
|
+
parser (>= 3.0.1.1)
|
42
|
+
rubocop-minitest (0.12.1)
|
43
|
+
rubocop (>= 0.90, < 2.0)
|
44
44
|
rubocop-rake (0.5.1)
|
45
45
|
rubocop
|
46
46
|
ruby-progressbar (1.11.0)
|
data/README.md
CHANGED
@@ -38,6 +38,9 @@ The generated YAML file will look similar to this:
|
|
38
38
|
# Path of generated Swift file.
|
39
39
|
output_path: "Colors.swift"
|
40
40
|
|
41
|
+
# Enables SwiftUI support
|
42
|
+
# swiftui: false
|
43
|
+
|
41
44
|
# Key-value pairs of theme colors.
|
42
45
|
colors:
|
43
46
|
|
@@ -65,6 +68,7 @@ colors:
|
|
65
68
|
alpha: 0.6
|
66
69
|
|
67
70
|
primary_background:
|
71
|
+
description: The color for the main background of your interface.
|
68
72
|
light: "#FFFFFF"
|
69
73
|
dark:
|
70
74
|
# Value for base (non-elevated) level
|
@@ -101,5 +105,5 @@ colors. The name of the namespacing function gets inferred from the `system_name
|
|
101
105
|
|
102
106
|
* ~~`$ stylegen init` command~~
|
103
107
|
* Option to specify target frameworks: AppKit, UIKit, Core Graphics, and SwiftUI
|
104
|
-
* SwiftUI support
|
108
|
+
* ~~SwiftUI support~~
|
105
109
|
* AppKit support
|
@@ -7,6 +7,9 @@
|
|
7
7
|
# Path of generated Swift file.
|
8
8
|
output_path: "Colors.swift"
|
9
9
|
|
10
|
+
# Enables SwiftUI support
|
11
|
+
# swiftui: false
|
12
|
+
|
10
13
|
# Key-value pairs of theme colors.
|
11
14
|
colors:
|
12
15
|
|
@@ -34,6 +37,8 @@ colors:
|
|
34
37
|
alpha: 0.6
|
35
38
|
|
36
39
|
primary_background:
|
40
|
+
# Use `description` to document your colors (optional).
|
41
|
+
description: The color for the main background of your interface.
|
37
42
|
light: "#FFFFFF"
|
38
43
|
dark:
|
39
44
|
# Value for base (non-elevated) level
|
@@ -21,20 +21,30 @@ module Stylegen
|
|
21
21
|
raise ArgumentError, "Invalid color syntax: #{hex}"
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
max_precision = 16
|
25
25
|
|
26
|
-
Color.new(r.round(
|
26
|
+
Color.new(r.round(max_precision), g.round(max_precision), b.round(max_precision), alpha || 1.0)
|
27
27
|
end
|
28
28
|
|
29
29
|
def grayscale?
|
30
30
|
@red == @green && @green == @blue
|
31
31
|
end
|
32
32
|
|
33
|
-
def to_s(struct_name,
|
33
|
+
def to_s(struct_name, indent = 0)
|
34
34
|
if grayscale?
|
35
35
|
"#{struct_name}(white: #{@red}, alpha: #{@alpha})"
|
36
36
|
else
|
37
|
-
|
37
|
+
indent_prefix = " " * indent
|
38
|
+
|
39
|
+
result = []
|
40
|
+
result << "#{struct_name}("
|
41
|
+
result << "#{indent_prefix} red: #{@red},"
|
42
|
+
result << "#{indent_prefix} green: #{@green},"
|
43
|
+
result << "#{indent_prefix} blue: #{@blue},"
|
44
|
+
result << "#{indent_prefix} alpha: #{@alpha}"
|
45
|
+
result << "#{indent_prefix})"
|
46
|
+
|
47
|
+
result.join("\n")
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
data/lib/stylegen/data.rb
CHANGED
@@ -30,6 +30,10 @@ module Stylegen
|
|
30
30
|
@data["output_path"]
|
31
31
|
end
|
32
32
|
|
33
|
+
def swiftui?
|
34
|
+
@data["swiftui"] || false
|
35
|
+
end
|
36
|
+
|
33
37
|
def basename
|
34
38
|
File.basename(@data["output_path"])
|
35
39
|
end
|
@@ -42,9 +46,13 @@ module Stylegen
|
|
42
46
|
"#{system_name}Color"
|
43
47
|
end
|
44
48
|
|
45
|
-
def
|
46
|
-
@
|
47
|
-
|
49
|
+
def color_entries
|
50
|
+
@color_entries ||= @data["colors"].map do |key, value|
|
51
|
+
{
|
52
|
+
property: inflector.camelize_lower(key),
|
53
|
+
description: value["description"],
|
54
|
+
color: generate_color(value)
|
55
|
+
}
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
data/lib/stylegen/generator.rb
CHANGED
@@ -1,126 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "stylegen/data"
|
4
|
+
require "stylegen/template"
|
4
5
|
|
5
6
|
module Stylegen
|
6
7
|
class Generator
|
7
8
|
def initialize(data)
|
8
9
|
@data = Data.new(data)
|
9
|
-
@file = File.open(@data.output_path, "w")
|
10
|
-
end
|
11
|
-
|
12
|
-
def out(line)
|
13
|
-
@file << line << "\n"
|
14
10
|
end
|
15
11
|
|
16
12
|
def generate
|
17
|
-
|
18
|
-
generate_struct
|
19
|
-
generate_colors
|
20
|
-
generate_extensions
|
21
|
-
end
|
22
|
-
|
23
|
-
def stats
|
24
|
-
@stats ||= { output_path: @data.output_path, color_count: @data.colors.count }
|
25
|
-
end
|
13
|
+
template = Template.new(@data)
|
26
14
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
out "//"
|
31
|
-
out "// #{@data.basename}"
|
32
|
-
out "//"
|
33
|
-
out "// Autogenerated by stylegen (v#{@data.version})"
|
34
|
-
out "// DO NOT EDIT"
|
35
|
-
out "//"
|
36
|
-
out ""
|
37
|
-
out "import UIKit"
|
38
|
-
out ""
|
15
|
+
file = File.open(@data.output_path, "w")
|
16
|
+
file << template.render
|
17
|
+
file.close
|
39
18
|
end
|
40
19
|
|
41
|
-
def
|
42
|
-
|
43
|
-
out ""
|
44
|
-
out " let uiColor: UIColor"
|
45
|
-
out ""
|
46
|
-
out " fileprivate init(white: CGFloat, alpha: CGFloat) {"
|
47
|
-
out " self.uiColor = UIColor(white: white, alpha: alpha)"
|
48
|
-
out " }"
|
49
|
-
out ""
|
50
|
-
out " fileprivate init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {"
|
51
|
-
out " self.uiColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)"
|
52
|
-
out " }"
|
53
|
-
out ""
|
54
|
-
out " fileprivate init(_ color: UIColor) {"
|
55
|
-
out " self.uiColor = color"
|
56
|
-
out " }"
|
57
|
-
out ""
|
58
|
-
out " fileprivate init(light: #{@data.struct_name}, dark: #{@data.struct_name}) {"
|
59
|
-
out " if #available(iOS 13.0, *) {"
|
60
|
-
out " self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in"
|
61
|
-
out " switch traits.userInterfaceStyle {"
|
62
|
-
out " case .dark:"
|
63
|
-
out " return dark.uiColor"
|
64
|
-
out " default:"
|
65
|
-
out " return light.uiColor"
|
66
|
-
out " }"
|
67
|
-
out " })"
|
68
|
-
out " } else {"
|
69
|
-
out " self.uiColor = light.uiColor"
|
70
|
-
out " }"
|
71
|
-
out " }"
|
72
|
-
out ""
|
73
|
-
out " fileprivate init(base: #{@data.struct_name}, elevated: #{@data.struct_name}) {"
|
74
|
-
out " if #available(iOS 13.0, *) {"
|
75
|
-
out " self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in"
|
76
|
-
out " switch traits.userInterfaceLevel {"
|
77
|
-
out " case .elevated:"
|
78
|
-
out " return elevated.uiColor"
|
79
|
-
out " default:"
|
80
|
-
out " return base.uiColor"
|
81
|
-
out " }"
|
82
|
-
out " })"
|
83
|
-
out " } else {"
|
84
|
-
out " self.uiColor = base.uiColor"
|
85
|
-
out " }"
|
86
|
-
out " }"
|
87
|
-
out ""
|
88
|
-
out "}"
|
89
|
-
out ""
|
90
|
-
end
|
91
|
-
|
92
|
-
def generate_colors
|
93
|
-
out "#{@data.access_level} extension #{@data.struct_name} {"
|
94
|
-
out ""
|
95
|
-
|
96
|
-
@data.colors.each do |member, color|
|
97
|
-
out " static let #{member} = #{color.to_s(@data.struct_name, 4)}"
|
98
|
-
out ""
|
99
|
-
end
|
100
|
-
|
101
|
-
out "}"
|
102
|
-
out ""
|
103
|
-
end
|
104
|
-
|
105
|
-
def generate_extensions
|
106
|
-
out "#{@data.access_level} extension UIColor {"
|
107
|
-
out ""
|
108
|
-
out " @inline(__always)"
|
109
|
-
out " static func #{@data.util_method_name}(_ color: #{@data.struct_name}) -> UIColor {"
|
110
|
-
out " return color.uiColor"
|
111
|
-
out " }"
|
112
|
-
out ""
|
113
|
-
out "}"
|
114
|
-
out ""
|
115
|
-
|
116
|
-
out "#{@data.access_level} extension CGColor {"
|
117
|
-
out ""
|
118
|
-
out " @inline(__always)"
|
119
|
-
out " static func #{@data.util_method_name}(_ color: #{@data.struct_name}) -> CGColor {"
|
120
|
-
out " return color.uiColor.cgColor"
|
121
|
-
out " }"
|
122
|
-
out ""
|
123
|
-
out "}"
|
20
|
+
def stats
|
21
|
+
@stats ||= { output_path: @data.output_path, color_count: @data.color_entries.count }
|
124
22
|
end
|
125
23
|
end
|
126
24
|
end
|
@@ -26,6 +26,9 @@
|
|
26
26
|
"Color": {
|
27
27
|
"type": "object",
|
28
28
|
"properties": {
|
29
|
+
"description": {
|
30
|
+
"type": "string"
|
31
|
+
},
|
29
32
|
"color": {
|
30
33
|
"$ref": "#/definitions/HexColor"
|
31
34
|
},
|
@@ -41,6 +44,9 @@
|
|
41
44
|
"BaseElevatedColor": {
|
42
45
|
"type": "object",
|
43
46
|
"properties": {
|
47
|
+
"description": {
|
48
|
+
"type": "string"
|
49
|
+
},
|
44
50
|
"base": {
|
45
51
|
"$ref": "#/definitions/AbstractColor"
|
46
52
|
},
|
@@ -54,6 +60,9 @@
|
|
54
60
|
"LightDarkColor": {
|
55
61
|
"type": "object",
|
56
62
|
"properties": {
|
63
|
+
"description": {
|
64
|
+
"type": "string"
|
65
|
+
},
|
57
66
|
"light": {
|
58
67
|
"$ref": "#/definitions/AbstractColor"
|
59
68
|
},
|
@@ -83,6 +92,11 @@
|
|
83
92
|
"minLength": 1,
|
84
93
|
"description": "Path of generated Swift file."
|
85
94
|
},
|
95
|
+
"swiftui": {
|
96
|
+
"type": "boolean",
|
97
|
+
"default": false,
|
98
|
+
"description": "Enables SwiftUI support."
|
99
|
+
},
|
86
100
|
"colors": {
|
87
101
|
"type": "object",
|
88
102
|
"description": "Key-value pairs of colors.",
|
@@ -102,4 +116,4 @@
|
|
102
116
|
"output_path",
|
103
117
|
"colors"
|
104
118
|
]
|
105
|
-
}
|
119
|
+
}
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stylegen
|
4
|
+
class Template
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
|
11
|
+
def render
|
12
|
+
result = []
|
13
|
+
result << render_header
|
14
|
+
result << render_imports
|
15
|
+
result << render_struct
|
16
|
+
result << render_colors
|
17
|
+
result << render_utils
|
18
|
+
result.join("\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def render_header
|
24
|
+
<<~HEREDOC
|
25
|
+
//
|
26
|
+
// #{data.basename}
|
27
|
+
//
|
28
|
+
// Autogenerated by stylegen (#{data.version})
|
29
|
+
// DO NOT EDIT
|
30
|
+
//
|
31
|
+
HEREDOC
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_imports
|
35
|
+
result = []
|
36
|
+
result << "import UIKit"
|
37
|
+
result << "import SwiftUI" if data.swiftui?
|
38
|
+
result << ""
|
39
|
+
result.join("\n")
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_struct
|
43
|
+
<<~HEREDOC
|
44
|
+
#{data.access_level} struct #{data.struct_name} {
|
45
|
+
|
46
|
+
let uiColor: UIColor
|
47
|
+
|
48
|
+
fileprivate init(white: CGFloat, alpha: CGFloat) {
|
49
|
+
self.uiColor = UIColor(white: white, alpha: alpha)
|
50
|
+
}
|
51
|
+
|
52
|
+
fileprivate init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
|
53
|
+
self.uiColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)
|
54
|
+
}
|
55
|
+
|
56
|
+
fileprivate init(_ color: UIColor) {
|
57
|
+
self.uiColor = color
|
58
|
+
}
|
59
|
+
|
60
|
+
fileprivate init(light: #{data.struct_name}, dark: #{data.struct_name}) {
|
61
|
+
if #available(iOS 13.0, *) {
|
62
|
+
self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
63
|
+
switch traits.userInterfaceStyle {
|
64
|
+
case .dark:
|
65
|
+
return dark.uiColor
|
66
|
+
default:
|
67
|
+
return light.uiColor
|
68
|
+
}
|
69
|
+
})
|
70
|
+
} else {
|
71
|
+
self.uiColor = light.uiColor
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
fileprivate init(base: #{data.struct_name}, elevated: #{data.struct_name}) {
|
76
|
+
if #available(iOS 13.0, *) {
|
77
|
+
self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
78
|
+
switch traits.userInterfaceLevel {
|
79
|
+
case .elevated:
|
80
|
+
return elevated.uiColor
|
81
|
+
default:
|
82
|
+
return base.uiColor
|
83
|
+
}
|
84
|
+
})
|
85
|
+
} else {
|
86
|
+
self.uiColor = base.uiColor
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
}
|
91
|
+
HEREDOC
|
92
|
+
end
|
93
|
+
|
94
|
+
def render_colors
|
95
|
+
result = []
|
96
|
+
result << "// MARK: Colors"
|
97
|
+
result << ""
|
98
|
+
result << "#{data.access_level} extension #{data.struct_name} {"
|
99
|
+
result << ""
|
100
|
+
|
101
|
+
data.color_entries.each do |entry|
|
102
|
+
unless entry[:description].nil?
|
103
|
+
entry[:description].strip.lines.each do |line|
|
104
|
+
result << " /// #{line.strip}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
result << " static let #{entry[:property]} = #{entry[:color].to_s(data.struct_name, 4)}\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
result << "}"
|
112
|
+
result << ""
|
113
|
+
result.join("\n")
|
114
|
+
end
|
115
|
+
|
116
|
+
def render_utils
|
117
|
+
result = []
|
118
|
+
result << "// MARK: Utils"
|
119
|
+
result << ""
|
120
|
+
|
121
|
+
if data.swiftui?
|
122
|
+
result << <<~HEREDOC
|
123
|
+
#{data.access_level} extension Color {
|
124
|
+
|
125
|
+
@inline(__always)
|
126
|
+
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> Color {
|
127
|
+
return Color(color.uiColor)
|
128
|
+
}
|
129
|
+
|
130
|
+
}
|
131
|
+
HEREDOC
|
132
|
+
end
|
133
|
+
|
134
|
+
result << <<~HEREDOC
|
135
|
+
#{data.access_level} extension UIColor {
|
136
|
+
|
137
|
+
@inline(__always)
|
138
|
+
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> UIColor {
|
139
|
+
return color.uiColor
|
140
|
+
}
|
141
|
+
|
142
|
+
}
|
143
|
+
|
144
|
+
#{data.access_level} extension CGColor {
|
145
|
+
|
146
|
+
@inline(__always)
|
147
|
+
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> CGColor {
|
148
|
+
return color.uiColor.cgColor
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
HEREDOC
|
153
|
+
|
154
|
+
result.join("\n")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/lib/stylegen/validator.rb
CHANGED
data/lib/stylegen/version.rb
CHANGED
data/stylegen.gemspec
CHANGED
data/test/test_color.rb
CHANGED
@@ -6,14 +6,14 @@ class TestColor < MiniTest::Test
|
|
6
6
|
def test_parsing
|
7
7
|
color = Stylegen::Color.from_hex("#FF8000")
|
8
8
|
assert_equal 1.0, color.red
|
9
|
-
assert_equal 0.
|
9
|
+
assert_equal 0.5019607843137255, color.green
|
10
10
|
assert_equal 0.0, color.blue
|
11
11
|
assert_equal 1.0, color.alpha
|
12
12
|
|
13
13
|
# Optional pound sign
|
14
14
|
color = Stylegen::Color.from_hex("FF8000")
|
15
15
|
assert_equal 1.0, color.red
|
16
|
-
assert_equal 0.
|
16
|
+
assert_equal 0.5019607843137255, color.green
|
17
17
|
assert_equal 0.0, color.blue
|
18
18
|
assert_equal 1.0, color.alpha
|
19
19
|
|
@@ -25,14 +25,14 @@ class TestColor < MiniTest::Test
|
|
25
25
|
def test_parsing_shorthand_syntax
|
26
26
|
color = Stylegen::Color.from_hex("#FC0")
|
27
27
|
assert_equal 1.0, color.red
|
28
|
-
assert_equal 0.
|
28
|
+
assert_equal 0.8000000000000002, color.green
|
29
29
|
assert_equal 0.0, color.blue
|
30
30
|
assert_equal 1.0, color.alpha
|
31
31
|
|
32
32
|
# Optional pound sign
|
33
33
|
color = Stylegen::Color.from_hex("FC0")
|
34
34
|
assert_equal 1.0, color.red
|
35
|
-
assert_equal 0.
|
35
|
+
assert_equal 0.8000000000000002, color.green
|
36
36
|
assert_equal 0.0, color.blue
|
37
37
|
assert_equal 1.0, color.alpha
|
38
38
|
end
|
@@ -47,7 +47,16 @@ class TestColor < MiniTest::Test
|
|
47
47
|
|
48
48
|
def test_to_string
|
49
49
|
color = Stylegen::Color.from_hex("#00FF00")
|
50
|
-
|
50
|
+
|
51
|
+
expected = <<~CODE.strip
|
52
|
+
ThemeColor(
|
53
|
+
red: 0.0,
|
54
|
+
green: 1.0,
|
55
|
+
blue: 0.0,
|
56
|
+
alpha: 1.0
|
57
|
+
)
|
58
|
+
CODE
|
59
|
+
|
51
60
|
assert_equal expected, color.to_s("ThemeColor")
|
52
61
|
|
53
62
|
# Grayscale
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylegen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- ".github/workflows/ci.yml"
|
148
148
|
- ".gitignore"
|
149
149
|
- ".rubocop.yml"
|
150
|
+
- CHANGELOG.md
|
150
151
|
- Gemfile
|
151
152
|
- Gemfile.lock
|
152
153
|
- LICENSE
|
@@ -163,7 +164,8 @@ files:
|
|
163
164
|
- lib/stylegen/colors/light_dark_color.rb
|
164
165
|
- lib/stylegen/data.rb
|
165
166
|
- lib/stylegen/generator.rb
|
166
|
-
- lib/stylegen/schema.json
|
167
|
+
- lib/stylegen/resources/schema.json
|
168
|
+
- lib/stylegen/template.rb
|
167
169
|
- lib/stylegen/validator.rb
|
168
170
|
- lib/stylegen/version.rb
|
169
171
|
- stylegen.gemspec
|
@@ -183,14 +185,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
185
|
requirements:
|
184
186
|
- - ">="
|
185
187
|
- !ruby/object:Gem::Version
|
186
|
-
version: 2.
|
188
|
+
version: 2.5.0
|
187
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
190
|
requirements:
|
189
191
|
- - ">="
|
190
192
|
- !ruby/object:Gem::Version
|
191
193
|
version: '0'
|
192
194
|
requirements: []
|
193
|
-
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.7.6
|
194
197
|
signing_key:
|
195
198
|
specification_version: 4
|
196
199
|
summary: Tool for generating styling code for iOS apps
|