stylegen 0.2.0 → 0.3.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 +13 -0
- data/Gemfile.lock +13 -13
- data/README.md +4 -1
- data/lib/stylegen/cli/template.yaml +3 -0
- data/lib/stylegen/data.rb +4 -0
- data/lib/stylegen/generator.rb +7 -108
- data/lib/stylegen/{schema.json → resources/schema.json} +5 -0
- data/lib/stylegen/resources/template.swift.erb +97 -0
- data/lib/stylegen/template.rb +16 -0
- data/lib/stylegen/validator.rb +1 -1
- data/lib/stylegen/version.rb +1 -1
- data/stylegen.gemspec +1 -1
- 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: 5c648fda564306d4dc88dab32098c2d6fb0a355e16adb0c352eec6b5ca7cea23
|
4
|
+
data.tar.gz: 0517ac0a864f9663f508376d3ab71859a248f82c028fbb14bd2eb33ac8ce6658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81a4d52f8b5c45938296c7b934069ff6b0906e167d554798da00e893fe38838623ca206d576222dbededddefa6885e2a25e04e29fe56fe93ff2892bda62e0cce
|
7
|
+
data.tar.gz: ce866c1b9c3de44234b290d964baa02c819ac814e74541e59f54fa112c0913752ba83281303ab82c5f182ce6f8301a8bf209c1861737ab3e967ad4fe7d2e7cb8
|
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
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stylegen (0.
|
4
|
+
stylegen (0.3.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
16
|
gli (2.20.0)
|
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
|
|
@@ -101,5 +104,5 @@ colors. The name of the namespacing function gets inferred from the `system_name
|
|
101
104
|
|
102
105
|
* ~~`$ stylegen init` command~~
|
103
106
|
* Option to specify target frameworks: AppKit, UIKit, Core Graphics, and SwiftUI
|
104
|
-
* SwiftUI support
|
107
|
+
* ~~SwiftUI support~~
|
105
108
|
* AppKit support
|
data/lib/stylegen/data.rb
CHANGED
data/lib/stylegen/generator.rb
CHANGED
@@ -1,126 +1,25 @@
|
|
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
|
-
|
19
|
-
|
20
|
-
|
13
|
+
template_content = File.read(File.join(__dir__, "resources/template.swift.erb"))
|
14
|
+
template = Template.new(template_content, @data)
|
15
|
+
|
16
|
+
file = File.open(@data.output_path, "w")
|
17
|
+
file << template.render
|
18
|
+
file.close
|
21
19
|
end
|
22
20
|
|
23
21
|
def stats
|
24
22
|
@stats ||= { output_path: @data.output_path, color_count: @data.colors.count }
|
25
23
|
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def generate_header
|
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 ""
|
39
|
-
end
|
40
|
-
|
41
|
-
def generate_struct
|
42
|
-
out "#{@data.access_level} struct #{@data.struct_name} {"
|
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 "}"
|
124
|
-
end
|
125
24
|
end
|
126
25
|
end
|
@@ -83,6 +83,11 @@
|
|
83
83
|
"minLength": 1,
|
84
84
|
"description": "Path of generated Swift file."
|
85
85
|
},
|
86
|
+
"swiftui": {
|
87
|
+
"type": "boolean",
|
88
|
+
"default": false,
|
89
|
+
"description": "Enables SwiftUI support."
|
90
|
+
},
|
86
91
|
"colors": {
|
87
92
|
"type": "object",
|
88
93
|
"description": "Key-value pairs of colors.",
|
@@ -0,0 +1,97 @@
|
|
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
|
+
}
|
data/lib/stylegen/validator.rb
CHANGED
data/lib/stylegen/version.rb
CHANGED
data/stylegen.gemspec
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.3.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: 2021-
|
11
|
+
date: 2021-05-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,9 @@ 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/resources/template.swift.erb
|
169
|
+
- lib/stylegen/template.rb
|
167
170
|
- lib/stylegen/validator.rb
|
168
171
|
- lib/stylegen/version.rb
|
169
172
|
- stylegen.gemspec
|
@@ -183,14 +186,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
186
|
requirements:
|
184
187
|
- - ">="
|
185
188
|
- !ruby/object:Gem::Version
|
186
|
-
version: 2.
|
189
|
+
version: 2.5.0
|
187
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
191
|
requirements:
|
189
192
|
- - ">="
|
190
193
|
- !ruby/object:Gem::Version
|
191
194
|
version: '0'
|
192
195
|
requirements: []
|
193
|
-
rubygems_version: 3.0.
|
196
|
+
rubygems_version: 3.0.1
|
194
197
|
signing_key:
|
195
198
|
specification_version: 4
|
196
199
|
summary: Tool for generating styling code for iOS apps
|