stylegen 0.3.1 → 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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/stylegen/cli/template.yaml +2 -0
- data/lib/stylegen/colors/base_elevated_color.rb +2 -0
- data/lib/stylegen/data.rb +7 -3
- data/lib/stylegen/generator.rb +2 -3
- data/lib/stylegen/resources/schema.json +10 -1
- data/lib/stylegen/template.rb +146 -5
- data/lib/stylegen/version.rb +1 -1
- metadata +4 -4
- data/lib/stylegen/resources/template.swift.erb +0 -97
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/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/stylegen/data.rb
CHANGED
@@ -46,9 +46,13 @@ module Stylegen
|
|
46
46
|
"#{system_name}Color"
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
@
|
51
|
-
|
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
|
+
}
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
data/lib/stylegen/generator.rb
CHANGED
@@ -10,8 +10,7 @@ module Stylegen
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def generate
|
13
|
-
|
14
|
-
template = Template.new(template_content, @data)
|
13
|
+
template = Template.new(@data)
|
15
14
|
|
16
15
|
file = File.open(@data.output_path, "w")
|
17
16
|
file << template.render
|
@@ -19,7 +18,7 @@ module Stylegen
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def stats
|
22
|
-
@stats ||= { output_path: @data.output_path, color_count: @data.
|
21
|
+
@stats ||= { output_path: @data.output_path, color_count: @data.color_entries.count }
|
23
22
|
end
|
24
23
|
end
|
25
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
|
},
|
@@ -107,4 +116,4 @@
|
|
107
116
|
"output_path",
|
108
117
|
"colors"
|
109
118
|
]
|
110
|
-
}
|
119
|
+
}
|
data/lib/stylegen/template.rb
CHANGED
@@ -1,16 +1,157 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "erb"
|
4
|
-
|
5
3
|
module Stylegen
|
6
4
|
class Template
|
7
|
-
|
8
|
-
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
def initialize(data)
|
9
8
|
@data = data
|
10
9
|
end
|
11
10
|
|
12
11
|
def render
|
13
|
-
|
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")
|
14
155
|
end
|
15
156
|
end
|
16
157
|
end
|
data/lib/stylegen/version.rb
CHANGED
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
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- lib/stylegen/data.rb
|
166
166
|
- lib/stylegen/generator.rb
|
167
167
|
- lib/stylegen/resources/schema.json
|
168
|
-
- lib/stylegen/resources/template.swift.erb
|
169
168
|
- lib/stylegen/template.rb
|
170
169
|
- lib/stylegen/validator.rb
|
171
170
|
- lib/stylegen/version.rb
|
@@ -193,7 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
192
|
- !ruby/object:Gem::Version
|
194
193
|
version: '0'
|
195
194
|
requirements: []
|
196
|
-
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.7.6
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Tool for generating styling code for iOS apps
|
@@ -1,97 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// <%= @data.basename %>
|
3
|
-
//
|
4
|
-
// Autogenerated by stylegen (<%= @data.version %>)
|
5
|
-
// DO NOT EDIT
|
6
|
-
//
|
7
|
-
|
8
|
-
import UIKit
|
9
|
-
<% if @data.swiftui? -%>
|
10
|
-
import SwiftUI
|
11
|
-
<% end -%>
|
12
|
-
|
13
|
-
<%= @data.access_level %> struct <%= @data.struct_name %> {
|
14
|
-
|
15
|
-
let uiColor: UIColor
|
16
|
-
|
17
|
-
fileprivate init(white: CGFloat, alpha: CGFloat) {
|
18
|
-
self.uiColor = UIColor(white: white, alpha: alpha)
|
19
|
-
}
|
20
|
-
|
21
|
-
fileprivate init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
|
22
|
-
self.uiColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)
|
23
|
-
}
|
24
|
-
|
25
|
-
fileprivate init(_ color: UIColor) {
|
26
|
-
self.uiColor = color
|
27
|
-
}
|
28
|
-
|
29
|
-
fileprivate init(light: <%= @data.struct_name %>, dark: <%= @data.struct_name %>) {
|
30
|
-
if #available(iOS 13.0, *) {
|
31
|
-
self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
32
|
-
switch traits.userInterfaceStyle {
|
33
|
-
case .dark:
|
34
|
-
return dark.uiColor
|
35
|
-
default:
|
36
|
-
return light.uiColor
|
37
|
-
}
|
38
|
-
})
|
39
|
-
} else {
|
40
|
-
self.uiColor = light.uiColor
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
fileprivate init(base: <%= @data.struct_name %>, elevated: <%= @data.struct_name %>) {
|
45
|
-
if #available(iOS 13.0, *) {
|
46
|
-
self.uiColor = UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
47
|
-
switch traits.userInterfaceLevel {
|
48
|
-
case .elevated:
|
49
|
-
return elevated.uiColor
|
50
|
-
default:
|
51
|
-
return base.uiColor
|
52
|
-
}
|
53
|
-
})
|
54
|
-
} else {
|
55
|
-
self.uiColor = base.uiColor
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
// MARK: Colors
|
62
|
-
|
63
|
-
<%= @data.access_level %> extension <%= @data.struct_name %> {
|
64
|
-
<% @data.colors.each do |member, color| %>
|
65
|
-
static let <%= member %> = <%= color.to_s(@data.struct_name, 4) %>
|
66
|
-
<% end %>
|
67
|
-
}
|
68
|
-
|
69
|
-
// MARK: - Extensions
|
70
|
-
<% if @data.swiftui? %>
|
71
|
-
<%= @data.access_level %> extension Color {
|
72
|
-
|
73
|
-
@inline(__always)
|
74
|
-
static func <%= @data.util_method_name %>(_ color: <%= @data.struct_name %>) -> Color {
|
75
|
-
return Color(color.uiColor)
|
76
|
-
}
|
77
|
-
|
78
|
-
}
|
79
|
-
<% end -%>
|
80
|
-
|
81
|
-
<%= @data.access_level %> extension UIColor {
|
82
|
-
|
83
|
-
@inline(__always)
|
84
|
-
static func <%= @data.util_method_name %>(_ color: <%= @data.struct_name %>) -> UIColor {
|
85
|
-
return color.uiColor
|
86
|
-
}
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
<%= @data.access_level %> extension CGColor {
|
91
|
-
|
92
|
-
@inline(__always)
|
93
|
-
static func <%= @data.util_method_name %>(_ color: <%= @data.struct_name %>) -> CGColor {
|
94
|
-
return color.uiColor.cgColor
|
95
|
-
}
|
96
|
-
|
97
|
-
}
|