palette 0.0.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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/README.markdown +59 -0
- data/Rakefile +2 -0
- data/lib/palette.rb +9 -0
- data/lib/palette/color.rb +74 -0
- data/lib/palette/color_scheme.rb +98 -0
- data/lib/palette/dsl.rb +11 -0
- data/lib/palette/link.rb +16 -0
- data/lib/palette/rule.rb +40 -0
- data/lib/palette/version.rb +3 -0
- data/palette.gemspec +24 -0
- data/spec/color_scheme_spec.rb +191 -0
- data/spec/color_spec.rb +33 -0
- data/spec/dsl_spec.rb +19 -0
- data/spec/link_spec.rb +12 -0
- data/spec/rule_spec.rb +84 -0
- data/spec/spec_helper.rb +10 -0
- metadata +122 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
palette (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
mocha (0.9.9)
|
10
|
+
rake
|
11
|
+
rake (0.8.7)
|
12
|
+
rspec (1.3.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
mocha (= 0.9.9)
|
19
|
+
palette!
|
20
|
+
rspec (= 1.3.0)
|
data/README.markdown
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Palette
|
2
|
+
|
3
|
+
## An easier way to write Vim color schemes
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
Install with Rubygems:
|
8
|
+
|
9
|
+
gem install palette
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
puts Palette::Dsl.run lambda {
|
14
|
+
vim_colors "great" do
|
15
|
+
# rules etc go here
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
19
|
+
## Syntax
|
20
|
+
|
21
|
+
vim_colors "sweet" do
|
22
|
+
author "Josh Clayton"
|
23
|
+
notes "My really sweet theme"
|
24
|
+
|
25
|
+
reset true
|
26
|
+
background :light
|
27
|
+
|
28
|
+
Normal "222", "f8f8ff"
|
29
|
+
|
30
|
+
Folded "808080", "ECECEC", :gui => "bold"
|
31
|
+
link :vimFold, :FoldColumn, :to => :Folded
|
32
|
+
end
|
33
|
+
|
34
|
+
This color scheme would generate the following output:
|
35
|
+
|
36
|
+
" Vim color file
|
37
|
+
" This file was generated by Palette
|
38
|
+
" http://rubygems.org/gems/palette
|
39
|
+
"
|
40
|
+
" Author: Josh Clayton
|
41
|
+
" My really sweet theme
|
42
|
+
let colors_name="sweet"
|
43
|
+
hi clear
|
44
|
+
if version > 580
|
45
|
+
if exists("syntax_on")
|
46
|
+
syntax reset
|
47
|
+
endif
|
48
|
+
endif
|
49
|
+
if has("gui_running")
|
50
|
+
set background=light
|
51
|
+
endif
|
52
|
+
hi Normal guifg=#222222 ctermfg=235 guibg=#F8F8FF ctermbg=231
|
53
|
+
hi Folded guifg=#808080 ctermfg=244 guibg=#ECECEC ctermbg=255 gui=bold cterm=bold
|
54
|
+
hi link vimFold Folded
|
55
|
+
hi link FoldColumn Folded
|
56
|
+
|
57
|
+
## Author
|
58
|
+
|
59
|
+
Written by Josh Clayton.
|
data/Rakefile
ADDED
data/lib/palette.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Palette
|
2
|
+
class Color
|
3
|
+
BASE_SET = [0, 95, 135, 175, 215, 255]
|
4
|
+
GRAY_SET = [ 8, 18, 28, 38, 48, 58, 68, 78, 88, 98, 108, 118,
|
5
|
+
128, 138, 148, 158, 168, 178, 188, 198, 208, 218, 228, 238]
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@hex = self.class.parse(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hex
|
12
|
+
@hex
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_cterm
|
16
|
+
self.class.color_map.index(closest_cterm_hex)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.parse(hex)
|
22
|
+
if hex.upcase =~ /^[A-F\d]{3}$/
|
23
|
+
hex.split(//).map {|code| code * 2 }.join
|
24
|
+
elsif hex.upcase =~ /^[A-F\d]{6}$/
|
25
|
+
hex
|
26
|
+
else
|
27
|
+
raise "invalid hex value: #{hex}"
|
28
|
+
end.upcase
|
29
|
+
end
|
30
|
+
|
31
|
+
def closest_cterm_hex
|
32
|
+
all_colors = self.class.color_map.values.map do |hexcode|
|
33
|
+
original_r, original_g, original_b = self.class.hex_to_decimal(@hex)
|
34
|
+
r, g, b = self.class.hex_to_decimal(hexcode)
|
35
|
+
distance = (original_r - r).abs + (original_g - g).abs + (original_b - b).abs
|
36
|
+
[hexcode, distance]
|
37
|
+
end
|
38
|
+
Hash[*all_colors.flatten].min {|a, b| a[1] <=> b[1] }[0]
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.color_map
|
42
|
+
@colors = {}
|
43
|
+
counter = 16
|
44
|
+
(0...6).each do |red|
|
45
|
+
(0...6).each do |green|
|
46
|
+
(0...6).each do |blue|
|
47
|
+
@colors[counter] = [
|
48
|
+
decimal_to_hex(BASE_SET[red]),
|
49
|
+
decimal_to_hex(BASE_SET[green]),
|
50
|
+
decimal_to_hex(BASE_SET[blue])
|
51
|
+
].join
|
52
|
+
counter += 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
GRAY_SET.each do |scale|
|
58
|
+
@colors[counter] = decimal_to_hex(scale) * 3
|
59
|
+
counter += 1
|
60
|
+
end
|
61
|
+
@colors
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.decimal_to_hex(decimal)
|
65
|
+
base = ("%x" % decimal).strip
|
66
|
+
base = "0#{base}" if base.length == 1
|
67
|
+
base
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.hex_to_decimal(hex)
|
71
|
+
hex.scan(/../).map {|x| ("%2d" % "0x#{x}").to_i }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Palette
|
2
|
+
class ColorScheme
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(color_name)
|
6
|
+
@name = color_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def author(author_name)
|
10
|
+
@author_name = author_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def notes(notes)
|
14
|
+
@notes = notes
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset(reset)
|
18
|
+
@reset = !!reset
|
19
|
+
end
|
20
|
+
|
21
|
+
def background(shade)
|
22
|
+
return unless %w(light dark).include?(shade.to_s)
|
23
|
+
@background = shade.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args)
|
27
|
+
@rules ||= []
|
28
|
+
@rules << Palette::Rule.new(name.to_s, *args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def String(*args)
|
32
|
+
@rules ||= []
|
33
|
+
@rules << Palette::Rule.new("String", *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
output = []
|
38
|
+
output << header
|
39
|
+
output << color_scheme_name
|
40
|
+
output << generate_reset
|
41
|
+
output << generate_background
|
42
|
+
output << @rules
|
43
|
+
output << @links
|
44
|
+
output.compact.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def link(*args)
|
48
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
49
|
+
|
50
|
+
@links ||= []
|
51
|
+
args.each do |arg|
|
52
|
+
@links << Link.new(arg, options[:to])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def header
|
57
|
+
%{
|
58
|
+
" Vim color file
|
59
|
+
" This file was generated by Palette
|
60
|
+
" http://rubygems.org/gems/palette
|
61
|
+
"
|
62
|
+
" Author: #{@author_name}
|
63
|
+
#{%{" #{@notes}} if @notes}
|
64
|
+
}.strip
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_reset
|
68
|
+
return unless @reset
|
69
|
+
%{
|
70
|
+
hi clear
|
71
|
+
if version > 580
|
72
|
+
if exists("syntax_on")
|
73
|
+
syntax reset
|
74
|
+
endif
|
75
|
+
endif
|
76
|
+
}.strip
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_background
|
80
|
+
return unless @background
|
81
|
+
%{
|
82
|
+
if has("gui_running")
|
83
|
+
set background=#{@background}
|
84
|
+
endif
|
85
|
+
}.strip
|
86
|
+
end
|
87
|
+
|
88
|
+
def color_scheme_name
|
89
|
+
%{let colors_name="#{@name}"}
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.run(name, block)
|
93
|
+
instance = new(name)
|
94
|
+
instance.instance_eval(&block)
|
95
|
+
instance.to_s
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/palette/dsl.rb
ADDED
data/lib/palette/link.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Palette
|
2
|
+
class Link
|
3
|
+
@@max_length = 0
|
4
|
+
attr_reader :from, :to
|
5
|
+
|
6
|
+
def initialize(from, to)
|
7
|
+
@from = from.to_s
|
8
|
+
@to = to.to_s
|
9
|
+
@@max_length = @from.length if @from.length > @@max_length
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
%{hi link #{sprintf("%-#{@@max_length}s", self.from)} #{self.to}}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/palette/rule.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Palette
|
2
|
+
class Rule
|
3
|
+
attr_reader :name, :fg, :bg, :gui
|
4
|
+
|
5
|
+
def initialize(name, *args)
|
6
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
|
8
|
+
@name = name.to_s
|
9
|
+
@fg = options[:fg] || args.first
|
10
|
+
@bg = options[:bg] || (args.length > 1 ? args.last : nil)
|
11
|
+
@gui = options[:gui]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
return "" if fg.nil? && bg.nil? && gui.nil?
|
16
|
+
output = ["hi", name]
|
17
|
+
|
18
|
+
if fg
|
19
|
+
color = Palette::Color.new(fg)
|
20
|
+
output << %{guifg=##{color.to_hex}}
|
21
|
+
output << %{ctermfg=#{color.to_cterm}}
|
22
|
+
end
|
23
|
+
|
24
|
+
if bg
|
25
|
+
color = Palette::Color.new(bg)
|
26
|
+
output << %{guibg=##{color.to_hex}}
|
27
|
+
output << %{ctermbg=#{color.to_cterm}}
|
28
|
+
end
|
29
|
+
|
30
|
+
if gui
|
31
|
+
output << %{gui=#{gui}}
|
32
|
+
if gui !~ /italic/
|
33
|
+
output << %{cterm=#{gui}}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
output.join(" ")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/palette.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "palette/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "palette"
|
7
|
+
s.version = Palette::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Josh Clayton"]
|
10
|
+
s.email = ["joshua.clayton@gmail.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/palette"
|
12
|
+
s.summary = %q{Build Vim colorschemes with ease}
|
13
|
+
s.description = %q{Palette provides an easy way to build Vim color schemes}
|
14
|
+
|
15
|
+
all_files = %x{git ls-files}.split("\n")
|
16
|
+
|
17
|
+
s.files = all_files.reject {|file| file =~ /^(spec|features|cucumber)/ }
|
18
|
+
s.test_files = all_files.select {|file| file =~ /^(spec|features|cucumber)/ }
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec", "1.3.0"
|
23
|
+
s.add_development_dependency "mocha", "0.9.9"
|
24
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Palette::ColorScheme do
|
4
|
+
let(:color_name) { "great" }
|
5
|
+
subject { Palette::ColorScheme.new(color_name) }
|
6
|
+
|
7
|
+
it "accepts a name as a constructor argument" do
|
8
|
+
subject.name.should == color_name
|
9
|
+
subject.to_s.should include(%{let colors_name="#{color_name}"})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Palette::ColorScheme, "notes" do
|
14
|
+
subject { Palette::ColorScheme.new("abc") }
|
15
|
+
|
16
|
+
it "allows assignment of author" do
|
17
|
+
subject.notes "Based on something great"
|
18
|
+
subject.to_s.should =~ /".*Based on something great/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Palette::ColorScheme, "author" do
|
23
|
+
subject { Palette::ColorScheme.new("abc") }
|
24
|
+
|
25
|
+
it "allows assignment of author" do
|
26
|
+
subject.author "John Doe"
|
27
|
+
subject.to_s.should include(%{" Author: John Doe})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Palette::ColorScheme, "reset" do
|
32
|
+
subject { Palette::ColorScheme.new("abc") }
|
33
|
+
|
34
|
+
let(:header) do
|
35
|
+
%{
|
36
|
+
hi clear
|
37
|
+
if version > 580
|
38
|
+
if exists("syntax_on")
|
39
|
+
syntax reset
|
40
|
+
endif
|
41
|
+
endif
|
42
|
+
}.strip
|
43
|
+
end
|
44
|
+
|
45
|
+
it "generates a reset when set" do
|
46
|
+
subject.reset(true)
|
47
|
+
subject.to_s.should include(header)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "doesn't include a reset by default" do
|
51
|
+
subject.to_s.should_not include(header)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe Palette::ColorScheme, "background" do
|
56
|
+
subject { Palette::ColorScheme.new("abc") }
|
57
|
+
|
58
|
+
it "generates a light background when set" do
|
59
|
+
background = %{
|
60
|
+
if has("gui_running")
|
61
|
+
set background=light
|
62
|
+
endif
|
63
|
+
}.strip
|
64
|
+
subject.background(:light)
|
65
|
+
subject.to_s.should include(background)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "generates a dark background when set" do
|
69
|
+
background = %{
|
70
|
+
if has("gui_running")
|
71
|
+
set background=dark
|
72
|
+
endif
|
73
|
+
}.strip
|
74
|
+
subject.background(:dark)
|
75
|
+
subject.to_s.should include(background)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "doesn't create a background by default" do
|
79
|
+
subject.to_s.should_not include("set background")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "doesn't create a background if bad data is passed" do
|
83
|
+
subject.background("lame")
|
84
|
+
subject.to_s.should_not include("set background")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Palette::ColorScheme, "rule generation" do
|
89
|
+
before { Palette::Rule.stubs(:new => "Custom rule") }
|
90
|
+
|
91
|
+
it "creates simple rules" do
|
92
|
+
Palette::ColorScheme.run "one", lambda {
|
93
|
+
Comment "ABCDEF", :gui => "bold"
|
94
|
+
}
|
95
|
+
Palette::Rule.should have_received(:new).with("Comment", "ABCDEF", :gui => "bold")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "creates multiple rules" do
|
99
|
+
Palette::ColorScheme.run "one", lambda {
|
100
|
+
Comment "ABCDEF", :gui => "bold"
|
101
|
+
Regexp :gui => "bold"
|
102
|
+
}
|
103
|
+
Palette::Rule.should have_received(:new).with("Comment", "ABCDEF", :gui => "bold")
|
104
|
+
Palette::Rule.should have_received(:new).with("Regexp", :gui => "bold")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "handles Ruby naming conflicts" do
|
108
|
+
Palette::ColorScheme.run "one", lambda {
|
109
|
+
String "ABCDEF"
|
110
|
+
}
|
111
|
+
Palette::Rule.should have_received(:new).with("String", "ABCDEF")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "outputs rules" do
|
115
|
+
output = Palette::ColorScheme.run "one", lambda {
|
116
|
+
Comment "ABCDEF", :gui => "bold"
|
117
|
+
String "ABCDEF"
|
118
|
+
}
|
119
|
+
|
120
|
+
output.should include(%{Custom rule\nCustom rule})
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe Palette::ColorScheme, "linking" do
|
125
|
+
before { Palette::Link.stubs(:new => "Custom link") }
|
126
|
+
|
127
|
+
it "handles simple linking" do
|
128
|
+
Palette::ColorScheme.run "one", lambda {
|
129
|
+
link :Something, :to => :Another
|
130
|
+
}
|
131
|
+
Palette::Link.should have_received(:new).with(:Something, :Another)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "handles complex linking" do
|
135
|
+
Palette::ColorScheme.run "one", lambda {
|
136
|
+
link :Something, :Else, :to => :Another
|
137
|
+
link :Red, :to => :Black
|
138
|
+
}
|
139
|
+
Palette::Link.should have_received(:new).with(:Something, :Another)
|
140
|
+
Palette::Link.should have_received(:new).with(:Else, :Another)
|
141
|
+
Palette::Link.should have_received(:new).with(:Red, :Black)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "outputs links" do
|
145
|
+
output = Palette::ColorScheme.run "one", lambda {
|
146
|
+
link :Something, :Else, :to => :Another
|
147
|
+
link :Red, :to => :Black
|
148
|
+
}
|
149
|
+
|
150
|
+
output.should include(%{Custom link\nCustom link\nCustom link})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe Palette::ColorScheme, "output order" do
|
155
|
+
subject { Palette::ColorScheme.new("abc") }
|
156
|
+
let(:header) { "header" }
|
157
|
+
let(:color_scheme_name) { "color scheme name" }
|
158
|
+
let(:reset) { "reset" }
|
159
|
+
let(:background) { "background" }
|
160
|
+
|
161
|
+
before do
|
162
|
+
subject.stubs(:header => header,
|
163
|
+
:color_scheme_name => color_scheme_name,
|
164
|
+
:generate_reset => reset,
|
165
|
+
:generate_background => background)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "generates the color file in the correct order" do
|
169
|
+
subject.to_s.should == [header, color_scheme_name, reset, background].join("\n")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe Palette::ColorScheme, ".run" do
|
174
|
+
let(:color_scheme) do
|
175
|
+
mock("color-scheme").tap do |scheme|
|
176
|
+
scheme.stubs(:great => "things")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
before do
|
181
|
+
Palette::ColorScheme.stubs(:new => color_scheme)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "creates a new color scheme with the correct name" do
|
185
|
+
Palette::ColorScheme.run "Great", lambda {
|
186
|
+
great
|
187
|
+
}
|
188
|
+
Palette::ColorScheme.should have_received(:new).with("Great")
|
189
|
+
color_scheme.should have_received(:great)
|
190
|
+
end
|
191
|
+
end
|
data/spec/color_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Palette::Color, "color conversion" do
|
4
|
+
it "generates hex from three hex digits" do
|
5
|
+
Palette::Color.new("AAA").to_hex.should == "AAAAAA"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "generates hex from six hex digits" do
|
9
|
+
Palette::Color.new("FAFAFA").to_hex.should == "FAFAFA"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "generates cterm colors from three hex digits" do
|
13
|
+
Palette::Color.new("000").to_cterm.should == 16
|
14
|
+
end
|
15
|
+
|
16
|
+
it "generates cterm colors from six hex digits" do
|
17
|
+
Palette::Color.new("eeeeee").to_cterm.should == 255
|
18
|
+
end
|
19
|
+
|
20
|
+
it "generates the closest cterm colors to a hex value" do
|
21
|
+
Palette::Color.new("eeeeef").to_cterm.should == 255
|
22
|
+
Palette::Color.new("d7005f").to_cterm.should == 161
|
23
|
+
Palette::Color.new("fffffa").to_cterm.should == 231
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an error if a bad color is passed" do
|
27
|
+
expect { Palette::Color.new("abcdfg") }.to raise_error
|
28
|
+
expect { Palette::Color.new("abcdf") }.to raise_error
|
29
|
+
expect { Palette::Color.new("00ff") }.to raise_error
|
30
|
+
expect { Palette::Color.new("0f") }.to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/dsl_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Palette::Dsl do
|
4
|
+
let(:color_name) { "great" }
|
5
|
+
|
6
|
+
it "creates a new scheme" do
|
7
|
+
Palette::ColorScheme.stubs(:run)
|
8
|
+
Palette::Dsl.new.vim_colors(color_name) {}
|
9
|
+
Palette::ColorScheme.should have_received(:run)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "runs schemes" do
|
13
|
+
Palette::ColorScheme.stubs(:run)
|
14
|
+
Palette::Dsl.run lambda {
|
15
|
+
vim_colors("awesome") {}
|
16
|
+
}
|
17
|
+
Palette::ColorScheme.should have_received(:run)
|
18
|
+
end
|
19
|
+
end
|
data/spec/link_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Palette::Link do
|
4
|
+
it "creates a link from one rule to another" do
|
5
|
+
Palette::Link.new("one", "two").to_s.should == %{hi link one two}
|
6
|
+
end
|
7
|
+
|
8
|
+
it "uses the longest 'from' as a base length" do
|
9
|
+
Palette::Link.new("three", "four")
|
10
|
+
Palette::Link.new("one", "two").to_s.should == %{hi link one two}
|
11
|
+
end
|
12
|
+
end
|
data/spec/rule_spec.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples_for "rule with colors" do
|
4
|
+
let(:fg) { "DEF" }
|
5
|
+
let(:bg) { "ABC" }
|
6
|
+
let(:hex) { "ABCDEF" }
|
7
|
+
let(:cterm) { 123 }
|
8
|
+
let(:color) do
|
9
|
+
mock("color").tap do |color|
|
10
|
+
color.stubs(:to_hex => hex, :to_cterm => cterm)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before { Palette::Color.stubs(:new => color) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Palette::Rule, "with a foreground" do
|
18
|
+
it_should_behave_like "rule with colors"
|
19
|
+
subject { Palette::Rule.new("Awesome", fg) }
|
20
|
+
|
21
|
+
it "highlights the correct colors" do
|
22
|
+
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm}"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "converts the correct colors" do
|
26
|
+
subject.to_s
|
27
|
+
Palette::Color.should have_received(:new).with(fg)
|
28
|
+
Palette::Color.should_not have_received(:new).with(bg)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Palette::Rule, "with a foreground and background" do
|
33
|
+
it_should_behave_like "rule with colors"
|
34
|
+
subject { Palette::Rule.new("Awesome", fg, bg) }
|
35
|
+
|
36
|
+
it "highlights the correct colors" do
|
37
|
+
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm} guibg=##{hex} ctermbg=#{cterm}"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "converts the correct colors" do
|
41
|
+
subject.to_s
|
42
|
+
Palette::Color.should have_received(:new).with(fg)
|
43
|
+
Palette::Color.should have_received(:new).with(bg)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Palette::Rule, "with a hash passed" do
|
48
|
+
it_should_behave_like "rule with colors"
|
49
|
+
subject { Palette::Rule.new("Awesome", :fg => fg, :bg => bg) }
|
50
|
+
|
51
|
+
it "highlights the correct colors" do
|
52
|
+
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm} guibg=##{hex} ctermbg=#{cterm}"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "converts the correct colors" do
|
56
|
+
subject.to_s
|
57
|
+
Palette::Color.should have_received(:new).with(fg)
|
58
|
+
Palette::Color.should have_received(:new).with(bg)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Palette::Rule, "with a gui" do
|
63
|
+
subject { Palette::Rule.new("Awesome", :gui => "bold") }
|
64
|
+
|
65
|
+
it "sets the gui correctly" do
|
66
|
+
subject.to_s.should == "hi Awesome gui=bold cterm=bold"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe Palette::Rule, "with a gui as italic" do
|
71
|
+
subject { Palette::Rule.new("Awesome", :gui => "italic") }
|
72
|
+
|
73
|
+
it "sets the gui correctly" do
|
74
|
+
subject.to_s.should == "hi Awesome gui=italic"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe Palette::Rule, "without colors" do
|
79
|
+
subject { Palette::Rule.new("Awesome") }
|
80
|
+
|
81
|
+
it "is empty" do
|
82
|
+
subject.to_s.should == ""
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: palette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Clayton
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-28 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 1.3.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 41
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 9
|
50
|
+
version: 0.9.9
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Palette provides an easy way to build Vim color schemes
|
54
|
+
email:
|
55
|
+
- joshua.clayton@gmail.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.markdown
|
67
|
+
- Rakefile
|
68
|
+
- lib/palette.rb
|
69
|
+
- lib/palette/color.rb
|
70
|
+
- lib/palette/color_scheme.rb
|
71
|
+
- lib/palette/dsl.rb
|
72
|
+
- lib/palette/link.rb
|
73
|
+
- lib/palette/rule.rb
|
74
|
+
- lib/palette/version.rb
|
75
|
+
- palette.gemspec
|
76
|
+
- spec/color_scheme_spec.rb
|
77
|
+
- spec/color_spec.rb
|
78
|
+
- spec/dsl_spec.rb
|
79
|
+
- spec/link_spec.rb
|
80
|
+
- spec/rule_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://rubygems.org/gems/palette
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Build Vim colorschemes with ease
|
116
|
+
test_files:
|
117
|
+
- spec/color_scheme_spec.rb
|
118
|
+
- spec/color_spec.rb
|
119
|
+
- spec/dsl_spec.rb
|
120
|
+
- spec/link_spec.rb
|
121
|
+
- spec/rule_spec.rb
|
122
|
+
- spec/spec_helper.rb
|