stylegen 0.1.0 → 0.2.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: 5882aa3fdd2e17f9e0fe683c07fd07d5c045f505a78a8ba7c5765edfc60a2c6e
4
- data.tar.gz: f583e4f26b3e4dccc121eceec5a7f5e4349f7210e660527aa07128f1401e2837
3
+ metadata.gz: 6880c6848932f2c2f954860a1885cfd20fda16e99f6ea01dd8c5fe5731658c45
4
+ data.tar.gz: b7f49e94a5c19dbe464b3c246cf1834b7477b118c006aea1eed9ebd0c548acd6
5
5
  SHA512:
6
- metadata.gz: d525975a51b7415c727b1f46299ec37283bcc2d2efbde3450cc361c4095c27abc7d2d606863676acc8f35950dbe885519cf1568fab89520fb731cf92812445d0
7
- data.tar.gz: 6aa2ac484c0697175a7f6e1ebf94221fcbf66f78e2ba11d3e351434c1949646bc3ff49e46ccf9895703327217a33e1c766d5eb9c3df1f9589b92f210ded81395
6
+ metadata.gz: d16722e424e033cd0d29b73ffa65358de4bdc490a3bf44736202f403bba405b6d4cb64499646dead5cc6185c71e0708d0977ac9688c4fd3baffd88f69ec6e546
7
+ data.tar.gz: 264639f5ff9bf1541f3670cf428c7390ec72d3746144501fa039eae7ce5a4b28f7bd3dfb72cc02ade6ce3ee9db6bdd844646ad1e11657dba9068afd9e70b0c5a
@@ -2,9 +2,9 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: "*"
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: "*"
8
8
 
9
9
  jobs:
10
10
  test:
@@ -28,5 +28,7 @@ jobs:
28
28
  with:
29
29
  ruby-version: ${{ matrix.ruby-version }}
30
30
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
+ - name: Lint
32
+ run: bundle exec rake rubocop
31
33
  - name: Run tests
32
34
  run: bundle exec rake
data/.gitignore CHANGED
@@ -1,2 +1,6 @@
1
1
  .idea
2
2
  pkg
