Permalink
Browse files

Cucumber and Aruba rock

  • Loading branch information...
1 parent 582ed6b commit d5dfc88d6703f30adad74c572767df3c32c66c68 @joshuaclayton committed Nov 3, 2010
Showing with 63 additions and 7 deletions.
  1. +1 −1 Gemfile.lock
  2. +47 −0 features/cli.feature
  3. +6 −1 lib/palette/color_scheme.rb
  4. +8 −4 lib/palette/rule.rb
  5. +1 −1 spec/color_scheme_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- palette (0.0.2)
+ palette (0.0.3)
GEM
remote: http://rubygems.org/
View
@@ -22,3 +22,50 @@ Feature: Run palette from the command line
When I run "palette features/fixtures/schemes/invalid_scheme"
Then the exit status should be 1
And the output should contain "Please check the syntax of your palette file"
+
+ Scenario: Process a complete valid file
+ Given a file named "great_scheme" with:
+ """
+ vim_colors "great_scheme" do
+ author "Josh Clayton"
+ notes "This is a pretty simple example"
+ reset true
+ background :light
+
+ black = "000"
+ white = "FFF"
+ Normal black, white
+ Identifier white, black
+
+ link :rubyDelimiter, :rubyInterpolationDelimiter, :to => :String
+ end
+ """
+ When I run "palette great_scheme"
+ Then the output should contain:
+ """
+ " Vim color file
+ " This file was generated by Palette
+ " http://rubygems.org/gems/palette
+ "
+ " Author: Josh Clayton
+ " Notes: This is a pretty simple example
+
+ let colors_name="great_scheme"
+
+ hi clear
+ if version > 580
+ if exists("syntax_on")
+ syntax reset
+ endif
+ endif
+
+ if has("gui_running")
+ set background=light
+ endif
+
+ hi Normal guifg=#000000 ctermfg=16 guibg=#FFFFFF ctermbg=231
+ hi Identifier guifg=#FFFFFF ctermfg=231 guibg=#000000 ctermbg=16
+
+ hi link rubyDelimiter String
+ hi link rubyInterpolationDelimiter String
+ """
@@ -36,10 +36,15 @@ def String(*args)
def to_s
output = []
output << header
+ output << ""
output << color_scheme_name
+ output << ""
output << generate_reset
+ output << ""
output << generate_background
+ output << ""
output << @rules
+ output << ""
output << @links
output.compact.join("\n")
end
@@ -60,7 +65,7 @@ def header
" http://rubygems.org/gems/palette
"
" Author: #{@author_name}
-#{%{" #{@notes}} if @notes}
+#{%{" Notes: #{@notes}} if @notes}
}.strip
end
View
@@ -1,30 +1,34 @@
module Palette
class Rule
+ @@max_length = 0
attr_reader :name, :fg, :bg, :gui
def initialize(name, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
@name = name.to_s
+
+ @@max_length = @name.length if @name.length > @@max_length
+
@fg = options[:fg] || args.first
@bg = options[:bg] || (args.length > 1 ? args.last : nil)
@gui = options[:gui]
end
def to_s
return "" if fg.nil? && bg.nil? && gui.nil?
- output = ["hi", name]
+ output = ["hi #{sprintf("%-#{@@max_length}s", name)}"]
if fg
color = Palette::Color.new(fg)
output << %{guifg=##{color.to_hex}}
- output << %{ctermfg=#{color.to_cterm}}
+ output << %{ctermfg=#{sprintf("%-3s", color.to_cterm)}}
end
if bg
color = Palette::Color.new(bg)
output << %{guibg=##{color.to_hex}}
- output << %{ctermbg=#{color.to_cterm}}
+ output << %{ctermbg=#{sprintf("%-3s", color.to_cterm)}}
end
if gui
@@ -34,7 +38,7 @@ def to_s
end
end
- output.join(" ")
+ output.join(" ").strip
end
end
end
@@ -166,7 +166,7 @@
end
it "generates the color file in the correct order" do
- subject.to_s.should == [header, color_scheme_name, reset, background].join("\n")
+ subject.to_s.should =~ /#{header}.*#{color_scheme_name}.*#{reset}.*#{background}/m
end
end

0 comments on commit d5dfc88

Please sign in to comment.