palette 0.0.3 → 0.0.4

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/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- palette (0.0.2)
4
+ palette (0.0.3)
5
+ sass (= 3.1.0.alpha.23)
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
@@ -28,6 +29,7 @@ GEM
28
29
  rake
29
30
  rake (0.8.7)
30
31
  rspec (1.3.0)
32
+ sass (3.1.0.alpha.23)
31
33
  term-ansicolor (1.0.5)
32
34
 
33
35
  PLATFORMS
@@ -40,3 +42,4 @@ DEPENDENCIES
40
42
  mocha (= 0.9.8)
41
43
  palette!
42
44
  rspec (= 1.3.0)
45
+ sass (= 3.1.0.alpha.23)
data/features/cli.feature CHANGED
@@ -3,22 +3,80 @@ Feature: Run palette from the command line
3
3
  As a user of palette
4
4
  I should be able to point palette to a file to generate a color schem
5
5
 
6
- Scenario: Process a file with valid palette syntax
7
- When I run "palette features/fixtures/schemes/valid_scheme"
8
- Then the output should contain "colors_name"
6
+ Scenario: Process a complete valid file
7
+ Given a file named "valid_scheme" with:
8
+ """
9
+ vim_colors "valid_scheme" do
10
+ author "Josh Clayton"
11
+ notes "This is a pretty simple example"
12
+ reset true
13
+ background :light
14
+
15
+ black = "000"
16
+ white = "FFF"
17
+ Normal black, white
18
+ Identifier white, black
19
+
20
+ link :rubyDelimiter, :rubyInterpolationDelimiter, :to => :String
21
+ end
22
+ """
23
+ When I run "palette valid_scheme"
24
+ Then the output should contain:
25
+ """
26
+ " Vim color file
27
+ " This file was generated by Palette
28
+ " http://rubygems.org/gems/palette
29
+ "
30
+ " Author: Josh Clayton
31
+ " Notes: This is a pretty simple example
32
+
33
+ let colors_name="valid_scheme"
34
+
35
+ hi clear
36
+ if version > 580
37
+ if exists("syntax_on")
38
+ syntax reset
39
+ endif
40
+ endif
41
+
42
+ if has("gui_running")
43
+ set background=light
44
+ endif
45
+
46
+ hi Normal guifg=#000000 ctermfg=16 guibg=#FFFFFF ctermbg=231
47
+ hi Identifier guifg=#FFFFFF ctermfg=231 guibg=#000000 ctermbg=16
48
+
49
+ hi link rubyDelimiter String
50
+ hi link rubyInterpolationDelimiter String
51
+ """
52
+
53
+ Scenario: Process a file with color math
54
+ Given a file named "valid_scheme" with:
55
+ """
56
+ vim_colors "valid_scheme" do
57
+ Normal darken("FFF", 40), invert("F00")
58
+ Identifier lighten("000", 60), complement("F00")
59
+ end
60
+ """
61
+ When I run "palette valid_scheme"
62
+ Then the output should contain:
63
+ """
64
+ hi Normal guifg=#999999 ctermfg=246 guibg=#00FFFF ctermbg=51
65
+ hi Identifier guifg=#999999 ctermfg=246 guibg=#00FFFF ctermbg=51
66
+ """
9
67
 
10
68
  Scenario: Process a nonexistant file
11
- When I run "palette features/fixtures/schemes/missing_scheme"
69
+ When I run "palette missing_scheme"
12
70
  Then the output should not contain "colors_name"
13
71
  And the exit status should be 0
14
72
 
15
73
  Scenario: Process a file with invalid palette syntax
16
- Given a file named "features/fixtures/schemes/invalid_scheme" with:
74
+ Given a file named "invalid_scheme" with:
17
75
  """
18
76
  vim_colors "bad syntax" do
19
77
  totally made up junk
20
78
  end
21
79
  """
22
- When I run "palette features/fixtures/schemes/invalid_scheme"
80
+ When I run "palette invalid_scheme"
23
81
  Then the exit status should be 1
24
82
  And the output should contain "Please check the syntax of your palette file"
@@ -1,11 +1,3 @@
1
1
  Bundler.require
2
2
 
3
3
  require "aruba"
