vic 0.0.5 → 0.0.6

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/lib/vic/color.rb CHANGED
@@ -79,8 +79,9 @@ module Vic
79
79
  #
80
80
  # @param [String] subject the string in question
81
81
  # @return [Match
82
- def hex_color?(subject)
83
- subject.match(/#[\da-f]{6}/) ? true : false
82
+ def is_hexadecimal?(subject)
83
+ return false unless subject.respond_to? :match
84
+ subject.match(/#?[\da-f]{6}/i) ? true : false
84
85
  end
85
86
  end
86
87
  end
@@ -1,7 +1,7 @@
1
1
  module Vic
2
2
  class ColorError < StandardError
3
- def initialize
4
- super('invalid color')
3
+ def initialize(message)
4
+ super(message)
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,5 @@
1
1
  module Vic
2
2
  class Colorscheme::Highlight
3
- include Vic::Color
4
3
 
5
4
  attr_accessor :group
6
5
 
@@ -11,7 +10,8 @@ module Vic
11
10
  # @param [Hash] args the arguments to set
12
11
  # @return [Vic::Colorscheme::Highlight] the new highlight
13
12
  def initialize(group, args={})
14
- @group = group
13
+ # Convert to group name to symbol to ensure consistency
14
+ @group = group.to_sym
15
15
  update_arguments!(args)
16
16
  end
17
17
 
@@ -34,9 +34,6 @@ module Vic
34
34
  arg = Argument.new(m, val)
35
35
  argument_set.add arg
36
36
  end
37
-
38
- # Return self for chaining
39
- self
40
37
  end
41
38
  end
42
39
  end
@@ -45,22 +42,32 @@ module Vic
45
42
  # the 256 color code for ctermfg.
46
43
  #
47
44
  # @param [String] hex a hexidecimal color
48
- def fg=(hex)
49
- self.guifg = hex
50
- self.ctermfg = Color.hex_to_256(hex)
45
+ def fg=(color)
46
+ if color == 'NONE'
47
+ self.ctermfg = color
48
+ elsif Color.is_hexadecimal?(color)
49
+ self.ctermfg = Color.hex_to_256(color)
50
+ else
51
+ raise ColorError.new "invalid hexadecimal color #{color}"
52
+ end
51
53
 
52
- # Return self for chaining
53
- self
54
+ self.guifg = color
54
55
  end
55
56
 
56
57
  # Sets guibg and ctermbg simultaneously. `hex` is automatically converted to
57
58
  # the 256 color code for ctermbg.
58
- def bg=(hex)
59
- self.guibg = hex
60
- self.ctermbg = Color.hex_to_256(hex)
59
+ #
60
+ # @param [String] hex a hexidecimal color
61
+ def bg=(color)
62
+ if color == 'NONE'
63
+ self.ctermbg = color
64
+ elsif Color.is_hexadecimal?(color)
65
+ self.ctermbg = Color.hex_to_256(color)
66
+ else
67
+ raise ColorError.new "invalid hexadecimal color #{color}"
68
+ end
61
69
 
62
- # Return self for chaining
63
- self
70
+ self.guibg = color
64
71
  end
65
72
 
66
73
  # Updates/sets the current highlight's arguments.
@@ -28,7 +28,7 @@ module Vic
28
28
  # @param [String] group the group name
29
29
  # @return [Colorscheme::Highlight,nil] the highlight
30
30
  def find_by_group(group)
31
- find {|h| h.group == group }
31
+ find {|h| h.group == group.to_sym }
32
32
  end
33
33
  end
34
34
  end
@@ -61,7 +61,7 @@ module Vic
61
61
  end
62
62
  alias_method :highlights, :highlight_set
63
63
 
64
- # Creates a new highlight or updates one if it exists.
64
+ # Creates a new highlight
65
65
  #
66
66
  # If inside of a language block the langauge name is automatcially prepended
67
67
  # to the group name of the new highlight.
@@ -69,32 +69,21 @@ module Vic
69
69
  # @see Vic::Highlight
70
70
  # @return [Vic::Highlight] the new highlight
71
71
  def highlight(group, args={})
72
- hilight = highlight_set.find_by_group(group)
73
- no_args = args.empty?
72
+ return if args.empty?
74
73
 
75
- # If the highlight doesn't exist or no args were passed, create the
76
- # highlight. This enables more flexible syntax for situations where you
77
- # may need to create or update a highlight using this syntax:
78
- #
79
- # `hi('Normal').gui('bold')
80
- #
81
- # Note: If a highlight has no arguments it isn't rendered.
82
- if not hilight and no_args
83
- hilight = Highlight.new("#{language}#{group}")
84
- highlight_set.add(hilight)
85
- elsif hilight and no_args
86
- return hilight
87
- elsif hilight
88
- hilight.update_arguments!(args)
74
+ if h = find_highlight(group)
75
+ h.update_arguments! args
89
76
  else
90
- hilight = Highlight.new("#{language}#{group}", args)
91
- highlight_set.add(hilight)
77
+ h = Highlight.new "#{language}#{group}", args
78
+ highlight_set.add h
92
79
  end
93
-
94
- hilight
95
80
  end
96
81
  alias_method :hi, :highlight
97
82
 
83
+ def find_highlight(group)
84
+ highlight_set.find_by_group(group)
85
+ end
86
+
98
87
  # Sets the current language to name. Any new highlights created will have
99
88
  # the language name automatically prepended.
100
89
  #
data/lib/vic.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Vic
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
4
4
 
5
5
  require 'vic/color'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000Z
12
+ date: 2012-02-22 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Create Vim colorschemes with Ruby
15
15
  email: cjholdbrooks@gmail.com