stylegen 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f3c7f3c64e0c2b99ca8ab6fa2f200f4a47af401b9e1c2547983eaed4f6a339e
4
- data.tar.gz: 870d75d1e851c2cf8d1f8958f0eed6ceff39b2537d28f81e199a6cb8f683caee
3
+ metadata.gz: 31f78139e4e4008bf37ab9d48bc8e00309b7a04d98be8e0a2d66a281afde0780
4
+ data.tar.gz: e08e613e70ef4ca0f96989051db35496783caf8c4de3245fb78600d6a72cd15a
5
5
  SHA512:
6
- metadata.gz: 9e18ecf6503daef89a5cc9fdc9f4fda1a90a2872ff701f750d924a2e3d4f4efedc3ca74cd9a4803fd4b3ee2001defc877e07d40feada9cfa96c845fa3c0e79d2
7
- data.tar.gz: 8365c8bad165c4f518502185e5f639c5e9beebe664c6018d2ea9ec1175bc6f720fa8dc6fc21b879fb76a9dea59e1e071222a360f0235519fcae5a72a087e5440
6
+ metadata.gz: aa6e4794fb3fa16e907aa5fe272fce946b225de69565ca92dee659dd2ddaae63e6ae141c320366bb05ff8dade91ae5b3acd1cb8ca5f0641ab44cfa909971a4bc
7
+ data.tar.gz: d0b5c306bb2edc0e1c017ba35df7dfb6445d02fe66b12cc7560999461c7ce4a2549378a47b371466b49771cb7300fb360a50ca6345f62e48c23137d1a58644d2
data/.deepsource.toml ADDED
@@ -0,0 +1,5 @@
1
+ version = 1
2
+
3
+ [[analyzers]]
4
+ name = "ruby"
5
+ enabled = true
@@ -1,14 +1,14 @@
1
1
  name: CI
2
-
3
2
  on:
4
3
  push:
5
- branches: "*"
4
+ branches:
5
+ - master
6
6
  pull_request:
7
- branches: "*"
7
+ branches:
8
+ - master
8
9
 
9
10
  jobs:
10
11
  test:
11
-
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
@@ -17,9 +17,10 @@ jobs:
17
17
  - "2.6"
18
18
  - "2.7"
19
19
  - "3.0"
20
+ - "3.1"
20
21
 
21
22
  steps:
22
- - uses: actions/checkout@v2
23
+ - uses: actions/checkout@v3
23
24
  - name: Set up Ruby
24
25
  uses: ruby/setup-ruby@v1
25
26
  with:
data/.rubocop.yml CHANGED
@@ -6,17 +6,6 @@ AllCops:
6
6
  TargetRubyVersion: 2.5
7
7
  NewCops: enable
8
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
9
  Metrics/MethodLength:
21
10
  Enabled: false
22
11
 
@@ -25,9 +14,3 @@ Metrics/AbcSize:
25
14
 
26
15
  Style/Documentation:
27
16
  Enabled: false
28
-
29
- Style/ParallelAssignment:
30
- Enabled: false
31
-
32
- Minitest/AssertInDelta:
33
- Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## v0.5.0
5
+ ### Changed
6
+ - Switched generated code from `struct` to `class`.
7
+ - SwiftUI: Use `Color(uiColor:)` initializer when running on iOS 15+.
8
+
4
9
  ## v0.4.0
5
10
  ### Added
6
11
  - Added support for color descriptions.
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stylegen (0.4.0)
4
+ stylegen (0.5.0)
5
5
  dry-inflector (~> 0.2.0)
6
6
  gli (~> 2.1)
7
7
  json_schemer (~> 0.2.0)
@@ -13,9 +13,9 @@ GEM
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.1)
16
+ gli (2.21.0)
17
17
  hana (1.3.7)
18
- json_schemer (0.2.18)
18
+ json_schemer (0.2.24)
19
19
  ecma-re-validator (~> 0.3)
20
20
  hana (~> 1.3)
21
21
  regexp_parser (~> 2.0)
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
- require "rubocop/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
6
 
7
7
  Rake::TestTask.new
8
8
  RuboCop::RakeTask.new
data/bin/stylegen CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "stylegen/cli"
4
+ require 'stylegen/cli'
5
5
 
6
6
  exit Stylegen::CLI::App.run(ARGV)
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "yaml"
4
- require "gli"
3
+ require 'yaml'
4
+ require 'gli'
5
5
 
