Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First go at the DSL is done. Need to write a few more tests.

  • Loading branch information...
commit 9c401bde7dbce1ed1fe142a8f35dc0cce4433619 1 parent 119f20e
@samwho authored
View
2  lib/vimcolorscheme.rb
@@ -7,3 +7,5 @@ module VimColorScheme
require 'vimcolorscheme/hex2term'
require 'vimcolorscheme/highlight_node'
+require 'vimcolorscheme/document'
+require 'vimcolorscheme/base'
View
11 lib/vimcolorscheme/base.rb
@@ -0,0 +1,11 @@
+module VimColorScheme
+ module Base
+ def new name, lightordark, &block
+ @document = VimColorScheme::Document.new(name, lightordark)
+ @document.instance_eval(&block)
+ @document
+ end
+ end
+
+ extend Base
+end
View
33 lib/vimcolorscheme/document.rb
@@ -1,18 +1,37 @@
module VimColorScheme
class Document
- def initialize options = {}
- @options = options
- @nodes = []
+ def initialize name, lightordark, options = {}
+ @name = name
+ @lightordark = lightordark
+ @options = options
+ @nodes = []
end
- def add_node name = nil
- @nodes << Node.new(name)
- return @nodes.last
+ def highlight name, &block
+ @nodes << HighlightNode.new(name)
+ @nodes.last.instance_eval(&block)
end
def to_s
result = ''
- result += @nodes.to_s
+
+ if @lightordark == :dark
+ result += "set background=dark\n\n"
+ else
+ result += "set background=light\n\n"
+ end
+
+ result += "highlight clear\n\n"
+ result += "if exists('syntax_on')\n"
+ result += " syntax reset\n"
+ result += "endif\n\n"
+ result += "let colors_name = '#{@name.to_s}'\n\n"
+
+ @nodes.each do |node|
+ result += node.to_s
+ end
+
+ return result
end
end
end
View
2  lib/vimcolorscheme/highlight_node.rb
@@ -51,7 +51,7 @@ def to_s
result += "guibg=#{attr_to_s(guibg)} "
result += "cterm=#{attr_to_s(cterm)} "
result += "ctermfg=#{attr_to_s(ctermfg)} "
- result += "ctermbg=#{attr_to_s(ctermbg)} "
+ result += "ctermbg=#{attr_to_s(ctermbg)}\n"
end
# Converts an attribute to string. This accounts for cases such as :none and
View
28 spec/base_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe VimColorScheme::Base do
+ let :test_scheme do
+ VimColorScheme.new :test_scheme, :dark do
+ highlight :Normal do
+ ctermfg '231'
+ ctermbg '31'
+ end
+ end.to_s
+ end
+
+ it "should correct print out the color scheme name" do
+ test_scheme.should include("let colors_name = 'test_scheme'")
+ end
+
+ it "should correctly set the background" do
+ test_scheme.should include("set background=dark")
+ end
+
+ it "should correctly clear highlighting at the start" do
+ test_scheme.should include("highlight clear")
+ end
+
+ it "should check if syntax highlighting is on" do
+ test_scheme.should include("if exists('syntax_on')")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.