4
-
5
- Before do
6
- schemes_origin_dir = File.join(%w(features fixtures schemes))
7
- schemes_dir = File.join(dirs.first, schemes_origin_dir)
8
-
9
- FileUtils.mkdir_p(schemes_dir)
10
- FileUtils.cp(Dir.glob(File.join(schemes_origin_dir, "*")), schemes_dir)
11
- end
@@ -1,3 +1,5 @@
1
+ require 'sass'
2
+
1
3
  module Palette
2
4
  class ColorScheme
3
5
  attr_reader :name
@@ -28,6 +30,29 @@ module Palette
28
30
  @rules << Palette::Rule.new(name.to_s, *args)
29
31
  end
30
32
 
33
+ %w(darken lighten saturate desaturate).each do |sass_method|
34
+ class_eval <<-EOM
35
+ def #{sass_method}(hex, number)
36
+ rgb = Palette::Color.hex_to_decimal(Palette::Color.parse(hex))
37
+ sass_context.#{sass_method}(Sass::Script::Color.new(rgb),
38
+ Sass::Script::Number.new(number)).tap{|c| c.options = {}}.inspect.gsub(/#/, "")
39
+ end
40
+ EOM
41
+ end
42
+
43
+ %w(grayscale complement invert).each do |sass_method|
44
+ class_eval <<-EOM
45
+ def #{sass_method}(hex)
46
+ rgb = Palette::Color.hex_to_decimal(Palette::Color.parse(hex))
47
+ sass_context.#{sass_method}(Sass::Script::Color.new(rgb)).tap{|c| c.options = {}}.inspect.gsub(/#/, "")
48
+ end
49
+ EOM
50
+ end
51
+
52
+ def sass_context
53
+ @context ||= Sass::Script::Functions::EvaluationContext.new({})
54
+ end
55
+
31
56
  def String(*args)
32
57
  @rules ||= []
33
58
  @rules << Palette::Rule.new("String", *args)
@@ -36,10 +61,15 @@ module Palette
36
61
  def to_s
37
62
  output = []
38
63
  output << header
64
+ output << ""
39
65
  output << color_scheme_name
66
+ output << ""
40
67
  output << generate_reset
68
+ output << ""
41
69
  output << generate_background
70
+ output << ""
42
71
  output << @rules
72
+ output << ""
43
73
  output << @links
44
74
  output.compact.join("\n")
45
75
  end
@@ -60,7 +90,7 @@ module Palette
60
90
  " http://rubygems.org/gems/palette
61
91
  "
62
92
  " Author: #{@author_name}
63
- #{%{" #{@notes}} if @notes}
93
+ #{%{" Notes: #{@notes}} if @notes}
64
94
  }.strip
65
95
  end
66
96
 
data/lib/palette/rule.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  module Palette
2
2
  class Rule
3
+ @@max_length = 0
3
4
  attr_reader :name, :fg, :bg, :gui
4
5
 
5
6
  def initialize(name, *args)
6
7
  options = args.last.is_a?(Hash) ? args.pop : {}
7
8
 
8
9
  @name = name.to_s
10
+
11
+ @@max_length = @name.length if @name.length > @@max_length
12
+
9
13
  @fg = options[:fg] || args.first
10
14
  @bg = options[:bg] || (args.length > 1 ? args.last : nil)
11
15
  @gui = options[:gui]
@@ -13,18 +17,18 @@ module Palette
13
17
 
14
18
  def to_s
15
19
  return "" if fg.nil? && bg.nil? && gui.nil?