3
+
4
+ # Testing artifacts
5
+ theme.yaml
6
+ Colors.swift
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stylegen (0.1.0)
5
- dry-inflector (>= 0.2.0)
6
- json_schemer (>= 0.2.0)
4
+ stylegen (0.2.0)
5
+ dry-inflector (~> 0.2.0)
6
+ gli (~> 2.1)
7
+ json_schemer (~> 0.2.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -12,6 +13,7 @@ GEM
12
13
  dry-inflector (0.2.0)
13
14
  ecma-re-validator (0.3.0)
14
15
  regexp_parser (~> 2.0)
16
+ gli (2.20.0)
15
17
  hana (1.3.7)
16
18
  json_schemer (0.2.17)
17
19
  ecma-re-validator (~> 0.3)
@@ -50,7 +52,7 @@ PLATFORMS
50
52
 
51
53
  DEPENDENCIES
52
54
  bundler
53
- minitest (>= 5.14.0)
55
+ minitest (~> 5.14)
54
56
  rake
55
57
  rubocop
56
58
  rubocop-minitest
data/README.md CHANGED
@@ -20,14 +20,20 @@ gem "stylegen"
20
20
 
21
21
  ## How to use
22
22
 
23
- Create a `theme.yaml` file in the root of your project. You can use the following YAML file as a starting point:
23
+ To use stylegen in your project, you will need to create a `theme.yaml` file at the root of the project by executing:
24
+
25
+ ```shell
26
+ $ stylegen init
27
+ ```
28
+
29
+ The generated YAML file will look similar to this:
24
30
 
25
31
  ```yaml
26
32
  # Name of the design system. Defaults to "Theme".
27
33
  # Feel free to use your company name, name of product,
28
34
  # or name of your design system.
29
35
  # e.g.: Primer, Material, Polaris, etc.
30
- system_name: "Theme"
36
+ # system_name: "Theme"
31
37
 
32
38
  # Path of generated Swift file.
33
39
  output_path: "Colors.swift"
@@ -38,7 +44,7 @@ colors:
38
44
  accent: # Keys will be used as color names.
39
45
  color: "#00BFC2" # Hex color
40
46
 
41
- # Shorthand syntax
47
+ # Shorthand syntax
42
48
  warning: "#ED4337"
43
49
 
44
50
  text_primary:
@@ -67,13 +73,14 @@ colors:
67
73
  elevated: "#191D1D"
68
74
  ```
69
75
 
70
- After creating the theme file run:
76
+ You can use your favorite text editor to edit the YAML file, then use the `build` sub-command to generate the Swift code:
71
77
 
72
78
  ```shell
73
- $ stylegen
79
+ $ stylegen build
74
80
  ```
75
81
 
76
- This will generate a Swift file that you can add to your target. The generated file will contain all the colors and utility methods for referencing the colors.
82
+ The generated file will contain all the colors and utility methods for referencing them. You must add this generated
83
+ file to your Xcode target to use it.
77
84
 
78
85
  In places where you normally do:
79
86
 
@@ -87,11 +94,12 @@ Now you can just do:
87
94
  self.backgroundColor = .theme(.accent)
88
95
  ```
89
96
 
90
- The `.theme()` static method serves as a namespace to easily distinguish between UIKit's built-in colors and our custom colors. The name of the namespacing function is inferred from the `system_name` property in the YAML file.
97
+ The `.theme()` static method serves as a namespace to easily distinguish between UIKit's built-in colors and our custom
98
+ colors. The name of the namespacing function gets inferred from the `system_name` property in the YAML file.
91
99
 
92
100
  ## TODO
93
101
 
94
- * `$ stylegen init` command
102
+ * ~~`$ stylegen init` command~~
95
103
  * Option to specify target frameworks: AppKit, UIKit, Core Graphics, and SwiftUI
96
104
  * SwiftUI support
97
105
  * AppKit support
data/Rakefile CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
5
6
 
6
7
  Rake::TestTask.new
8
+ RuboCop::RakeTask.new
7
9
 
8
10
  task default: :test
data/bin/stylegen CHANGED
@@ -1,31 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "yaml"
5
- require "optparse"
6
- require "stylegen"
4
+ require "stylegen/cli"
7
5
 
8
- @options = {}
9
-
10
- OptionParser.new do |opts|
11
- opts.on_tail("--version", "Show version") do
12
- puts Stylegen::VERSION
13
- exit
14
- end
15
- end.parse!
16
-
17
- data = File.open("theme.yaml") { |file| YAML.safe_load(file) }
18
-
19
- validator = Stylegen::Validator.new
20
- unless validator.valid?(data)
21
- warn "theme.yaml contains one or more errors:"
22
-
23
- validator.validate(data).each do |e|
24
- warn " #{e}"
25
- end
26
-
27
- exit(1)
28
- end
29
-
30
- generator = Stylegen::Generator.new(data)
31
- generator.generate
6
+ exit Stylegen::CLI::App.run(ARGV)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stylegen/cli/app"
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,42 @@
1
+ # Name of the design system. Defaults to "Theme".
2
+ # Feel free to use your company name, name of product,
3
+ # or name of your design system.
4
+ # e.g.: Primer, Material, Polaris, etc.
5
+ # system_name: "Theme"
6
+
7
+ # Path of generated Swift file.
8
+ output_path: "Colors.swift"
9
+
10
+ # Key-value pairs of theme colors.
11
+ colors:
12
+
13
+ accent: # Keys will be used as color names.
14
+ color: "#00BFC2" # Hex color
15
+
16
+ # Shorthand syntax
17
+ warning: "#ED4337"
18
+
19
+ text_primary:
20
+ light: # Value for light mode
21
+ color: "#000000"
22
+ # Optionally you can specify an alpha value.
23
+ # Defaults to `1.0`.
24
+ alpha: 0.95
25
+ dark: # Value for dark mode
26
+ color: "#FFFFFF"
27
+
28
+ text_secondary:
29
+ light:
30
+ color: "#000000"
31
+ alpha: 0.4
32
+ dark:
33
+ color: "#FFFFFF"
34
+ alpha: 0.6
35
+
36
+ primary_background:
37
+ light: "#FFFFFF"
38
+ dark:
39
+ # Value for base (non-elevated) level
40
+ base: "#0D0D0D"
41
+ # Value for elevated level
42
+ elevated: "#191D1D"
data/lib/stylegen/data.rb CHANGED
@@ -43,8 +43,8 @@ module Stylegen
43
43
  end
44
44
 
45
45
  def colors
46
- @data["colors"].each do |key, value|
47
- yield inflector.camelize_lower(key), generate_color(value)
46
+ @colors ||= @data["colors"].map do |key, value|
47
+ [inflector.camelize_lower(key), generate_color(value)]
48
48
  end
49
49
  end
50
50
 
@@ -20,6 +20,10 @@ module Stylegen
20
20
  generate_extensions
21
21
  end
22
22
 
23
+ def stats
24
+ @stats ||= { output_path: @data.output_path, color_count: @data.colors.count }
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def generate_header
@@ -89,7 +93,7 @@ module Stylegen
89
93
  out "#{@data.access_level} extension #{@data.struct_name} {"
90
94
  out ""
91
95
 
92
- @data.colors do |member, color|
96
+ @data.colors.each do |member, color|
93
97
  out " static let #{member} = #{color.to_s(@data.struct_name, 4)}"
94
98
  out ""
95
99
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stylegen
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/stylegen.gemspec CHANGED
@@ -16,11 +16,12 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
  s.license = "MIT"
18
18
 
19
- s.add_runtime_dependency "dry-inflector", ">= 0.2.0"
20
- 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"
21
22
 
22
23
  s.add_development_dependency "bundler"
23
- s.add_development_dependency "minitest", ">= 5.14.0"
24
+ s.add_development_dependency "minitest", "~> 5.14"
24
25
  s.add_development_dependency "rake"
25
26
  s.add_development_dependency "rubocop"
26
27
  s.add_development_dependency "rubocop-minitest"
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylegen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-01-23 00:00:00.000000000 Z
11
+ date: 2021-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.2.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
26
  version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: gli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: json_schemer
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: 0.2.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 0.2.0
41
55
  - !ruby/object:Gem::Dependency
@@ -56,16 +70,16 @@ dependencies:
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 5.14.0
75
+ version: '5.14'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 5.14.0
82
+ version: '5.14'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +154,9 @@ files:
140
154
  - Rakefile
141
155
  - bin/stylegen
142
156
  - lib/stylegen.rb
157
+ - lib/stylegen/cli.rb
158
+ - lib/stylegen/cli/app.rb
159
+ - lib/stylegen/cli/template.yaml
143
160
  - lib/stylegen/colors.rb
144
161
  - lib/stylegen/colors/base_elevated_color.rb
145
162
  - lib/stylegen/colors/color.rb
@@ -173,8 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
190
  - !ruby/object:Gem::Version
174
191
  version: '0'
175
192
  requirements: []
176
- rubyforge_project:
177
- rubygems_version: 2.7.6
193
+ rubygems_version: 3.0.3
178
194
  signing_key:
179
195
  specification_version: 4
180
196
  summary: Tool for generating styling code for iOS apps