Class: Vic::Colorscheme
- Inherits:
-
Object
- Object
- Vic::Colorscheme
- Defined in:
- lib/vic/colorscheme.rb
Defined Under Namespace
Classes: Highlight, HighlightSet
Instance Attribute Summary collapse
-
#colors_name ⇒ Object
Returns the value of attribute colors_name.
-
#information(inf = {}) ⇒ Hash
(also: #info)
Returns/sets the information attribute.
Instance Method Summary collapse
-
#background ⇒ String
Returns the background color.
-
#background! ⇒ Object
Sets the background color by attempting to determine it.
-
#background=(light_or_dark) ⇒ String
Sets the background color.
- #find_highlight(group) ⇒ Object
-
#header ⇒ String
Returns the colorscheme header.
-
#highlight(group, args = {}) ⇒ Vic::Highlight
(also: #hi)
Creates a new highlight.
-
#highlight_set ⇒ Object
(also: #highlights)
Returns the set of highlights for the colorscheme.
-
#initialize(colors_name, &block) ⇒ Colorscheme
constructor
A new instance of Colorscheme.
-
#language(name = nil, &block) ⇒ String
Returns the current language or temporarily sets the language to name if a block is given.
-
#language=(name) ⇒ String
Sets the current language to name.
-
#write ⇒ String
Returns the colorscheme as a string.
Constructor Details
#initialize(colors_name, &block) ⇒ Colorscheme
A new instance of Colorscheme. If a block is given with no arguments, the the block will be evaluated in the context of the new colorscheme. Otherwise the block will yield self.
12 13 14 15 16 17 |
# File 'lib/vic/colorscheme.rb', line 12 def initialize(colors_name, &block) @colors_name = colors_name if block_given? block.arity == 0 ? instance_eval(&block) : yield(self) end end |
Instance Attribute Details
#colors_name ⇒ Object
Returns the value of attribute colors_name.
3 4 5 |
# File 'lib/vic/colorscheme.rb', line 3 def colors_name @colors_name end |
#information(inf = {}) ⇒ Hash Also known as: info
Returns/sets the information attribute
23 24 25 |
# File 'lib/vic/colorscheme.rb', line 23 def information @information end |
Instance Method Details
#background ⇒ String
Returns the background color.
31 32 33 |
# File 'lib/vic/colorscheme.rb', line 31 def background @background ||= background! end |
#background! ⇒ Object
Sets the background color by attempting to determine it.
@return the background attribute
48 49 50 51 52 53 54 55 56 |
# File 'lib/vic/colorscheme.rb', line 48 def background! @background = if normal = highlights.find_by_group('Normal') return 'dark' unless color = normal.guibg color.partition('#').last.to_i(16) <= 8421504 ? 'dark' : 'light' else 'dark' end end |
#background=(light_or_dark) ⇒ String
Sets the background color.
39 40 41 42 43 |
# File 'lib/vic/colorscheme.rb', line 39 def background=(light_or_dark) unless (light_or_dark =~ /^light$|^dark$/).nil? @background = light_or_dark end end |
#find_highlight(group) ⇒ Object
83 84 85 |
# File 'lib/vic/colorscheme.rb', line 83 def find_highlight(group) highlight_set.find_by_group(group) end |
#header ⇒ String
Returns the colorscheme header.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vic/colorscheme.rb', line 117 def header <<-EOT.gsub(/^ {6}/, '') " Vim color file #{info.to_a.map do |pair| pair.join(": ").tap {|s| s[0] = '" ' + s[0].upcase } end.join("\n")} set background=#{background} hi clear if exists("syntax_on") syntax reset endif let g:colors_name="#{colors_name}" EOT end |
#highlight(group, args = {}) ⇒ Vic::Highlight Also known as: hi
Creates a new highlight
If inside of a language block the langauge name is automatcially prepended to the group name of the new highlight.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vic/colorscheme.rb', line 71 def highlight(group, args={}) return if args.empty? if h = find_highlight(group) h.update_arguments! args else h = Highlight.new "#{language}#{group}", args highlight_set.add h end end |
#highlight_set ⇒ Object Also known as: highlights
Returns the set of highlights for the colorscheme
59 60 61 |
# File 'lib/vic/colorscheme.rb', line 59 def highlight_set @highlight_set ||= HighlightSet.new end |
#language(name = nil, &block) ⇒ String
Returns the current language or temporarily sets the language to name if a block is given. If a block is given with no arguments, it will be evaluated in the context of the colorscheme, otherwise it will yield the colorscheme.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vic/colorscheme.rb', line 103 def language(name=nil, &block) if @language and not name return @language elsif name and block_given? previous_language = self.language self.language = name block.arity == 0 ? instance_eval(&block) : yield(self) self.language = previous_language end end |
#language=(name) ⇒ String
Sets the current language to name. Any new highlights created will have the language name automatically prepended.
91 92 93 |
# File 'lib/vic/colorscheme.rb', line 91 def language=(name) @language = name end |
#write ⇒ String
Returns the colorscheme as a string
137 138 139 |
# File 'lib/vic/colorscheme.rb', line 137 def write [header, highlights.map(&:write)].join("\n") end |