stylegen 0.4.0 → 0.6.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 +12 -0
- data/bin/stylegen +9 -2
- data/lib/stylegen/cli/commands.rb +76 -0
- data/lib/stylegen/cli/error.rb +8 -0
- data/lib/stylegen/cli.rb +1 -1
- data/lib/stylegen/colors/base_elevated_color.rb +3 -2
- data/lib/stylegen/colors/color.rb +14 -6
- data/lib/stylegen/colors/light_dark_color.rb +3 -2
- data/lib/stylegen/colors.rb +3 -3
- data/lib/stylegen/data.rb +41 -18
- data/lib/stylegen/generator.rb +3 -3
- data/lib/stylegen/template.rb +65 -56
- data/lib/stylegen/validator.rb +3 -3
- data/lib/stylegen/version.rb +1 -1
- data/lib/stylegen.rb +6 -5
- metadata +14 -28
- data/.github/workflows/ci.yml +0 -31
- data/.gitignore +0 -6
- data/.rubocop.yml +0 -33
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -63
- data/Rakefile +0 -10
- data/lib/stylegen/cli/app.rb +0 -62
- data/stylegen.gemspec +0 -31
- data/test/helper.rb +0 -8
- data/test/test_base_elevated_color.rb +0 -34
- data/test/test_color.rb +0 -67
- data/test/test_light_dark_color.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615869614190f084f865e58f8f64e7b2769498c6d582c0746239fff8a8f58260
|
4
|
+
data.tar.gz: 529834fed7438410cb530801016277bd1a9206e4b018fdb9e68c80ec32ca8b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d6b421af6b58144a307056ff0a6ee5325db69651589f6a93ca8b216ac2dda98cb403b1943dd555bed4abae7f08d6946d4ad59a76933bbf014da19e5153d0cb5
|
7
|
+
data.tar.gz: 280d122e2fdd15771ff59cff799c660afcd1fd2b63cda567e8d1c58bb0fc1f5993604e4e505366ff5911b4bd84a49cb42cc1591db023db22a7173eadda1f4e00
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## v0.6.0
|
5
|
+
### Changed
|
6
|
+
- Switched from GLI to dry-cli for CLI. Some may produce slightly different STDOUT and STDERR output.
|
7
|
+
### Added
|
8
|
+
- Added `--output` flag to `stylegen init` command. This allows you to specify a different output file than the default `theme.yaml`.
|
9
|
+
- Added `--input` flag to `stylegen build` command. This allows you to specify a different input file than the default `theme.yaml`.
|
10
|
+
|
11
|
+
## v0.5.0
|
12
|
+
### Changed
|
13
|
+
- Switched generated code from `struct` to `class`.
|
14
|
+
- SwiftUI: Use `Color(uiColor:)` initializer when running on iOS 15+.
|
15
|
+
|
4
16
|
## v0.4.0
|
5
17
|
### Added
|
6
18
|
- Added support for color descriptions.
|
data/bin/stylegen
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'stylegen'
|
5
5
|
|
6
|
-
|
6
|
+
begin
|
7
|
+
arguments = ARGV.empty? ? ['build'] : ARGV
|
8
|
+
cli = Dry::CLI.new(Stylegen::CLI::Commands)
|
9
|
+
cli.call(arguments: arguments)
|
10
|
+
rescue Stylegen::CLI::Commands::Error => e
|
11
|
+
warn e.message
|
12
|
+
exit 1
|
13
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'dry/cli'
|
5
|
+
|
6
|
+
require 'stylegen/validator'
|
7
|
+
require 'stylegen/generator'
|
8
|
+
require 'stylegen/version'
|
9
|
+
require 'stylegen/cli/error'
|
10
|
+
|
11
|
+
module Stylegen
|
12
|
+
module CLI
|
13
|
+
module Commands
|
14
|
+
extend Dry::CLI::Registry
|
15
|
+
|
16
|
+
class Error < StandardError
|
17
|
+
end
|
18
|
+
|
19
|
+
class Version < Dry::CLI::Command
|
20
|
+
desc 'Prints stylegen version'
|
21
|
+
|
22
|
+
def call(*)
|
23
|
+
puts "stylegen version #{Stylegen::VERSION}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Init < Dry::CLI::Command
|
28
|
+
desc 'Generates a sample theme.yaml file in the current directory'
|
29
|
+
|
30
|
+
option :output, aliases: ['-o'], type: :string, default: 'theme.yaml', desc: 'Path to the output file'
|
31
|
+
|
32
|
+
def call(output: 'theme.yaml', **)
|
33
|
+
raise Error, "'#{output}' already exists." if File.exist?(output)
|
34
|
+
|
35
|
+
template = File.read(File.join(__dir__, 'template.yaml'))
|
36
|
+
File.write(output, template)
|
37
|
+
|
38
|
+
puts "Generated '#{output}'."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Build < Dry::CLI::Command
|
43
|
+
desc 'Generates the Swift colors file'
|
44
|
+
|
45
|
+
option :input, aliases: ['-i'], type: :string, default: 'theme.yaml', desc: 'Path to the theme.yaml file'
|
46
|
+
|
47
|
+
def call(input: 'theme.yaml', **)
|
48
|
+
raise Error, "'#{input}' not found. Create one with 'stylegen init'." unless File.exist?(input)
|
49
|
+
|
50
|
+
data = File.open(input) { |file| YAML.safe_load(file) }
|
51
|
+
|
52
|
+
validator = Validator.new
|
53
|
+
unless validator.valid?(data)
|
54
|
+
message = []
|
55
|
+
message << "#{input} contains one or more errors:"
|
56
|
+
|
57
|
+
validator.validate(data).each do |e|
|
58
|
+
message << " #{e}"
|
59
|
+
end
|
60
|
+
|
61
|
+
raise Error, message.join("\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
generator = Generator.new(data)
|
65
|
+
generator.generate
|
66
|
+
|
67
|
+
puts "Generated '#{generator.stats[:output_path]}' with #{generator.stats[:color_count]} colors."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
register 'init', Init
|
72
|
+
register 'build', Build
|
73
|
+
register 'version', Version, aliases: ['-v', '--version']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/stylegen/cli.rb
CHANGED
@@ -5,11 +5,12 @@ module Stylegen
|
|
5
5
|
attr_reader :description
|
6
6
|
|
7
7
|
def initialize(base, elevated)
|
8
|
-
@base
|
8
|
+
@base = base
|
9
|
+
@elevated = elevated
|
9
10
|
end
|
10
11
|
|
11
12
|
def to_s(struct_name, indent = 0)
|
12
|
-
indent_prefix =
|
13
|
+
indent_prefix = ' ' * indent
|
13
14
|
|
14
15
|
result = []
|
15
16
|
result << "#{struct_name}("
|
@@ -4,8 +4,13 @@ module Stylegen
|
|
4
4
|
class Color
|
5
5
|
attr_reader :red, :green, :blue, :alpha
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
MAX_PRECISION = 16
|
8
|
+
|
9
|
+
def initialize(red, green, blue, alpha)
|
10
|
+
@red = red
|
11
|
+
@green = green
|
12
|
+
@blue = blue
|
13
|
+
@alpha = alpha
|
9
14
|
end
|
10
15
|
|
11
16
|
def self.from_hex(hex, alpha = nil)
|
@@ -21,9 +26,12 @@ module Stylegen
|
|
21
26
|
raise ArgumentError, "Invalid color syntax: #{hex}"
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
Color.new(
|
30
|
+
r.round(MAX_PRECISION),
|
31
|
+
g.round(MAX_PRECISION),
|
32
|
+
b.round(MAX_PRECISION),
|
33
|
+
alpha || 1.0
|
34
|
+
)
|
27
35
|
end
|
28
36
|
|
29
37
|
def grayscale?
|
@@ -34,7 +42,7 @@ module Stylegen
|
|
34
42
|
if grayscale?
|
35
43
|
"#{struct_name}(white: #{@red}, alpha: #{@alpha})"
|
36
44
|
else
|
37
|
-
indent_prefix =
|
45
|
+
indent_prefix = ' ' * indent
|
38
46
|
|
39
47
|
result = []
|
40
48
|
result << "#{struct_name}("
|
@@ -3,11 +3,12 @@
|
|
3
3
|
module Stylegen
|
4
4
|
class LightDarkColor
|
5
5
|
def initialize(light, dark)
|
6
|
-
@light
|
6
|
+
@light = light
|
7
|
+
@dark = dark
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_s(struct_name, indent = 0)
|
10
|
-
indent_prefix =
|
11
|
+
indent_prefix = ' ' * indent
|
11
12
|
|
12
13
|
result = []
|
13
14
|
result << "#{struct_name}("
|
data/lib/stylegen/colors.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'stylegen/colors/color'
|
4
|
+
require 'stylegen/colors/light_dark_color'
|
5
|
+
require 'stylegen/colors/base_elevated_color'
|
data/lib/stylegen/data.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'dry/inflector'
|
4
|
+
require 'stylegen/version'
|
5
|
+
require 'stylegen/colors'
|
6
6
|
|
7
7
|
module Stylegen
|
8
8
|
class Data
|
@@ -14,12 +14,31 @@ module Stylegen
|
|
14
14
|
@inflector ||= Dry::Inflector.new
|
15
15
|
end
|
16
16
|
|
17
|
+
def file_header
|
18
|
+
header = @data['header'] || <<~HEADER
|
19
|
+
//
|
20
|
+
// {{STYLEGEN_FILENAME}}
|
21
|
+
//
|
22
|
+
// Autogenerated by stylegen ({{STYLEGEN_VERSION}})
|
23
|
+
// DO NOT EDIT
|
24
|
+
//
|
25
|
+
HEADER
|
26
|
+
|
27
|
+
replacements = {
|
28
|
+
'STYLEGEN_FILENAME' => basename,
|
29
|
+
'STYLEGEN_VERSION' => version,
|
30
|
+
'STYLEGEN_YEAR' => Date.today.year
|
31
|
+
}
|
32
|
+
|
33
|
+
header.strip.gsub(/{{(\w+)}}/) { replacements[Regexp.last_match(1)] || '' }
|
34
|
+
end
|
35
|
+
|
17
36
|
def version
|
18
37
|
Stylegen::VERSION
|
19
38
|
end
|
20
39
|
|
21
40
|
def system_name
|
22
|
-
@data[
|
41
|
+
@data['system_name'] || 'Theme'
|
23
42
|
end
|
24
43
|
|
25
44
|
def util_method_name
|
@@ -27,19 +46,23 @@ module Stylegen
|
|
27
46
|
end
|
28
47
|
|
29
48
|
def output_path
|
30
|
-
@data[
|
49
|
+
@data['output_path']
|
31
50
|
end
|
32
51
|
|
33
52
|
def swiftui?
|
34
|
-
@data[
|
53
|
+
@data['swiftui'] || false
|
35
54
|
end
|
36
55
|
|
37
56
|
def basename
|
38
|
-
File.basename(@data[
|
57
|
+
File.basename(@data['output_path'])
|
39
58
|
end
|
40
59
|
|
41
60
|
def access_level
|
42
|
-
@data[
|
61
|
+
@data['access_level'] || 'internal'
|
62
|
+
end
|
63
|
+
|
64
|
+
def effective_access_level
|
65
|
+
access_level == 'internal' ? '' : "#{access_level} "
|
43
66
|
end
|
44
67
|
|
45
68
|
def struct_name
|
@@ -47,10 +70,10 @@ module Stylegen
|
|
47
70
|
end
|
48
71
|
|
49
72
|
def color_entries
|
50
|
-
@color_entries ||= @data[
|
73
|
+
@color_entries ||= @data['colors'].map do |key, value|
|
51
74
|
{
|
52
75
|
property: inflector.camelize_lower(key),
|
53
|
-
description: value[
|
76
|
+
description: value['description'],
|
54
77
|
color: generate_color(value)
|
55
78
|
}
|
56
79
|
end
|
@@ -61,17 +84,17 @@ module Stylegen
|
|
61
84
|
def generate_color(data)
|
62
85
|
if data.is_a?(String)
|
63
86
|
Color.from_hex(data)
|
64
|
-
elsif data.key?(
|
65
|
-
Color.from_hex(data[
|
66
|
-
elsif data.key?(
|
87
|
+
elsif data.key?('color')
|
88
|
+
Color.from_hex(data['color'], data['alpha'])
|
89
|
+
elsif data.key?('light')
|
67
90
|
LightDarkColor.new(
|
68
|
-
generate_color(data[
|
69
|
-
generate_color(data[
|
91
|
+
generate_color(data['light']),
|
92
|
+
generate_color(data['dark'])
|
70
93
|
)
|
71
|
-
elsif data.key?(
|
94
|
+
elsif data.key?('base')
|
72
95
|
BaseElevatedColor.new(
|
73
|
-
generate_color(data[
|
74
|
-
generate_color(data[
|
96
|
+
generate_color(data['base']),
|
97
|
+
generate_color(data['elevated'])
|
75
98
|
)
|
76
99
|
end
|
77
100
|
end
|
data/lib/stylegen/generator.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'stylegen/data'
|
4
|
+
require 'stylegen/template'
|
5
5
|
|
6
6
|
module Stylegen
|
7
7
|
class Generator
|
@@ -12,7 +12,7 @@ module Stylegen
|
|
12
12
|
def generate
|
13
13
|
template = Template.new(@data)
|
14
14
|
|
15
|
-
file = File.open(@data.output_path,
|
15
|
+
file = File.open(@data.output_path, 'w')
|
16
16
|
file << template.render
|
17
17
|
file.close
|
18
18
|
end
|
data/lib/stylegen/template.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Stylegen
|
4
|
+
# rubocop:disable Metrics/ClassLength
|
4
5
|
class Template
|
5
6
|
attr_reader :data
|
6
7
|
|
@@ -21,69 +22,70 @@ module Stylegen
|
|
21
22
|
private
|
22
23
|
|
23
24
|
def render_header
|
24
|
-
|
25
|
-
//
|
26
|
-
// #{data.basename}
|
27
|
-
//
|
28
|
-
// Autogenerated by stylegen (#{data.version})
|
29
|
-
// DO NOT EDIT
|
30
|
-
//
|
31
|
-
HEREDOC
|
25
|
+
@data.file_header << "\n"
|
32
26
|
end
|
33
27
|
|
34
28
|
def render_imports
|
35
29
|
result = []
|
36
|
-
result <<
|
37
|
-
result <<
|
38
|
-
result <<
|
30
|
+
result << 'import UIKit'
|
31
|
+
result << 'import SwiftUI' if data.swiftui?
|
32
|
+
result << ''
|
39
33
|
result.join("\n")
|
40
34
|
end
|
41
35
|
|
42
36
|
def render_struct
|
43
|
-
<<~HEREDOC
|
44
|
-
#{data.
|
37
|
+
<<~HEREDOC.lstrip
|
38
|
+
#{data.effective_access_level} final class #{data.struct_name} {
|
45
39
|
|
46
|
-
let
|
40
|
+
let rawValue: UIColor
|
47
41
|
|
48
|
-
|
49
|
-
self.
|
42
|
+
private init(_ rawValue: UIColor) {
|
43
|
+
self.rawValue = rawValue
|
50
44
|
}
|
51
45
|
|
52
|
-
|
53
|
-
self.
|
46
|
+
private convenience init(white: CGFloat, alpha: CGFloat) {
|
47
|
+
self.init(
|
48
|
+
UIColor(white: white, alpha: alpha)
|
49
|
+
)
|
54
50
|
}
|
55
51
|
|
56
|
-
|
57
|
-
self.
|
52
|
+
private convenience init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
|
53
|
+
self.init(
|
54
|
+
UIColor(red: red, green: green, blue: blue, alpha: alpha)
|
55
|
+
)
|
58
56
|
}
|
59
57
|
|
60
|
-
|
58
|
+
private convenience init(light: #{data.struct_name}, dark: #{data.struct_name}) {
|
61
59
|
if #available(iOS 13.0, *) {
|
62
|
-
self.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
self.init(
|
61
|
+
UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
62
|
+
switch traits.userInterfaceStyle {
|
63
|
+
case .dark:
|
64
|
+
return dark.rawValue
|
65
|
+
default:
|
66
|
+
return light.rawValue
|
67
|
+
}
|
68
|
+
})
|
69
|
+
)
|
70
70
|
} else {
|
71
|
-
self.
|
71
|
+
self.init(light.rawValue)
|
72
72
|
}
|
73
73
|
}
|
74
74
|
|
75
|
-
|
75
|
+
private convenience init(base: #{data.struct_name}, elevated: #{data.struct_name}) {
|
76
76
|
if #available(iOS 13.0, *) {
|
77
|
-
self.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
self.init(
|
78
|
+
UIColor(dynamicProvider: { (traits: UITraitCollection) -> UIColor in
|
79
|
+
switch traits.userInterfaceLevel {
|
80
|
+
case .elevated:
|
81
|
+
return elevated.rawValue
|
82
|
+
default:
|
83
|
+
return base.rawValue
|
84
|
+
}
|
85
|
+
})
|
86
|
+
)
|
85
87
|
} else {
|
86
|
-
self.
|
88
|
+
self.init(base.rawValue)
|
87
89
|
}
|
88
90
|
}
|
89
91
|
|
@@ -93,10 +95,10 @@ module Stylegen
|
|
93
95
|
|
94
96
|
def render_colors
|
95
97
|
result = []
|
96
|
-
result <<
|
97
|
-
result <<
|
98
|
-
result << "#{data.
|
99
|
-
result <<
|
98
|
+
result << '// MARK: Colors'
|
99
|
+
result << ''
|
100
|
+
result << "#{data.effective_access_level} extension #{data.struct_name} {".lstrip
|
101
|
+
result << ''
|
100
102
|
|
101
103
|
data.color_entries.each do |entry|
|
102
104
|
unless entry[:description].nil?
|
@@ -108,44 +110,50 @@ module Stylegen
|
|
108
110
|
result << " static let #{entry[:property]} = #{entry[:color].to_s(data.struct_name, 4)}\n"
|
109
111
|
end
|
110
112
|
|
111
|
-
result <<
|
112
|
-
result <<
|
113
|
+
result << '}'
|
114
|
+
result << ''
|
113
115
|
result.join("\n")
|
114
116
|
end
|
115
117
|
|
116
118
|
def render_utils
|
117
119
|
result = []
|
118
|
-
result <<
|
119
|
-
result <<
|
120
|
+
result << '// MARK: Utils'
|
121
|
+
result << ''
|
120
122
|
|
121
123
|
if data.swiftui?
|
122
|
-
result << <<~HEREDOC
|
123
|
-
#{data.
|
124
|
+
result << <<~HEREDOC.lstrip
|
125
|
+
#{data.effective_access_level} extension Color {
|
124
126
|
|
125
127
|
@inline(__always)
|
126
128
|
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> Color {
|
127
|
-
|
129
|
+
if #available(iOS 15.0, *) {
|
130
|
+
return Color(uiColor: color.rawValue)
|
131
|
+
} else {
|
132
|
+
return Color(color.rawValue)
|
133
|
+
}
|
128
134
|
}
|
129
135
|
|
130
136
|
}
|
131
137
|
HEREDOC
|
132
138
|
end
|
133
139
|
|
134
|
-
result << <<~HEREDOC
|
135
|
-
#{data.
|
140
|
+
result << <<~HEREDOC.lstrip
|
141
|
+
#{data.effective_access_level} extension UIColor {
|
136
142
|
|
137
143
|
@inline(__always)
|
138
144
|
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> UIColor {
|
139
|
-
return color.
|
145
|
+
return color.rawValue
|
140
146
|
}
|
141
147
|
|
142
148
|
}
|
149
|
+
HEREDOC
|
143
150
|
|
144
|
-
|
151
|
+
result << <<~HEREDOC.lstrip
|
152
|
+
#{data.effective_access_level} extension CGColor {
|
145
153
|
|
146
154
|
@inline(__always)
|
147
155
|
static func #{data.util_method_name}(_ color: #{data.struct_name}) -> CGColor {
|
148
|
-
return color.
|
156
|
+
return color.rawValue.cgColor
|
149
157
|
}
|
150
158
|
|
151
159
|
}
|
@@ -154,4 +162,5 @@ module Stylegen
|
|
154
162
|
result.join("\n")
|
155
163
|
end
|
156
164
|
end
|
165
|
+
# rubocop:enable Metrics/ClassLength
|
157
166
|
end
|
data/lib/stylegen/validator.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'json_schemer'
|
4
4
|
|
5
5
|
module Stylegen
|
6
6
|
class Validator
|
@@ -12,7 +12,7 @@ module Stylegen
|
|
12
12
|
errors = []
|
13
13
|
|
14
14
|
schema.validate(config).each do |v|
|
15
|
-
errors << JSONSchemer::Errors.pretty(v) unless v[
|
15
|
+
errors << JSONSchemer::Errors.pretty(v) unless v['type'] == 'schema'
|
16
16
|
end
|
17
17
|
|
18
18
|
errors
|
@@ -21,7 +21,7 @@ module Stylegen
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def schema
|
24
|
-
@schema ||= JSONSchemer.schema(File.read(File.join(__dir__,
|
24
|
+
@schema ||= JSONSchemer.schema(File.read(File.join(__dir__, 'resources/schema.json')))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/stylegen/version.rb
CHANGED
data/lib/stylegen.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require 'stylegen/version'
|
4
|
+
require 'stylegen/cli'
|
5
|
+
require 'stylegen/colors'
|
6
|
+
require 'stylegen/generator'
|
7
|
+
require 'stylegen/data'
|
8
|
+
require 'stylegen/validator'
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylegen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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: 2023-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: dry-
|
14
|
+
name: dry-cli
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.7.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.7.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dry-inflector
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json_schemer
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,19 +144,14 @@ executables:
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
-
- ".github/workflows/ci.yml"
|
148
|
-
- ".gitignore"
|
149
|
-
- ".rubocop.yml"
|
150
147
|
- CHANGELOG.md
|
151
|
-
- Gemfile
|
152
|
-
- Gemfile.lock
|
153
148
|
- LICENSE
|
154
149
|
- README.md
|
155
|
-
- Rakefile
|
156
150
|
- bin/stylegen
|
157
151
|
- lib/stylegen.rb
|
158
152
|
- lib/stylegen/cli.rb
|
159
|
-
- lib/stylegen/cli/
|
153
|
+
- lib/stylegen/cli/commands.rb
|
154
|
+
- lib/stylegen/cli/error.rb
|
160
155
|
- lib/stylegen/cli/template.yaml
|
161
156
|
- lib/stylegen/colors.rb
|
162
157
|
- lib/stylegen/colors/base_elevated_color.rb
|
@@ -168,15 +163,11 @@ files:
|
|
168
163
|
- lib/stylegen/template.rb
|
169
164
|
- lib/stylegen/validator.rb
|
170
165
|
- lib/stylegen/version.rb
|
171
|
-
- stylegen.gemspec
|
172
|
-
- test/helper.rb
|
173
|
-
- test/test_base_elevated_color.rb
|
174
|
-
- test/test_color.rb
|
175
|
-
- test/test_light_dark_color.rb
|
176
166
|
homepage: https://github.com/raymondjavaxx/stylegen
|
177
167
|
licenses:
|
178
168
|
- MIT
|
179
|
-
metadata:
|
169
|
+
metadata:
|
170
|
+
rubygems_mfa_required: 'true'
|
180
171
|
post_install_message:
|
181
172
|
rdoc_options: []
|
182
173
|
require_paths:
|
@@ -192,13 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
183
|
- !ruby/object:Gem::Version
|
193
184
|
version: '0'
|
194
185
|
requirements: []
|
195
|
-
|
196
|
-
rubygems_version: 2.7.6
|
186
|
+
rubygems_version: 3.1.4
|
197
187
|
signing_key:
|
198
188
|
specification_version: 4
|
199
189
|
summary: Tool for generating styling code for iOS apps
|
200
|
-
test_files:
|
201
|
-
- test/helper.rb
|
202
|
-
- test/test_base_elevated_color.rb
|
203
|
-
- test/test_color.rb
|
204
|
-
- test/test_light_dark_color.rb
|
190
|
+
test_files: []
|
data/.github/workflows/ci.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
name: CI
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: "*"
|
6
|
-
pull_request:
|
7
|
-
branches: "*"
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
test:
|
11
|
-
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
strategy:
|
14
|
-
matrix:
|
15
|
-
ruby-version:
|
16
|
-
- "2.5"
|
17
|
-
- "2.6"
|
18
|
-
- "2.7"
|
19
|
-
- "3.0"
|
20
|
-
|
21
|
-
steps:
|
22
|
-
- uses: actions/checkout@v2
|
23
|
-
- name: Set up Ruby
|
24
|
-
uses: ruby/setup-ruby@v1
|
25
|
-
with:
|
26
|
-
ruby-version: ${{ matrix.ruby-version }}
|
27
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
28
|
-
- name: Lint
|
29
|
-
run: bundle exec rake rubocop
|
30
|
-
- name: Run tests
|
31
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-rake
|
3
|
-
- rubocop-minitest
|
4
|
-
|
5
|
-
AllCops:
|
6
|
-
TargetRubyVersion: 2.5
|
7
|
-
NewCops: enable
|
8
|
-
|
9
|
-
Style/StringLiterals:
|
10
|
-
Enabled: true
|
11
|
-
EnforcedStyle: double_quotes
|
12
|
-
|
13
|
-
Metrics/ClassLength:
|
14
|
-
Enabled: true
|
15
|
-
Max: 150
|
16
|
-
|
17
|
-
Naming/MethodParameterName:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Metrics/MethodLength:
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
Metrics/AbcSize:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
Style/Documentation:
|
27
|
-
Enabled: false
|
28
|
-
|
29
|
-
Style/ParallelAssignment:
|
30
|
-
Enabled: false
|
31
|
-
|
32
|
-
Minitest/AssertInDelta:
|
33
|
-
Enabled: false
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
stylegen (0.4.0)
|
5
|
-
dry-inflector (~> 0.2.0)
|
6
|
-
gli (~> 2.1)
|
7
|
-
json_schemer (~> 0.2.0)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
ast (2.4.2)
|
13
|
-
dry-inflector (0.2.0)
|
14
|
-
ecma-re-validator (0.3.0)
|
15
|
-
regexp_parser (~> 2.0)
|
16
|
-
gli (2.20.1)
|
17
|
-
hana (1.3.7)
|
18
|
-
json_schemer (0.2.18)
|
19
|
-
ecma-re-validator (~> 0.3)
|
20
|
-
hana (~> 1.3)
|
21
|
-
regexp_parser (~> 2.0)
|
22
|
-
uri_template (~> 0.7)
|
23
|
-
minitest (5.14.4)
|
24
|
-
parallel (1.20.1)
|
25
|
-
parser (3.0.1.1)
|
26
|
-
ast (~> 2.4.1)
|
27
|
-
rainbow (3.0.0)
|
28
|
-
rake (13.0.3)
|
29
|
-
regexp_parser (2.1.1)
|
30
|
-
rexml (3.2.5)
|
31
|
-
rubocop (1.14.0)
|
32
|
-
parallel (~> 1.10)
|
33
|
-
parser (>= 3.0.0.0)
|
34
|
-
rainbow (>= 2.2.2, < 4.0)
|
35
|
-
regexp_parser (>= 1.8, < 3.0)
|
36
|
-
rexml
|
37
|
-
rubocop-ast (>= 1.5.0, < 2.0)
|
38
|
-
ruby-progressbar (~> 1.7)
|
39
|
-
unicode-display_width (>= 1.4.0, < 3.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
|
-
rubocop-rake (0.5.1)
|
45
|
-
rubocop
|
46
|
-
ruby-progressbar (1.11.0)
|
47
|
-
unicode-display_width (2.0.0)
|
48
|
-
uri_template (0.7.0)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
ruby
|
52
|
-
|
53
|
-
DEPENDENCIES
|
54
|
-
bundler
|
55
|
-
minitest (~> 5.14)
|
56
|
-
rake
|
57
|
-
rubocop
|
58
|
-
rubocop-minitest
|
59
|
-
rubocop-rake
|
60
|
-
stylegen!
|
61
|
-
|
62
|
-
BUNDLED WITH
|
63
|
-
2.1.4
|
data/Rakefile
DELETED
data/lib/stylegen/cli/app.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
require "gli"
|
5
|
-
|
6
|
-
require "stylegen/validator"
|
7
|
-
require "stylegen/generator"
|
8
|
-
|
9
|
-
module Stylegen
|
10
|
-
module CLI
|
11
|
-
class App
|
12
|
-
extend GLI::App
|
13
|
-
|
14
|
-
program_desc "CLI tool for managing colors in iOS apps"
|
15
|
-
|
16
|
-
version Stylegen::VERSION
|
17
|
-
|
18
|
-
default_command :build
|
19
|
-
|
20
|
-
# Commands
|
21
|
-
|
22
|
-
desc "Generates a sample theme.yaml file in the current directory"
|
23
|
-
command :init do |c|
|
24
|
-
c.action do
|
25
|
-
exit_now!("'theme.yaml' already exists!") if File.exist?("theme.yaml")
|
26
|
-
|
27
|
-
template = File.read(File.join(__dir__, "template.yaml"))
|
28
|
-
File.write("theme.yaml", template)
|
29
|
-
|
30
|
-
puts "Generated 'theme.yaml'."
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Generates the Swift colors file"
|
35
|
-
command :build do |c|
|
36
|
-
c.action do
|
37
|
-
exit_now!("'theme.yaml' not found. Create one with 'stylegen init'.") unless File.exist?("theme.yaml")
|
38
|
-
|
39
|
-
data = File.open("theme.yaml") { |file| YAML.safe_load(file) }
|
40
|
-
|
41
|
-
validator = Validator.new
|
42
|
-
|
43
|
-
unless validator.valid?(data)
|
44
|
-
message = []
|
45
|
-
message << "theme.yaml contains one or more errors:"
|
46
|
-
|
47
|
-
validator.validate(data).each do |e|
|
48
|
-
message << " #{e}"
|
49
|
-
end
|
50
|
-
|
51
|
-
exit_now!(message.join("\n"))
|
52
|
-
end
|
53
|
-
|
54
|
-
generator = Generator.new(data)
|
55
|
-
generator.generate
|
56
|
-
|
57
|
-
puts "Generated '#{generator.stats[:output_path]}' with #{generator.stats[:color_count]} colors."
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/stylegen.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "./lib/stylegen/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "stylegen"
|
7
|
-
s.version = Stylegen::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Ramon Torres"]
|
10
|
-
s.email = ["raymondjavaxx@gmail.com"]
|
11
|
-
s.homepage = "https://github.com/raymondjavaxx/stylegen"
|
12
|
-
s.description = s.summary = "Tool for generating styling code for iOS apps"
|
13
|
-
s.files = `git ls-files`.split("\n")
|
14
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.license = "MIT"
|
18
|
-
|
19
|
-
s.add_runtime_dependency "dry-inflector", "~> 0.2.0"
|
20
|
-
s.add_runtime_dependency "gli", "~> 2.1"
|
21
|
-
s.add_runtime_dependency "json_schemer", "~> 0.2.0"
|
22
|
-
|
23
|
-
s.add_development_dependency "bundler"
|
24
|
-
s.add_development_dependency "minitest", "~> 5.14"
|
25
|
-
s.add_development_dependency "rake"
|
26
|
-
s.add_development_dependency "rubocop"
|
27
|
-
s.add_development_dependency "rubocop-minitest"
|
28
|
-
s.add_development_dependency "rubocop-rake"
|
29
|
-
|
30
|
-
s.required_ruby_version = ">= 2.5.0"
|
31
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "helper"
|
4
|
-
|
5
|
-
class TestBaseElevatedColor < MiniTest::Test
|
6
|
-
def test_to_string
|
7
|
-
color = Stylegen::BaseElevatedColor.new(
|
8
|
-
Stylegen::Color.from_hex("#000000"),
|
9
|
-
Stylegen::Color.from_hex("#333333")
|
10
|
-
)
|
11
|
-
|
12
|
-
# Default indentation
|
13
|
-
|
14
|
-
expected = <<~CODE.chomp
|
15
|
-
ThemeColor(
|
16
|
-
base: ThemeColor(white: 0.0, alpha: 1.0),
|
17
|
-
elevated: ThemeColor(white: 0.2, alpha: 1.0)
|
18
|
-
)
|
19
|
-
CODE
|
20
|
-
|
21
|
-
assert_equal expected, color.to_s("ThemeColor")
|
22
|
-
|
23
|
-
# Additional indentation
|
24
|
-
|
25
|
-
expected = <<~CODE.chomp
|
26
|
-
ThemeColor(
|
27
|
-
base: ThemeColor(white: 0.0, alpha: 1.0),
|
28
|
-
elevated: ThemeColor(white: 0.2, alpha: 1.0)
|
29
|
-
)
|
30
|
-
CODE
|
31
|
-
|
32
|
-
assert_equal expected, color.to_s("ThemeColor", 4)
|
33
|
-
end
|
34
|
-
end
|
data/test/test_color.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "helper"
|
4
|
-
|
5
|
-
class TestColor < MiniTest::Test
|
6
|
-
def test_parsing
|
7
|
-
color = Stylegen::Color.from_hex("#FF8000")
|
8
|
-
assert_equal 1.0, color.red
|
9
|
-
assert_equal 0.5019607843137255, color.green
|
10
|
-
assert_equal 0.0, color.blue
|
11
|
-
assert_equal 1.0, color.alpha
|
12
|
-
|
13
|
-
# Optional pound sign
|
14
|
-
color = Stylegen::Color.from_hex("FF8000")
|
15
|
-
assert_equal 1.0, color.red
|
16
|
-
assert_equal 0.5019607843137255, color.green
|
17
|
-
assert_equal 0.0, color.blue
|
18
|
-
assert_equal 1.0, color.alpha
|
19
|
-
|
20
|
-
# Specify alpha
|
21
|
-
color = Stylegen::Color.from_hex("#FF8000", 0.5)
|
22
|
-
assert_equal 0.5, color.alpha
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_parsing_shorthand_syntax
|
26
|
-
color = Stylegen::Color.from_hex("#FC0")
|
27
|
-
assert_equal 1.0, color.red
|
28
|
-
assert_equal 0.8000000000000002, color.green
|
29
|
-
assert_equal 0.0, color.blue
|
30
|
-
assert_equal 1.0, color.alpha
|
31
|
-
|
32
|
-
# Optional pound sign
|
33
|
-
color = Stylegen::Color.from_hex("FC0")
|
34
|
-
assert_equal 1.0, color.red
|
35
|
-
assert_equal 0.8000000000000002, color.green
|
36
|
-
assert_equal 0.0, color.blue
|
37
|
-
assert_equal 1.0, color.alpha
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_grayscale
|
41
|
-
color = Stylegen::Color.new(1, 1, 1, 1)
|
42
|
-
assert color.grayscale?
|
43
|
-
|
44
|
-
color = Stylegen::Color.new(1, 1, 0.9, 1)
|
45
|
-
refute color.grayscale?
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_to_string
|
49
|
-
color = Stylegen::Color.from_hex("#00FF00")
|
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
|
-
|
60
|
-
assert_equal expected, color.to_s("ThemeColor")
|
61
|
-
|
62
|
-
# Grayscale
|
63
|
-
color = Stylegen::Color.from_hex("#FFFFFF")
|
64
|
-
expected = "ThemeColor(white: 1.0, alpha: 1.0)"
|
65
|
-
assert_equal expected, color.to_s("ThemeColor")
|
66
|
-
end
|
67
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "helper"
|
4
|
-
|
5
|
-
class TestLightDarkColor < MiniTest::Test
|
6
|
-
def test_to_string
|
7
|
-
color = Stylegen::LightDarkColor.new(
|
8
|
-
Stylegen::Color.from_hex("#FFFFFF"),
|
9
|
-
Stylegen::Color.from_hex("#333333")
|
10
|
-
)
|
11
|
-
|
12
|
-
# Default indentation
|
13
|
-
|
14
|
-
expected = <<~CODE.chomp
|
15
|
-
ThemeColor(
|
16
|
-
light: ThemeColor(white: 1.0, alpha: 1.0),
|
17
|
-
dark: ThemeColor(white: 0.2, alpha: 1.0)
|
18
|
-
)
|
19
|
-
CODE
|
20
|
-
|
21
|
-
assert_equal expected, color.to_s("ThemeColor")
|
22
|
-
|
23
|
-
# Additional indentation
|
24
|
-
|
25
|
-
expected = <<~CODE.chomp
|
26
|
-
ThemeColor(
|
27
|
-
light: ThemeColor(white: 1.0, alpha: 1.0),
|
28
|
-
dark: ThemeColor(white: 0.2, alpha: 1.0)
|
29
|
-
)
|
30
|
-
CODE
|
31
|
-
|
32
|
-
assert_equal expected, color.to_s("ThemeColor", 4)
|
33
|
-
end
|
34
|
-
end
|