spectra 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/spectra +1 -61
- data/lib/spectra/commands.rb +99 -0
- data/lib/spectra/{color.rb → models/color.rb} +1 -2
- data/lib/spectra/{components.rb → models/components.rb} +1 -3
- data/lib/spectra/models/spectrum.rb +60 -0
- data/lib/spectra/template.rb +3 -9
- data/lib/spectra/utilities.rb +115 -0
- data/lib/spectra/version.rb +1 -1
- data/lib/spectra/views/palette.mustache +1 -0
- data/lib/spectra/views/serializable.rb +34 -23
- data/lib/spectra/views/view.rb +0 -2
- data/lib/spectra.rb +3 -45
- data/spectra.gemspec +5 -2
- metadata +55 -13
- data/lib/spectra/spectrum.rb +0 -57
- data/lib/spectra/utilities/extensions.rb +0 -47
- data/lib/spectra/utilities/logger.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6196e19e6dd376e660f847d8c8182d7043e43a7a
|
4
|
+
data.tar.gz: 1f239074435518c4d00af6e69dda7848a32ae311
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d52e986caab621c77e2696a4fe2fb8575a777138c0e74526856319f5677cf920f4c4058e34901189767fbe5f10a81254dc3a1483ab6257553b3eacd50591d2f
|
7
|
+
data.tar.gz: 231e70574e51600740350005396ee877a6df38f62aaebed06004832832af9f9749131c1869de1fa7bea59d097942b07b4f605681bd754732dca4b769b9a17350
|
data/bin/spectra
CHANGED
@@ -1,66 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'spectra'
|
4
|
-
require 'ostruct'
|
5
|
-
require 'optparse'
|
6
4
|
|
7
|
-
|
8
|
-
subcommands:
|
9
|
-
+ create: creates a template spectrum.rb file
|
10
|
-
)
|
11
|
-
|
12
|
-
command_descriptions = {
|
13
|
-
base: %Q(
|
14
|
-
Invoke without a subcommand to generate colors from the spectrum.rb in the current directory
|
15
|
-
),
|
16
|
-
create: %Q(
|
17
|
-
Creates a template spectrum.rb file populated with instructional defualts in the current directory.
|
18
|
-
)}
|
19
|
-
|
20
|
-
options = OpenStruct.new
|
21
|
-
|
22
|
-
main = OptionParser.new do |opts|
|
23
|
-
opts.banner = 'usage: spectra [options] [subcommand [options]]'
|
24
|
-
|
25
|
-
opts.separator command_descriptions[:base][1..-1]
|
26
|
-
opts.separator "\noptions:"
|
27
|
-
|
28
|
-
opts.on('-v', '--verbose', 'Enables verbose debugging output') do |flag|
|
29
|
-
options.verbose = flag
|
30
|
-
end
|
31
|
-
|
32
|
-
opts.on('-d', '--dry-run', 'Processes colors without writing anything to disk') do |flag|
|
33
|
-
options.dry_run = flag
|
34
|
-
end
|
35
|
-
|
36
|
-
opts.on('-h', '--help', 'Shows this message') do
|
37
|
-
puts opts; exit
|
38
|
-
end
|
39
|
-
|
40
|
-
opts.separator command_list
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
subcommands = {
|
45
|
-
create: OptionParser.new do |opts|
|
46
|
-
opts.banner = 'usage: create'
|
47
|
-
opts.separator command_descriptions[:create][1..-1]
|
48
|
-
|
49
|
-
opts.separator "\noptions"
|
50
|
-
opts.on('-h', '--help', 'Shows this message') do
|
51
|
-
puts opts; exit
|
52
|
-
end
|
53
|
-
end
|
54
|
-
}
|
55
|
-
|
56
|
-
main.order! # order parses all possible arguments desctructively (in order, duh)
|
57
|
-
subcommand = ARGV.shift.intern
|
58
|
-
subcommands[subcommand].order! if subcommand
|
59
|
-
|
60
|
-
case subcommand
|
61
|
-
when :create
|
62
|
-
Spectra.create(options);
|
63
|
-
else
|
64
|
-
Spectra.generate(options)
|
65
|
-
end
|
5
|
+
Spectra::Command.run(ARGV)
|
66
6
|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
require 'claide'
|
3
|
+
require 'spectra/models/spectrum'
|
4
|
+
|
5
|
+
module Spectra
|
6
|
+
|
7
|
+
class Command < CLAide::Command
|
8
|
+
|
9
|
+
self.abstract_command = true
|
10
|
+
self.default_subcommand = 'generate'
|
11
|
+
|
12
|
+
self.command = 'spectra'
|
13
|
+
self.summary = 'Serializes colors into a variety of filetypes using a convenient ruby DSL'
|
14
|
+
|
15
|
+
##
|
16
|
+
## Subcommands
|
17
|
+
##
|
18
|
+
|
19
|
+
class Generate < Command
|
20
|
+
|
21
|
+
self.summary = 'Serializes output color files (default)'
|
22
|
+
|
23
|
+
self.description = <<-DESC
|
24
|
+
If no subcommand is specified, this is the default.
|
25
|
+
|
26
|
+
Processes and generates files from the spectrum.rb file in the current directory. Colors
|
27
|
+
specified therein will be serialized into the denoted filetypes, overwriting any existing
|
28
|
+
files at those locations.
|
29
|
+
DESC
|
30
|
+
|
31
|
+
def self.options
|
32
|
+
[[
|
33
|
+
'--dry-run', 'Prints the would-be output file rather than generating anything'
|
34
|
+
]].concat(super)
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(argv)
|
38
|
+
# update config from options
|
39
|
+
Config.dry_run = argv.flag?('dry-run', false)
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate!
|
44
|
+
super
|
45
|
+
begin
|
46
|
+
@definition = IO.read('spectrum.rb')
|
47
|
+
rescue Exception
|
48
|
+
raise Informative, 'Failed to find a spectrum.rb file in the current directory'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def run
|
53
|
+
# generate the views from the user's spectrum.rb
|
54
|
+
spectrum = Spectra::Spectrum.new
|
55
|
+
spectrum.generate(@definition)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class Init < Command
|
61
|
+
|
62
|
+
attr_accessor :source, :destination
|
63
|
+
|
64
|
+
self.summary = 'Creates a template spectrum.rb file'
|
65
|
+
|
66
|
+
self.description = <<-DESC
|
67
|
+
Creates a template spectrum.rb file in the current directiory. The template file contains
|
68
|
+
instructional defaults to demonstrate spectra's features to the uninitiated.
|
69
|
+
DESC
|
70
|
+
|
71
|
+
def initialize(argv)
|
72
|
+
super
|
73
|
+
self.source = File.dirname(__FILE__) + '/template.rb'
|
74
|
+
self.destination = "#{Dir.pwd}/spectrum.rb"
|
75
|
+
end
|
76
|
+
|
77
|
+
def validate!
|
78
|
+
super
|
79
|
+
raise Informative, "#{self.destination} already exists" if File.file?(self.destination)
|
80
|
+
end
|
81
|
+
|
82
|
+
def run
|
83
|
+
begin
|
84
|
+
IO.copy_stream(self.source, self.destination)
|
85
|
+
rescue Exception => exception
|
86
|
+
message = 'Failed to create spectrum.rb'
|
87
|
+
message += "\n#{exception}"
|
88
|
+
raise Informative, message
|
89
|
+
else
|
90
|
+
Spectra.logger.debug "[✓] Created #{self.destination}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end # module
|
99
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
require 'spectra/models/color'
|
3
|
+
require 'spectra/views/factory'
|
4
|
+
|
5
|
+
module Spectra
|
6
|
+
|
7
|
+
class Spectrum
|
8
|
+
|
9
|
+
attr_accessor :_prefix
|
10
|
+
attr_accessor :colors, :views
|
11
|
+
|
12
|
+
def generate(definition)
|
13
|
+
# evaluate color definition file, setup defaults
|
14
|
+
self.instance_eval(definition)
|
15
|
+
self.formats(:palette, :objc) unless self.views
|
16
|
+
|
17
|
+
# render views according to the specification
|
18
|
+
self.views.each do |view|
|
19
|
+
view.serialize({ colors: self.colors, prefix: self._prefix })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
## DSL
|
25
|
+
##
|
26
|
+
|
27
|
+
def prefix(prefix)
|
28
|
+
self._prefix = prefix
|
29
|
+
end
|
30
|
+
|
31
|
+
def formats(*types)
|
32
|
+
types.each { |type| format(type) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def format(type, directory = nil, &renamer)
|
36
|
+
self.views ||= []
|
37
|
+
self.views.concat(Views.from_attributes({ type: type, directory: directory, renamer: renamer }))
|
38
|
+
end
|
39
|
+
|
40
|
+
def color(name, attributes)
|
41
|
+
self.colors ||= []
|
42
|
+
self.colors << Color.new(name, Components.componentize(attributes))
|
43
|
+
end
|
44
|
+
|
45
|
+
def components(*components)
|
46
|
+
components.hash_from(:red, :green, :blue, :alpha)
|
47
|
+
end
|
48
|
+
|
49
|
+
def hex(*components)
|
50
|
+
components.hash_from(:hex, :alpha)
|
51
|
+
end
|
52
|
+
|
53
|
+
def white(*components)
|
54
|
+
components.hash_from(:white, :alpha)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
data/lib/spectra/template.rb
CHANGED
@@ -2,22 +2,16 @@
|
|
2
2
|
## replace with your desired class/method prefix (used where applicable)
|
3
3
|
prefix :foo
|
4
4
|
|
5
|
-
##
|
6
|
-
|
7
|
-
## specify formats with `format` or `formats`
|
5
|
+
## specifiy the output formats using `format <type> [<output-path]`
|
8
6
|
format :palette
|
9
|
-
|
10
|
-
## replace path with your own personal category directory
|
11
7
|
format :objc, 'path/to/categories'
|
12
8
|
|
13
|
-
##
|
9
|
+
## customize the name generation for a specific format
|
14
10
|
# format :objc do |name, prefix|
|
15
11
|
# name.camelize(true)
|
16
12
|
# end
|
17
13
|
|
18
|
-
##
|
19
|
-
|
20
|
-
## note: the last component is always alpha, and can safely be omitted
|
14
|
+
## specify the colors to generate
|
21
15
|
color :red, (components 255, 0, 0, 1.0)
|
22
16
|
color :gray, (white 0.5, 1.0)
|
23
17
|
color :green, (hex 0x00ff00, 1.0)
|
@@ -0,0 +1,115 @@
|
|
1
|
+
##
|
2
|
+
## Exceptions
|
3
|
+
##
|
4
|
+
|
5
|
+
require 'claide'
|
6
|
+
|
7
|
+
module Spectra
|
8
|
+
class Informative < Exception
|
9
|
+
|
10
|
+
include CLAide::InformativeError
|
11
|
+
|
12
|
+
def message
|
13
|
+
"[!] #{super}".ansi.red
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
## Logger
|
21
|
+
##
|
22
|
+
|
23
|
+
require 'logger'
|
24
|
+
|
25
|
+
module Spectra
|
26
|
+
class << self
|
27
|
+
attr_accessor :logger
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.logger
|
31
|
+
unless @logger
|
32
|
+
@logger = Logger.new(STDOUT)
|
33
|
+
@logger.formatter = proc { |sev, date, prog, msg| msg + "\n" }
|
34
|
+
end
|
35
|
+
|
36
|
+
@logger
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
## Config
|
42
|
+
##
|
43
|
+
|
44
|
+
module Spectra
|
45
|
+
module Config
|
46
|
+
class << self
|
47
|
+
def attributes
|
48
|
+
@attributes ||= {}
|
49
|
+
end
|
50
|
+
|
51
|
+
def respond_to?(name)
|
52
|
+
key = parse_name(name)
|
53
|
+
super || self.attributes[key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def method_missing(name, *args)
|
57
|
+
key, is_setter = parse_name(name)
|
58
|
+
self.attributes[key] = args[0] if is_setter
|
59
|
+
self.attributes[key]
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_name(name)
|
63
|
+
key, is_setter = name.intern, false
|
64
|
+
|
65
|
+
if /^(\w+)=$/ =~ name
|
66
|
+
key, is_setter = $1.intern, true
|
67
|
+
end
|
68
|
+
|
69
|
+
return key, is_setter
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
## Extensions
|
77
|
+
##
|
78
|
+
|
79
|
+
class Numeric
|
80
|
+
def limit(range)
|
81
|
+
self > range.max ? range.max : self < range.min ? range.min : self
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Symbol
|
86
|
+
def camelize(pascal)
|
87
|
+
self.to_s.split('_').map.with_index do |component, index|
|
88
|
+
!pascal && index == 0 ? component : component.capitalize
|
89
|
+
end.join('')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Array
|
94
|
+
def hash_from(*keys)
|
95
|
+
Hash[ keys.first(self.length).zip(self) ]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Hash
|
100
|
+
def pick(*keys)
|
101
|
+
self.select { |key, value| keys.include?(key) }
|
102
|
+
end
|
103
|
+
|
104
|
+
def deep_merge(hash)
|
105
|
+
worker = proc do |key, source, update|
|
106
|
+
if source.is_a?(Hash) && update.is_a?(Hash)
|
107
|
+
source.merge(update, &worker)
|
108
|
+
else
|
109
|
+
update
|
110
|
+
end
|
111
|
+
end
|
112
|
+
self.merge(hash, &worker)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/lib/spectra/version.rb
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
|
2
2
|
module Spectra
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def destination(attributes)
|
22
|
-
destination = self.directory
|
23
|
-
destination << '/' unless destination.end_with?('/')
|
24
|
-
destination + self.filename
|
4
|
+
module Serializable
|
5
|
+
|
6
|
+
attr_accessor :directory, :filename
|
7
|
+
|
8
|
+
def serialize(attributes)
|
9
|
+
text = self.render(attributes)
|
10
|
+
path = self.destination(attributes)
|
11
|
+
|
12
|
+
begin
|
13
|
+
file = File.open(path, 'w+')
|
14
|
+
rescue Exception
|
15
|
+
raise Informative, "Couldn't open #{path}"
|
16
|
+
else
|
17
|
+
self.write_file(file, text, path)
|
18
|
+
ensure
|
19
|
+
file.close unless file.nil?
|
25
20
|
end
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
23
|
+
def write_file(file, text, path)
|
24
|
+
Spectra.logger.info "[✓] Generating #{path}"
|
25
|
+
if Config.dry_run
|
26
|
+
Spectra.logger.info "\n#{text}"
|
27
|
+
else
|
28
|
+
file.write(text)
|
29
29
|
end
|
30
|
+
end
|
30
31
|
|
32
|
+
def destination(attributes)
|
33
|
+
destination = self.directory
|
34
|
+
destination << '/' unless destination.end_with?('/')
|
35
|
+
destination + self.filename
|
31
36
|
end
|
32
37
|
|
38
|
+
def directory
|
39
|
+
@directory ||= './'
|
40
|
+
end
|
41
|
+
|
33
42
|
end
|
34
43
|
|
44
|
+
end # module
|
45
|
+
|
data/lib/spectra/views/view.rb
CHANGED
data/lib/spectra.rb
CHANGED
@@ -1,47 +1,5 @@
|
|
1
|
-
|
2
|
-
require 'spectra/version'
|
3
|
-
require 'spectra/spectrum'
|
4
|
-
require 'spectra/utilities/logger'
|
5
|
-
|
6
|
-
module Spectra
|
7
|
-
|
8
|
-
class << self
|
9
|
-
attr_accessor :logger, :options
|
10
|
-
end
|
11
1
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
begin
|
16
|
-
definition = IO.read('spectrum.rb')
|
17
|
-
rescue Exception => execption
|
18
|
-
logger.terminate "Failed to read spectrum.rb file: #{execption}"
|
19
|
-
end
|
20
|
-
|
21
|
-
spectrum = Spectrum.new
|
22
|
-
spectrum.generate(definition)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.create(options)
|
26
|
-
self.options = options
|
27
|
-
|
28
|
-
begin
|
29
|
-
IO.copy_stream(File.dirname(__FILE__) + '/spectra/template.rb', 'spectrum.rb')
|
30
|
-
rescue Exception => exception
|
31
|
-
logger.terminate "Failed to create spectrum.rb file: #{exception}"
|
32
|
-
else
|
33
|
-
logger.info "created #{Dir.pwd}/spectrum.rb"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.logger
|
38
|
-
@logger ||= SpectraLogger.new(STDOUT)
|
39
|
-
end
|
40
|
-
|
41
|
-
def options=(options)
|
42
|
-
@options = options
|
43
|
-
self.logger.level = options.verbose ? Logger::DEBUG : Logger::INFO
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
2
|
+
require 'spectra/version'
|
3
|
+
require 'spectra/utilities'
|
4
|
+
require 'spectra/commands'
|
47
5
|
|
data/spectra.gemspec
CHANGED
@@ -19,8 +19,11 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ['lib']
|
20
20
|
|
21
21
|
gem.add_development_dependency 'bundler', '~> 1.6'
|
22
|
-
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rake', '~> 10.4'
|
23
|
+
gem.add_development_dependency 'pry', '~> 0.10'
|
24
|
+
gem.add_development_dependency 'pry-byebug', '~> 2.0'
|
23
25
|
|
24
|
-
gem.add_runtime_dependency '
|
26
|
+
gem.add_runtime_dependency 'claide', '~> 0.8'
|
27
|
+
gem.add_runtime_dependency 'mustache', '~> 1.0'
|
25
28
|
end
|
26
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Cobb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,30 +28,72 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
47
|
+
version: '0.10'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: claide
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
82
|
+
version: '0.8'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: mustache
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - "~>"
|
46
88
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
89
|
+
version: '1.0'
|
48
90
|
type: :runtime
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
94
|
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
96
|
+
version: '1.0'
|
55
97
|
description: DSL for synchronzing color palettes, Objective-C categories, and Swift
|
56
98
|
extensions
|
57
99
|
email:
|
@@ -68,12 +110,12 @@ files:
|
|
68
110
|
- Rakefile
|
69
111
|
- bin/spectra
|
70
112
|
- lib/spectra.rb
|
71
|
-
- lib/spectra/
|
72
|
-
- lib/spectra/
|
73
|
-
- lib/spectra/
|
113
|
+
- lib/spectra/commands.rb
|
114
|
+
- lib/spectra/models/color.rb
|
115
|
+
- lib/spectra/models/components.rb
|
116
|
+
- lib/spectra/models/spectrum.rb
|
74
117
|
- lib/spectra/template.rb
|
75
|
-
- lib/spectra/utilities
|
76
|
-
- lib/spectra/utilities/logger.rb
|
118
|
+
- lib/spectra/utilities.rb
|
77
119
|
- lib/spectra/version.rb
|
78
120
|
- lib/spectra/views/factory.rb
|
79
121
|
- lib/spectra/views/objc_category.mustache
|
data/lib/spectra/spectrum.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'spectra/color'
|
3
|
-
require 'spectra/views/factory'
|
4
|
-
|
5
|
-
module Spectra
|
6
|
-
class Spectrum
|
7
|
-
|
8
|
-
attr_accessor :_prefix
|
9
|
-
attr_accessor :colors, :views
|
10
|
-
|
11
|
-
def generate(definition)
|
12
|
-
# evaluate color definition file, setup defaults
|
13
|
-
self.instance_eval(definition)
|
14
|
-
self.formats(:palette, :objc) unless self.views
|
15
|
-
|
16
|
-
# render views according to the specification
|
17
|
-
self.views.each do |view|
|
18
|
-
view.serialize({ colors: self.colors, prefix: self._prefix })
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
## DSL
|
24
|
-
##
|
25
|
-
|
26
|
-
def prefix(prefix)
|
27
|
-
self._prefix = prefix
|
28
|
-
end
|
29
|
-
|
30
|
-
def formats(*types)
|
31
|
-
types.each { |type| format(type) }
|
32
|
-
end
|
33
|
-
|
34
|
-
def format(type, directory = nil, &renamer)
|
35
|
-
self.views ||= []
|
36
|
-
self.views.concat(Views.from_attributes({ type: type, directory: directory, renamer: renamer }))
|
37
|
-
end
|
38
|
-
|
39
|
-
def color(name, attributes)
|
40
|
-
self.colors ||= []
|
41
|
-
self.colors << Color.new(name, Components.componentize(attributes))
|
42
|
-
end
|
43
|
-
|
44
|
-
def components(*components)
|
45
|
-
components.hash_from(:red, :green, :blue, :alpha)
|
46
|
-
end
|
47
|
-
|
48
|
-
def hex(*components)
|
49
|
-
components.hash_from(:hex, :alpha)
|
50
|
-
end
|
51
|
-
|
52
|
-
def white(*components)
|
53
|
-
components.hash_from(:white, :alpha)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
@@ -1,47 +0,0 @@
|
|
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
|
-
|