Permalink
Browse files

Added in a Raw node that lets you do raw input. Added more tests and …

…started on the README.
  • Loading branch information...
1 parent 77d029e commit 05434323f04b1097b169ba5e3f09d7caf1e26d8b @samwho committed May 1, 2012
View
@@ -0,0 +1,12 @@
+This is a Ruby DSL for creating Vim color schemes. I personally found color
+schemes difficult to get working in both terminal and graphical interfaces, this
+DSL tries to remedy that by, for example, automatically filling in the value of
+guibg by looking at ctermbg.
+
+# Installation
+
+Installation is standard for a Ruby gem:
+
+ gem install vimcolorscheme
+
+
View
@@ -12,6 +12,7 @@
ctermbg :none
end
+ comment "Highlighting for a constant in Ruby."
highlight :rubyConstant do
guifg '#ff0000'
gui :bold
View
@@ -7,5 +7,7 @@ module VimColorScheme
require 'vimcolorscheme/hex2term'
require 'vimcolorscheme/highlight_node'
+require 'vimcolorscheme/comment_node'
+require 'vimcolorscheme/raw_node'
require 'vimcolorscheme/document'
require 'vimcolorscheme/base'
@@ -0,0 +1,15 @@
+module VimColorScheme
+ class CommentNode
+ # Initializes the comment node with a comment string.
+ def initialize comment
+ @comment = comment
+ end
+
+ # Renders the comment node by splitting the string at newlines and then
+ # appending the " comment character at the start of each line and joining
+ # the result with newlines.
+ def to_s
+ @comment.split(/\n/).map { |str| str = '" ' + str }.join("\n") + "\n"
+ end
+ end
+end
@@ -24,6 +24,54 @@ def highlight name, &block
@nodes.last.instance_eval(&block)
end
+ # Creates a comment node in the document. It takes a single argument, which
+ # is the string that will be in the comment. You don't need to include the "
+ # comment character in the string, that will be done for you when the vim
+ # color scheme document is created.
+ #
+ # Example:
+ #
+ # comment "This is a comment!"
+ #
+ # Alternately, you can create a comment by returning a string from a block:
+ #
+ # comment do
+ # "This is a comment!"
+ # end
+ #
+ # Both examples above yield the same result.
+ def comment string = nil
+ if block_given?
+ @nodes << CommentNode.new(yield)
+ else
+ @nodes << CommentNode.new(string)
+ end
+ end
+
+ # Creates a raw node in the current document. Raw nodes are inteded for
+ # users that want to insert code into their vim color scheme that we don't
+ # currently have a native implementation for.
+ #
+ # Example:
+ #
+ # raw "let g:my_var = 'variable!'"
+ #
+ # You can also give raw a block that returns a string:
+ #
+ # raw do
+ # "let g:my_var = 'variable!'"
+ # end
+ #
+ # The two examples above are functionally the same. The strings that are
+ # passed to raw will be printed as-is into the vim color scheme file.
+ def raw string = nil
+ if block_given?
+ @nodes << RawNode.new(yield)
+ else
+ @nodes << RawNode.new(string)
+ end
+ end
+
# Saves this color scheme to a file. If the file exists, the user will be
# prompted as to whether or not they want to overwrite the file.
def save path
@@ -0,0 +1,15 @@
+module VimColorScheme
+ class RawNode
+ # The raw node gets initialized with a string. This string will later just
+ # be printed as-is into the vim file.
+ def initialize raw
+ @raw = raw
+ end
+
+ # Just returns the value that was passed into the constructor of this
+ # object.
+ def to_s
+ @raw + "\n"
+ end
+ end
+end
View
@@ -4,11 +4,22 @@
describe VimColorScheme::Base do
let :test_scheme do
VimColorScheme.new :test_scheme, :dark do
+ comment "This is a comment!"
+ comment do
+ "This is a block comment!"
+ end
+
highlight :Normal do
ctermfg '231'
ctermbg '31'
cterm :bold, :underline
end
+
+ raw "Some raw input."
+
+ raw do
+ "Some raw block input."
+ end
end.to_s
end
@@ -58,4 +69,20 @@
file.read.should == test_scheme_object.to_s
end
end
+
+ it 'should render comments' do
+ test_scheme.should include('" This is a comment!' + "\n")
+ end
+
+ it 'should render block comments' do
+ test_scheme.should include('" This is a block comment!' + "\n")
+ end
+
+ it 'should render raw' do
+ test_scheme.should include("Some raw input.\n")
+ end
+
+ it 'should render raw blocks' do
+ test_scheme.should include("Some raw block input.\n")
+ end
end

0 comments on commit 0543432

Please sign in to comment.