16
- output = ["hi", name]
20
+ output = ["hi #{sprintf("%-#{@@max_length}s", name)}"]
17
21
 
18
22
  if fg
19
23
  color = Palette::Color.new(fg)
20
24
  output << %{guifg=##{color.to_hex}}
21
- output << %{ctermfg=#{color.to_cterm}}
25
+ output << %{ctermfg=#{sprintf("%-3s", color.to_cterm)}}
22
26
  end
23
27
 
24
28
  if bg
25
29
  color = Palette::Color.new(bg)
26
30
  output << %{guibg=##{color.to_hex}}
27
- output << %{ctermbg=#{color.to_cterm}}
31
+ output << %{ctermbg=#{sprintf("%-3s", color.to_cterm)}}
28
32
  end
29
33
 
30
34
  if gui
@@ -34,7 +38,7 @@ module Palette
34
38
  end
35
39
  end
36
40
 
37
- output.join(" ")
41
+ output.join(" ").strip
38
42
  end
39
43
  end
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module Palette
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -166,7 +166,7 @@ describe Palette::ColorScheme, "output order" do
166
166
  end
167
167
 
168
168
  it "generates the color file in the correct order" do
169
- subject.to_s.should == [header, color_scheme_name, reset, background].join("\n")
169
+ subject.to_s.should =~ /#{header}.*#{color_scheme_name}.*#{reset}.*#{background}/m
170
170
  end
171
171
  end
172
172
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palette
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Clayton
@@ -15,13 +15,31 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-02 00:00:00 -04:00
18
+ date: 2010-11-04 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rspec
22
+ name: sass
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: -3702664446
30
+ segments:
31
+ - 3
32
+ - 1
33
+ - 0
34
+ - alpha
35
+ - 23
36
+ version: 3.1.0.alpha.23
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: rspec
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
25
43
  none: false
26
44
  requirements:
27
45
  - - "="
@@ -33,11 +51,11 @@ dependencies:
33
51
  - 0
34
52
  version: 1.3.0
35
53
  type: :development
36
- version_requirements: *id001
54
+ version_requirements: *id002
37
55
  - !ruby/object:Gem::Dependency
38
56
  name: mocha
39
57
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
58
+ requirement: &id003 !ruby/object:Gem::Requirement
41
59
  none: false
42
60
  requirements:
43
61
  - - "="
@@ -49,11 +67,11 @@ dependencies:
49
67
  - 8
50
68
  version: 0.9.8
51
69
  type: :development
52
- version_requirements: *id002
70
+ version_requirements: *id003
53
71
  - !ruby/object:Gem::Dependency
54
72
  name: bourne
55
73
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
74
+ requirement: &id004 !ruby/object:Gem::Requirement
57
75
  none: false
58
76
  requirements:
59
77
  - - "="
@@ -64,11 +82,11 @@ dependencies:
64
82
  - 0
65
83
  version: "1.0"
66
84
  type: :development
67
- version_requirements: *id003
85
+ version_requirements: *id004
68
86
  - !ruby/object:Gem::Dependency
69
87
  name: cucumber
70
88
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
89
+ requirement: &id005 !ruby/object:Gem::Requirement
72
90
  none: false
73
91
  requirements:
74
92
  - - "="
@@ -80,11 +98,11 @@ dependencies:
80
98
  - 3
81
99
  version: 0.9.3
82
100
  type: :development
83
- version_requirements: *id004
101
+ version_requirements: *id005
84
102
  - !ruby/object:Gem::Dependency
85
103
  name: aruba
86
104
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
105
+ requirement: &id006 !ruby/object:Gem::Requirement
88
106
  none: false
89
107
  requirements:
90
108
  - - "="
@@ -96,7 +114,7 @@ dependencies:
96
114
  - 4
97
115
  version: 0.2.4
98
116
  type: :development
99
- version_requirements: *id005
117
+ version_requirements: *id006
100
118
  description: Palette provides an easy way to build Vim color schemes
101
119
  email:
102
120
  - joshua.clayton@gmail.com
@@ -122,7 +140,6 @@ files:
122
140
  - lib/palette/rule.rb
123
141
  - lib/palette/version.rb
124
142
  - features/cli.feature
125
- - features/fixtures/schemes/valid_scheme
126
143
  - features/support/env.rb
127
144
  - spec/color_scheme_spec.rb
128
145
  - spec/color_spec.rb
@@ -166,7 +183,6 @@ specification_version: 3
166
183
  summary: Build Vim colorschemes with ease
167
184
  test_files:
168
185
  - features/cli.feature
169
- - features/fixtures/schemes/valid_scheme
170
186
  - features/support/env.rb
171
187
  - spec/color_scheme_spec.rb
172
188
  - spec/color_spec.rb
@@ -1,12 +0,0 @@
1
- vim_colors "sweet" do
2
- author "Josh Clayton"
3
- notes "My really sweet theme"
4
-
5
- reset true
6
- background :light
7
-
8
- Normal "222", "f8f8ff"
9
-
10
- Folded "808080", "ECECEC", :gui => "bold"
11
- link :vimFold, :FoldColumn, :to => :Folded
12
- end