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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f3c7f3c64e0c2b99ca8ab6fa2f200f4a47af401b9e1c2547983eaed4f6a339e
4
- data.tar.gz: 870d75d1e851c2cf8d1f8958f0eed6ceff39b2537d28f81e199a6cb8f683caee
3
+ metadata.gz: 615869614190f084f865e58f8f64e7b2769498c6d582c0746239fff8a8f58260
4
+ data.tar.gz: 529834fed7438410cb530801016277bd1a9206e4b018fdb9e68c80ec32ca8b7f
5
5
  SHA512:
6
- metadata.gz: 9e18ecf6503daef89a5cc9fdc9f4fda1a90a2872ff701f750d924a2e3d4f4efedc3ca74cd9a4803fd4b3ee2001defc877e07d40feada9cfa96c845fa3c0e79d2
7
- data.tar.gz: 8365c8bad165c4f518502185e5f639c5e9beebe664c6018d2ea9ec1175bc6f720fa8dc6fc21b879fb76a9dea59e1e071222a360f0235519fcae5a72a087e5440
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 "stylegen/cli"
4
+ require 'stylegen'
5
5
 
6
- exit Stylegen::CLI::App.run(ARGV)
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stylegen
4
+ module CLI
5
+ class Error < StandardError
6
+ end
7
+ end
8
+ end
data/lib/stylegen/cli.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "stylegen/cli/app"
3
+ require 'stylegen/cli/commands'
@@ -5,11 +5,12 @@ module Stylegen
5
5
  attr_reader :description
6
6
 
7
7
  def initialize(base, elevated)
8
- @base, @elevated = base, elevated
8
+ @base = base
9
+ @elevated = elevated
9
10
  end
10
11
 
11
12
  def to_s(struct_name, indent = 0)
12
- indent_prefix = " " * indent
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
- def initialize(r, g, b, a)
8
- @red, @green, @blue, @alpha = r, g, b, a
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
- max_precision = 16
25
-
26
- Color.new(r.round(max_precision), g.round(max_precision), b.round(max_precision), alpha || 1.0)
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 = " " * indent
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, @dark = light, dark
6
+ @light = light
7
+ @dark = dark
7
8
  end
8
9
 
9
10
  def to_s(struct_name, indent = 0)
10
- indent_prefix = " " * indent
11
+ indent_prefix = ' ' * indent
11
12
 
12
13
  result = []
13
14
  result << "#{struct_name}("
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "stylegen/colors/color"
4
- require "stylegen/colors/light_dark_color"
5
- require "stylegen/colors/base_elevated_color"
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 "dry/inflector"
4
- require "stylegen/version"
5
- require "stylegen/colors"
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["system_name"] || "Theme"
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["output_path"]
49
+ @data['output_path']
31
50
  end
32
51
 
33
52
  def swiftui?
34
- @data["swiftui"] || false
53
+ @data['swiftui'] || false
35
54
  end
36
55
 
37
56
  def basename
38
- File.basename(@data["output_path"])
57
+ File.basename(@data['output_path'])
39
58
  end
40
59
 
41
60
  def access_level
42
- @data["access_level"] || "internal"
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["colors"].map do |key, value|
73
+ @color_entries ||= @data['colors'].map do |key, value|
51
74
  {
52
75
  property: inflector.camelize_lower(key),
53
- description: value["description"],
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?("color")
65
- Color.from_hex(data["color"], data["alpha"])
66
- elsif data.key?("light")
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["light"]),
69
- generate_color(data["dark"])
91
+ generate_color(data['light']),
92
+ generate_color(data['dark'])
70
93
  )
71
- elsif data.key?("base")
94
+ elsif data.key?('base')
72
95
  BaseElevatedColor.new(
73
- generate_color(data["base"]),
74
- generate_color(data["elevated"])
96
+ generate_color(data['base']),
97
+ generate_color(data['elevated'])
75
98
  )
76
99
  end
77
100
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "stylegen/data"
4
- require "stylegen/template"
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, "w")
15
+ file = File.open(@data.output_path, 'w')
16
16
  file << template.render
17
17
  file.close
18
18
  end
@@ -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
- <<~HEREDOC
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 << "import UIKit"
37
- result << "import SwiftUI" if data.swiftui?
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.access_level} struct #{data.struct_name} {
37
+ <<~HEREDOC.lstrip
38
+ #{data.effective_access_level} final class #{data.struct_name} {
45
39
 
46
- let uiColor: UIColor
40
+ let rawValue: UIColor
47
41
 
48
- fileprivate init(white: CGFloat, alpha: CGFloat) {
49
- self.uiColor = UIColor(white: white, alpha: alpha)
42
+ private init(_ rawValue: UIColor) {
43
+ self.rawValue = rawValue
50
44
  }
51
45
 
52
- fileprivate init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
53
- self.uiColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)
46
+ private convenience init(white: CGFloat, alpha: CGFloat) {
47
+ self.init(
48
+ UIColor(white: white, alpha: alpha)
49
+ )
54
50
  }
55
51
 
56
- fileprivate init(_ color: UIColor) {
57
- self.uiColor = color
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
- fileprivate init(light: #{data.struct_name}, dark: #{data.struct_name}) {
58
+ private convenience init(light: #{data.struct_name}, dark: #{data.struct_name}) {
61
59
  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
- })
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.uiColor = light.uiColor
71
+ self.init(light.rawValue)
72
72
  }
73
73
  }
74
74
 
75
- fileprivate init(base: #{data.struct_name}, elevated: #{data.struct_name}) {
75
+ private convenience init(base: #{data.struct_name}, elevated: #{data.struct_name}) {
76
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
- })
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.uiColor = base.uiColor
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 << "// MARK: Colors"
97
- result << ""
98
- result << "#{data.access_level} extension #{data.struct_name} {"
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 << "// MARK: Utils"
119
- result << ""
120
+ result << '// MARK: Utils'
121
+ result << ''
120
122
 
121
123
  if data.swiftui?
122
- result << <<~HEREDOC
123
- #{data.access_level} extension Color {
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
- return Color(color.uiColor)
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.access_level} extension UIColor {
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.uiColor
145
+ return color.rawValue
140
146
  }
141
147
 
142
148
  }
149
+ HEREDOC
143
150
 
144
- #{data.access_level} extension CGColor {
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.uiColor.cgColor
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json_schemer"
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["type"] == "schema"
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__, "resources/schema.json")))
24
+ @schema ||= JSONSchemer.schema(File.read(File.join(__dir__, 'resources/schema.json')))
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stylegen
4
- VERSION = "0.4.0"
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/stylegen.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "stylegen/version"
4
- require "stylegen/colors"
5
- require "stylegen/generator"
6
- require "stylegen/data"
7
- require "stylegen/validator"
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.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: 2022-03-06 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dry-inflector
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.2.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.2.0
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: gli
28
+ name: dry-inflector
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
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: '2.1'
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/app.rb
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
- rubyforge_project:
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: []
@@ -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
@@ -1,6 +0,0 @@
1
- .idea
2
- pkg
3
-
4
- # Testing artifacts
5
- theme.yaml
6
- Colors.swift
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
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
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
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
- require "rubocop/rake_task"
6
-
7
- Rake::TestTask.new
8
- RuboCop::RakeTask.new
9
-
10
- task default: :test
@@ -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,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- gem "minitest"
4
-
5
- require "minitest/pride"
6
- require "minitest/autorun"
7
-
8
- require_relative "../lib/stylegen"
@@ -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