6
- require "stylegen/validator"
7
- require "stylegen/generator"
6
+ require 'stylegen/validator'
7
+ require 'stylegen/generator'
8
8
 
9
9
  module Stylegen
10
10
  module CLI
11
11
  class App
12
12
  extend GLI::App
13
13
 
14
- program_desc "CLI tool for managing colors in iOS apps"
14
+ program_desc 'CLI tool for managing colors in iOS apps'
15
15
 
16
16
  version Stylegen::VERSION
17
17
 
@@ -19,30 +19,30 @@ module Stylegen
19
19
 
20
20
  # Commands
21
21
 
22
- desc "Generates a sample theme.yaml file in the current directory"
22
+ desc 'Generates a sample theme.yaml file in the current directory'
23
23
  command :init do |c|
24
24
  c.action do
25
- exit_now!("'theme.yaml' already exists!") if File.exist?("theme.yaml")
25
+ exit_now!("'theme.yaml' already exists!") if File.exist?('theme.yaml')
26
26
 
27
- template = File.read(File.join(__dir__, "template.yaml"))
28
- File.write("theme.yaml", template)
27
+ template = File.read(File.join(__dir__, 'template.yaml'))
28
+ File.write('theme.yaml', template)
29
29
 
30
30
  puts "Generated 'theme.yaml'."
31
31
  end
32
32
  end
33
33
 
34
- desc "Generates the Swift colors file"
34
+ desc 'Generates the Swift colors file'
35
35
  command :build do |c|
36
36
  c.action do
37
- exit_now!("'theme.yaml' not found. Create one with 'stylegen init'.") unless File.exist?("theme.yaml")
37
+ exit_now!("'theme.yaml' not found. Create one with 'stylegen init'.") unless File.exist?('theme.yaml')
38
38
 
39
- data = File.open("theme.yaml") { |file| YAML.safe_load(file) }
39
+ data = File.open('theme.yaml') { |file| YAML.safe_load(file) }
40
40
 
41
41
  validator = Validator.new
42
42
 
43
43
  unless validator.valid?(data)
44
44
  message = []
45
- message << "theme.yaml contains one or more errors:"
45
+ message << 'theme.yaml contains one or more errors:'
46
46
 
47
47
  validator.validate(data).each do |e|
48
48
  message << " #{e}"
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/app'
@@ -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.5.0'
5
5
  end
data/lib/stylegen.rb CHANGED
@@ -1,7 +1,7 @@
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/colors'
5
+ require 'stylegen/generator'
6
+ require 'stylegen/data'
7
+ require 'stylegen/validator'
data/stylegen.gemspec CHANGED
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "./lib/stylegen/version"
3
+ require './lib/stylegen/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "stylegen"
6
+ s.name = 'stylegen'
7
7
  s.version = Stylegen::VERSION
8
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"
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
13
  s.files = `git ls-files`.split("\n")
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
- s.require_paths = ["lib"]
17
- s.license = "MIT"
16
+ s.require_paths = ['lib']
17
+ s.license = 'MIT'
18
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"
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
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"
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
29
 
30
- s.required_ruby_version = ">= 2.5.0"
30
+ s.required_ruby_version = '>= 2.5.0'
31
31
  end
data/test/helper.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "minitest"
3
+ gem 'minitest'
4
4
 
5
- require "minitest/pride"
6
- require "minitest/autorun"
5
+ require 'minitest/pride'
6
+ require 'minitest/autorun'
7
7
 
8
- require_relative "../lib/stylegen"
8
+ require_relative '../lib/stylegen'
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
3
+ require_relative 'helper'
4
4
 
5
5
  class TestBaseElevatedColor < MiniTest::Test
6
6
  def test_to_string
7
7
  color = Stylegen::BaseElevatedColor.new(
8
- Stylegen::Color.from_hex("#000000"),
9
- Stylegen::Color.from_hex("#333333")
8
+ Stylegen::Color.from_hex('#000000'),
9
+ Stylegen::Color.from_hex('#333333')
10
10
  )
11
11
 
12
12
  # Default indentation
@@ -18,7 +18,7 @@ class TestBaseElevatedColor < MiniTest::Test
18
18
  )
19
19
  CODE
20
20
 
21
- assert_equal expected, color.to_s("ThemeColor")
21
+ assert_equal expected, color.to_s('ThemeColor')
22
22
 
23
23
  # Additional indentation
24
24
 
