spectra 0.1.1
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 +7 -0
- data/.gitignore +27 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/bin/spectra +28 -0
- data/lib/spectra/components.rb +62 -0
- data/lib/spectra/dsl.rb +52 -0
- data/lib/spectra/extensions.rb +47 -0
- data/lib/spectra/logger.rb +12 -0
- data/lib/spectra/models.rb +57 -0
- data/lib/spectra/serializer.rb +60 -0
- data/lib/spectra/templates/factory.rb +23 -0
- data/lib/spectra/templates/objc_category.mustache +22 -0
- data/lib/spectra/templates/objc_category.rb +58 -0
- data/lib/spectra/templates/palette.mustache +4 -0
- data/lib/spectra/templates/palette.rb +27 -0
- data/lib/spectra/templates/swift_extension.mustache +21 -0
- data/lib/spectra/templates/swift_extension.rb +23 -0
- data/lib/spectra/templates/template.rb +73 -0
- data/lib/spectra/version.rb +3 -0
- data/lib/spectra.rb +31 -0
- data/spectra.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee1b6454f86dcc042a8b03acd6cf8660aa6baa86
|
4
|
+
data.tar.gz: 970a196f54c7562ed965fd13bf551b5eeb3f77e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbdcb8d68ee9cc39eee38d0df5085da70973af302e0ba8feee1e8f7ff66dde156a6b1bb9411d0b37f8d51e1f994b6c83281be83b029d6556537885ec9a0960df
|
7
|
+
data.tar.gz: b86738e123ee3d95ade7f5ceab28bd013bbea8a7d034b05078cdf48a41dd7658bb2bf2d8a9bebadaad5031164037055879fc8a72993a590d116144add2aa5e32
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
spectrum.rb
|
25
|
+
.ruby-version
|
26
|
+
.ruby-gemset
|
27
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ty Cobb
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Spectra
|
2
|
+
========
|
3
|
+
Keep app-specific colors in-sync across all your tools with a single specification!
|
4
|
+
|
5
|
+
Spectra is a command-line utility and Ruby DSL that generates color palettes (.clr), Objective-C categories, and Swift extensions. Define a spectrum.rb file and then run spectra from the terminal. That's all there is to it.
|
6
|
+
|
7
|
+
## Using the DSL: spectrum.rb
|
8
|
+
|
9
|
+
Specifying a class/method prefix (required):
|
10
|
+
```ruby
|
11
|
+
prefix :spc # subsitute your desired prefix
|
12
|
+
```
|
13
|
+
|
14
|
+
Specifying output formats (optional, defaults to `:palette` and `:objc`):
|
15
|
+
```ruby
|
16
|
+
|
17
|
+
## if you don't care about options
|
18
|
+
formats :palette, :swift
|
19
|
+
|
20
|
+
## if you want to specify the output directory
|
21
|
+
format :objc, 'path/to/categories'
|
22
|
+
|
23
|
+
## if you want to customize the method/color names
|
24
|
+
format :swift, 'path/to/extensions' do |name, prefix|
|
25
|
+
name.camelize(true) # SyntacticRogueRed
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Specifying colors (optional, but it's pretty pointless not to):
|
30
|
+
```ruby
|
31
|
+
color :red, (components 255, 0, 130)
|
32
|
+
color :gray, (hex 0xEEEEEE 0.6)
|
33
|
+
color :white, (white 1.0)
|
34
|
+
color :overlay (components 0.8, 0.7, 0.2, 0.75)
|
35
|
+
|
36
|
+
## alternate syntax
|
37
|
+
|
38
|
+
color :red, red: 255, blue: 130
|
39
|
+
color :gray, hex: 0xEEEEEE, a: 0.6
|
40
|
+
color :white, w: 1.0
|
41
|
+
color :overlay, r: 0.8, g: 0.7, b: 0.2, a: 0.75
|
42
|
+
```
|
data/Rakefile
ADDED
data/bin/spectra
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spectra'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = OpenStruct.new
|
8
|
+
options.verbose = false
|
9
|
+
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = 'usage: spectra [-vh]'
|
12
|
+
|
13
|
+
opts.on('-v', '--verbose', 'Enables verbose debugging output') do |flag|
|
14
|
+
options.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-d', '--dry-run', 'Processes colors without writing anything to disk') do |flag|
|
18
|
+
options.dry_run = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-h', '--help', 'Shows this message') do |flag|
|
22
|
+
puts opts; exit
|
23
|
+
end
|
24
|
+
|
25
|
+
end.parse!(ARGV)
|
26
|
+
|
27
|
+
Spectra.generate(options)
|
28
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
module Spectra
|
3
|
+
|
4
|
+
module Components
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :valid
|
8
|
+
end
|
9
|
+
|
10
|
+
self.valid = [ :red, :green, :blue, :white, :alpha ]
|
11
|
+
|
12
|
+
def self.componentize(attributes)
|
13
|
+
components = self.map_attributes(attributes).pick(*self.valid)
|
14
|
+
hex, white = attributes[:hex], components[:white]
|
15
|
+
|
16
|
+
components[:alpha] ||= 1.0
|
17
|
+
components.merge!(self.componentize_hex(hex)) if hex
|
18
|
+
components.merge!(self.componentize_white(white)) if white
|
19
|
+
|
20
|
+
components.each { |key, value| components[key] = self.normalize(value) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.valid?(name)
|
24
|
+
self.valid.include?(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
## Helpers
|
29
|
+
##
|
30
|
+
|
31
|
+
def self.componentize_hex(value)
|
32
|
+
hex = value.is_a?(String) ? value.to_i : value
|
33
|
+
Hash.new.tap do |hash|
|
34
|
+
hash[:red] = (hex & 0xFF0000) >> 16
|
35
|
+
hash[:green] = (hex & 0x00FF00) >> 8
|
36
|
+
hash[:blue] = (hex & 0x0000FF)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.componentize_white(value)
|
41
|
+
{ red: value, green: value, blue: value }
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
## Helpers
|
46
|
+
##
|
47
|
+
|
48
|
+
def self.normalize(number)
|
49
|
+
number = number / 255.0 if number.is_a?(Fixnum)
|
50
|
+
raise "component #{number} is not in a legible format" unless number.is_a?(Float)
|
51
|
+
number.limit(0.0..1.0)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.map_attributes(attributes)
|
55
|
+
key_map = { r: :red, g: :green, b: :blue, w: :white, a: :alpha }
|
56
|
+
return Hash[attributes.map { |key, value| [ key_map[key] || key, value ] }]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
data/lib/spectra/dsl.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require 'spectra/components'
|
3
|
+
require 'spectra/serializer'
|
4
|
+
|
5
|
+
module Spectra
|
6
|
+
|
7
|
+
module DSL
|
8
|
+
def prefix(prefix)
|
9
|
+
self._prefix = prefix
|
10
|
+
end
|
11
|
+
|
12
|
+
def formats(*types)
|
13
|
+
types.each { |type| format(type) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def format(type, path = nil, &renamer)
|
17
|
+
self.serializers ||= []
|
18
|
+
|
19
|
+
serializers = Serializer.from_type(type, {
|
20
|
+
path: path,
|
21
|
+
template: { type: type, renamer: renamer }
|
22
|
+
})
|
23
|
+
self.serializers.concat(serializers)
|
24
|
+
|
25
|
+
serializers.each { |serializer| Spectra.logger.debug "dsl add: #{serializer}" }
|
26
|
+
end
|
27
|
+
|
28
|
+
def color(name, attributes)
|
29
|
+
self.colors ||= []
|
30
|
+
|
31
|
+
color = Color.new(name, Components.componentize(attributes))
|
32
|
+
self.colors << color
|
33
|
+
|
34
|
+
Spectra.logger.debug "dsl add: #{color}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def components(*components)
|
38
|
+
components.hash_from(:red, :green, :blue, :alpha)
|
39
|
+
end
|
40
|
+
|
41
|
+
def hex(*components)
|
42
|
+
components.hash_from(:hex, :alpha)
|
43
|
+
end
|
44
|
+
|
45
|
+
def white(*components)
|
46
|
+
components.hash_from(:white, :alpha)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
|
4
|
+
def hash_from(*keys)
|
5
|
+
Hash[ keys.first(self.length).zip(self) ]
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
class Hash
|
11
|
+
|
12
|
+
def pick(*keys)
|
13
|
+
self.select { |key, value| keys.include?(key) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def deep_merge(hash)
|
17
|
+
worker = proc do |key, source, update|
|
18
|
+
if source.is_a?(Hash) && update.is_a?(Hash)
|
19
|
+
source.merge(update, &worker)
|
20
|
+
else
|
21
|
+
update
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
self.merge(hash, &worker)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class Numeric
|
31
|
+
|
32
|
+
def limit(range)
|
33
|
+
self > range.max ? range.max : self < range.min ? range.min : self
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class Symbol
|
39
|
+
|
40
|
+
def camelize(pascal)
|
41
|
+
self.to_s.split('_').map.with_index do |component, index|
|
42
|
+
!pascal && index == 0 ? component : component.capitalize
|
43
|
+
end.join('')
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
require 'spectra/extensions'
|
3
|
+
require 'spectra/components'
|
4
|
+
require 'spectra/dsl'
|
5
|
+
|
6
|
+
module Spectra
|
7
|
+
|
8
|
+
class Root
|
9
|
+
|
10
|
+
attr_accessor :_prefix
|
11
|
+
attr_accessor :colors, :serializers
|
12
|
+
|
13
|
+
include DSL
|
14
|
+
|
15
|
+
def generate(definition)
|
16
|
+
self.instance_eval(definition)
|
17
|
+
self.formats(:palette, :objc) unless self.serializers
|
18
|
+
|
19
|
+
self.serializers.each do |serializer|
|
20
|
+
serializer.serialize({
|
21
|
+
colors: self.colors,
|
22
|
+
prefix: self._prefix,
|
23
|
+
})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class Color
|
30
|
+
|
31
|
+
attr_accessor :name, :components
|
32
|
+
|
33
|
+
def initialize(name, components)
|
34
|
+
self.name = name
|
35
|
+
self.components = components
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_to?(name)
|
39
|
+
super || Components.valid?(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(name)
|
43
|
+
Components.valid?(name) ? self.components[name] : super
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
## Debugging
|
48
|
+
##
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
"<color: #{name} colors: #{components.values_at(:red, :green, :blue, :alpha).map{|v| v.is_a?(String) ? v : '%.2f' % (v || 0.0) }}>"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
require 'spectra/extensions'
|
3
|
+
require 'spectra/templates/factory'
|
4
|
+
|
5
|
+
module Spectra
|
6
|
+
|
7
|
+
class Serializer
|
8
|
+
|
9
|
+
attr_accessor :template, :path
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
self.path = attributes[:path]
|
13
|
+
self.template = Template.from_attributes(attributes[:template])
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialize(attributes)
|
17
|
+
text = self.template.render(attributes)
|
18
|
+
path = self.resource_path(attributes)
|
19
|
+
|
20
|
+
Spectra.logger.debug "#{Spectra.options.dry_run ? 'would write' : 'writing'} to: #{path}"
|
21
|
+
|
22
|
+
if Spectra.options.dry_run
|
23
|
+
Spectra.logger.debug "\n#{text}"
|
24
|
+
else
|
25
|
+
File.open(path, 'w+') { |file| file.write(text) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def resource_path(attributes)
|
30
|
+
resource_path = self.path || self.template.path
|
31
|
+
resource_path << '/' unless resource_path.end_with?('/')
|
32
|
+
resource_path + self.template.filename
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
## Factory
|
37
|
+
##
|
38
|
+
|
39
|
+
def self.from_type(type, attributes)
|
40
|
+
case type.intern
|
41
|
+
when :palette, :swift
|
42
|
+
[ Serializer.new(attributes) ]
|
43
|
+
when :objc
|
44
|
+
[ Serializer.new(attributes.deep_merge(template: { is_header: true })), Serializer.new(attributes) ]
|
45
|
+
else raise "Specfied an invalid serializer type: #{type}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
## Debugging
|
51
|
+
##
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
"<serializer => #{self.path || './'}, #{self.template}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'spectra/templates/palette'
|
3
|
+
require 'spectra/templates/objc_category'
|
4
|
+
require 'spectra/templates/swift_extension'
|
5
|
+
|
6
|
+
module Spectra
|
7
|
+
|
8
|
+
class Template
|
9
|
+
|
10
|
+
def self.from_attributes(attributes)
|
11
|
+
case attributes[:type].intern
|
12
|
+
when :palette
|
13
|
+
Palette.new(attributes)
|
14
|
+
when :objc
|
15
|
+
ObjcCategory.new(attributes)
|
16
|
+
when :swift
|
17
|
+
SwiftExtension.new(attributes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
//
|
2
|
+
// UIColor+{{class_prefix}}Color.{{file_extension}}
|
3
|
+
// This file is generated by Spectra, so don't expect to make any persistent changes
|
4
|
+
//
|
5
|
+
|
6
|
+
@{{file_keyword}} UIColor ({{class_prefix}}Color)
|
7
|
+
|
8
|
+
{{#colors}}
|
9
|
+
+ (UIColor *){{name}}{{#is_header}};{{/is_header}}
|
10
|
+
{{^is_header}}
|
11
|
+
{
|
12
|
+
{{#white}}
|
13
|
+
return [UIColor colorWithWhite:{{white}} alpha:{{alpha}}];
|
14
|
+
{{/white}}
|
15
|
+
{{^white}}
|
16
|
+
return [UIColor colorWithRed:{{red}} green:{{green}} blue:{{blue}} alpha:{{alpha}}];
|
17
|
+
{{/white}}
|
18
|
+
}
|
19
|
+
|
20
|
+
{{/is_header}}
|
21
|
+
{{/colors}}{{whitespace}}@end
|
22
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
require 'spectra/templates/template'
|
3
|
+
|
4
|
+
module Spectra
|
5
|
+
|
6
|
+
class ObjcCategory < Template
|
7
|
+
|
8
|
+
attr_accessor :is_header
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
super
|
12
|
+
self.is_header = attributes[:is_header]
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
## Templating
|
17
|
+
##
|
18
|
+
|
19
|
+
def class_prefix
|
20
|
+
self.prefix.upcase
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_keyword
|
24
|
+
self.is_header ? "interface" : "implementation"
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_extension
|
28
|
+
self.is_header ? 'h' : 'm'
|
29
|
+
end
|
30
|
+
|
31
|
+
def whitespace
|
32
|
+
self.is_header ? "\n" : ''
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
## Formatting
|
37
|
+
##
|
38
|
+
|
39
|
+
def format_color_value(value)
|
40
|
+
'%.2f' % (value || 0.0) + 'f'
|
41
|
+
end
|
42
|
+
|
43
|
+
def renamer
|
44
|
+
@renamer ||= lambda { |name, prefix| "#{prefix}_#{name.camelize(false)}Color" }
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
## Pathing Hooks
|
49
|
+
##
|
50
|
+
|
51
|
+
def filename
|
52
|
+
"UIColor+#{self.class_prefix}Color.#{self.file_extension}"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
require 'spectra/templates/template'
|
3
|
+
|
4
|
+
module Spectra
|
5
|
+
|
6
|
+
class Palette < Template
|
7
|
+
|
8
|
+
def renamer
|
9
|
+
@renamer ||= lambda { |name, prefix| name.camelize(true) }
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
## Pathing
|
14
|
+
##
|
15
|
+
|
16
|
+
def path
|
17
|
+
"#{Dir.home}/Library/Colors/"
|
18
|
+
end
|
19
|
+
|
20
|
+
def filename
|
21
|
+
"#{self.prefix}-palette.clr"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
//
|
2
|
+
// Colors.swift
|
3
|
+
// This file is generated by Spectra, so don't expect to make any persistent changes
|
4
|
+
//
|
5
|
+
|
6
|
+
import UIKit
|
7
|
+
|
8
|
+
extension UIColor {
|
9
|
+
|
10
|
+
{{#colors}}
|
11
|
+
class func {{name}}() -> UIColor {
|
12
|
+
{{#white}}
|
13
|
+
return UIColor(white: {{white}}, alpha: {{alpha}})
|
14
|
+
{{/white}}
|
15
|
+
{{^white}}
|
16
|
+
return UIColor(red: {{red}}, green: {{green}}, blue: {{blue}}, alpha: {{alpha}})
|
17
|
+
{{/white}}
|
18
|
+
}
|
19
|
+
|
20
|
+
{{/colors}}}
|
21
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'spectra/templates/template'
|
3
|
+
|
4
|
+
module Spectra
|
5
|
+
|
6
|
+
class SwiftExtension < Template
|
7
|
+
|
8
|
+
def renamer
|
9
|
+
@renamer ||= lambda { |name, prefix| name.camelize(true) }
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
## Pathing
|
14
|
+
##
|
15
|
+
|
16
|
+
def filename
|
17
|
+
return 'Colors.swift'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
require 'mustache'
|
3
|
+
|
4
|
+
module Spectra
|
5
|
+
|
6
|
+
class Template < Mustache
|
7
|
+
|
8
|
+
attr_accessor :renamer, :colors, :prefix
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
self.renamer = attributes[:renamer]
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
## Mustache
|
16
|
+
##
|
17
|
+
|
18
|
+
self.path = 'lib/spectra/templates'
|
19
|
+
|
20
|
+
def self.template_name
|
21
|
+
super.split('/').last
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
## Rendering
|
26
|
+
##
|
27
|
+
|
28
|
+
def render(attributes)
|
29
|
+
self.prefix = attributes[:prefix]
|
30
|
+
self.colors = parse_colors(attributes[:colors])
|
31
|
+
super() # offload to Mustache
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_colors(colors)
|
35
|
+
colors.map { |color| self.parse_color(color) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_color(color)
|
39
|
+
copy = color.clone
|
40
|
+
copy.name = self.format_color_name(color)
|
41
|
+
copy.components = color.components.map do |key, value|
|
42
|
+
[ key, self.format_color_value(value) ]
|
43
|
+
end.to_h
|
44
|
+
copy
|
45
|
+
end
|
46
|
+
|
47
|
+
def format_color_name(color)
|
48
|
+
self.renamer.call(color.name, self.prefix)
|
49
|
+
end
|
50
|
+
|
51
|
+
def format_color_value(value)
|
52
|
+
'%.2f' % (value || 0.0)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
## Pathing
|
57
|
+
##
|
58
|
+
|
59
|
+
def path
|
60
|
+
'./'
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
## Debugging
|
65
|
+
##
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
"<template: #{self.class.name} renamer: #{@renamer}>"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/lib/spectra.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require 'spectra/version'
|
3
|
+
require 'spectra/logger'
|
4
|
+
require 'spectra/models'
|
5
|
+
|
6
|
+
module Spectra
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :logger, :options
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.generate(options)
|
13
|
+
self.options = options
|
14
|
+
logger.level = options.verbose ? Logger::DEBUG : Logger::INFO
|
15
|
+
|
16
|
+
begin
|
17
|
+
definition = IO.read('spectrum.rb')
|
18
|
+
rescue Exception => execption
|
19
|
+
logger.terminate "Failed to read spectrum.rb file: #{execption}"
|
20
|
+
end
|
21
|
+
|
22
|
+
spectra = Root.new
|
23
|
+
spectra.generate(definition)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.logger
|
27
|
+
@logger ||= SpectraLogger.new(STDOUT)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
data/spectra.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spectra/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'spectra'
|
8
|
+
gem.version = Spectra::VERSION
|
9
|
+
gem.authors = ['Ty Cobb']
|
10
|
+
gem.email = ['ty.cobb.m@gmail.com']
|
11
|
+
gem.summary = %q{DSL for synchronizng color palettes, Objective-C categories, and Swift extensions}
|
12
|
+
gem.description = %q{DSL for synchronzing color palettes, Objective-C categories, and Swift extensions}
|
13
|
+
gem.homepage = 'https://github.com/derkis/Spectrum'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files -z`.split("\x0")
|
17
|
+
gem.executables = ['spectra']
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
gem.add_runtime_dependency 'mustache', '~> 0.99.6'
|
25
|
+
end
|
26
|
+
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spectra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ty Cobb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mustache
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.99.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.99.6
|
55
|
+
description: DSL for synchronzing color palettes, Objective-C categories, and Swift
|
56
|
+
extensions
|
57
|
+
email:
|
58
|
+
- ty.cobb.m@gmail.com
|
59
|
+
executables:
|
60
|
+
- spectra
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/spectra
|
70
|
+
- lib/spectra.rb
|
71
|
+
- lib/spectra/components.rb
|
72
|
+
- lib/spectra/dsl.rb
|
73
|
+
- lib/spectra/extensions.rb
|
74
|
+
- lib/spectra/logger.rb
|
75
|
+
- lib/spectra/models.rb
|
76
|
+
- lib/spectra/serializer.rb
|
77
|
+
- lib/spectra/templates/factory.rb
|
78
|
+
- lib/spectra/templates/objc_category.mustache
|
79
|
+
- lib/spectra/templates/objc_category.rb
|
80
|
+
- lib/spectra/templates/palette.mustache
|
81
|
+
- lib/spectra/templates/palette.rb
|
82
|
+
- lib/spectra/templates/swift_extension.mustache
|
83
|
+
- lib/spectra/templates/swift_extension.rb
|
84
|
+
- lib/spectra/templates/template.rb
|
85
|
+
- lib/spectra/version.rb
|
86
|
+
- spectra.gemspec
|
87
|
+
homepage: https://github.com/derkis/Spectrum
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: DSL for synchronizng color palettes, Objective-C categories, and Swift extensions
|
111
|
+
test_files: []
|