@@ -29,6 +29,6 @@ class TestBaseElevatedColor < MiniTest::Test
29
29
  )
30
30
  CODE
31
31
 
32
- assert_equal expected, color.to_s("ThemeColor", 4)
32
+ assert_equal expected, color.to_s('ThemeColor', 4)
33
33
  end
34
34
  end
data/test/test_color.rb CHANGED
@@ -1,40 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
3
+ require_relative 'helper'
4
4
 
5
5
  class TestColor < MiniTest::Test
6
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
7
+ color = Stylegen::Color.from_hex('#FF8000')
8
+ assert_in_delta(1.0, color.red)
9
+ assert_in_delta(0.5019607843137255, color.green)
10
+ assert_in_delta(0.0, color.blue)
11
+ assert_in_delta(1.0, color.alpha)
12
12
 
13
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
14
+ color = Stylegen::Color.from_hex('FF8000')
15
+ assert_in_delta(1.0, color.red)
16
+ assert_in_delta(0.5019607843137255, color.green)
17
+ assert_in_delta(0.0, color.blue)
18
+ assert_in_delta(1.0, color.alpha)
19
19
 
20
20
  # Specify alpha
21
- color = Stylegen::Color.from_hex("#FF8000", 0.5)
22
- assert_equal 0.5, color.alpha
21
+ color = Stylegen::Color.from_hex('#FF8000', 0.5)
22
+ assert_in_delta(0.5, color.alpha)
23
23
  end
24
24
 
25
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
26
+ color = Stylegen::Color.from_hex('#FC0')
27
+ assert_in_delta(1.0, color.red)
28
+ assert_in_delta(0.8000000000000002, color.green)
29
+ assert_in_delta(0.0, color.blue)
30
+ assert_in_delta(1.0, color.alpha)
31
31
 
32
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
33
+ color = Stylegen::Color.from_hex('FC0')
34
+ assert_in_delta(1.0, color.red)
35
+ assert_in_delta(0.8000000000000002, color.green)
36
+ assert_in_delta(0.0, color.blue)
37
+ assert_in_delta(1.0, color.alpha)
38
38
  end
39
39
 
40
40
  def test_grayscale
@@ -46,7 +46,7 @@ class TestColor < MiniTest::Test
46
46
  end
47
47
 
48
48
  def test_to_string
49
- color = Stylegen::Color.from_hex("#00FF00")
49
+ color = Stylegen::Color.from_hex('#00FF00')
50
50
 
51
51
  expected = <<~CODE.strip
52
52
  ThemeColor(
@@ -57,11 +57,11 @@ class TestColor < MiniTest::Test
57
57
  )
58
58
  CODE
59
59
 
60
- assert_equal expected, color.to_s("ThemeColor")
60
+ assert_equal expected, color.to_s('ThemeColor')
61
61
 
62
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")
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
66
  end
67
67
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
3
+ require_relative 'helper'
4
4
 
5
5
  class TestLightDarkColor < MiniTest::Test
6
6
  def test_to_string
7
7
  color = Stylegen::LightDarkColor.new(
8
- Stylegen::Color.from_hex("#FFFFFF"),
9
- Stylegen::Color.from_hex("#333333")
8
+ Stylegen::Color.from_hex('#FFFFFF'),
9
+ Stylegen::Color.from_hex('#333333')
10
10
  )
11
11
 
12
12
  # Default indentation
@@ -18,7 +18,7 @@ class TestLightDarkColor < MiniTest::Test
18
18
  )
19
19
  CODE
20
20
 
21
- assert_equal expected, color.to_s("ThemeColor")
21
+ assert_equal expected, color.to_s('ThemeColor')
22
22
 
23
23
  # Additional indentation
24
24
 
@@ -29,6 +29,6 @@ class TestLightDarkColor < MiniTest::Test
29
29
  )
30
30
  CODE
31
31
 
32
- assert_equal expected, color.to_s("ThemeColor", 4)
32
+ assert_equal expected, color.to_s('ThemeColor', 4)
33
33
  end
34
34
  end
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.0
4
+ version: 0.5.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: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -144,6 +144,7 @@ executables:
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
+ - ".deepsource.toml"
147
148
  - ".github/workflows/ci.yml"
148
149
  - ".gitignore"
149
150
  - ".rubocop.yml"
@@ -192,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.7.6
196
+ rubygems_version: 3.1.2
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Tool for generating styling code for iOS apps