vic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ module Vic
2
+ class Colorscheme
3
+ attr_accessor :colors_name
4
+
5
+ def initialize(colors_name, &block)
6
+ @colors_name = colors_name
7
+ instance_eval(&block) if block_given?
8
+ end
9
+
10
+ # Retrieves the background color.
11
+ #
12
+ # @return [String] 'light' or 'dark'
13
+ def background
14
+ @background ||= background!
15
+ end
16
+
17
+ # Sets the background color.
18
+ #
19
+ # @param [String] a value of 'light' or 'dark'
20
+ # @return [String] the background attribute
21
+ def background=(light_or_dark)
22
+ unless (light_or_dark =~ /^light$|^dark$/).nil?
23
+ @background = light_or_dark
24
+ end
25
+ end
26
+
27
+ # Sets the background color by attempting to determine it.
28
+ #
29
+ # @return[String] the background attribute
30
+ def background!
31
+ @background =
32
+ if (normal = highlights.select {|h| h.group_name == 'Normal'}.first)
33
+ return 'dark' unless color = normal.guibg
34
+ color.partition('#').last.to_i(16) <= 8421504 ? 'dark' : 'light'
35
+ else
36
+ 'dark'
37
+ end
38
+ end
39
+
40
+ # Returns the set of highlights belonging the colorscheme
41
+ #
42
+ # @return[Array] the highlights
43
+ def highlights
44
+ @highlights ||= []
45
+ end
46
+
47
+ # Proxy method for `Vim::Highlight#new`. If inside of a language block the
48
+ # langauge name is automatcially prepended to the group name of the new
49
+ # highlight.
50
+ #
51
+ # @see Vim::Highlight
52
+ # @return [Vim::Highlight] the new highlight
53
+ def highlight(group_name, args={}, &block)
54
+ group_name = "#{@language}#{group_name}" if @language
55
+ highlights.push(Highlight.new group_name, args, &block).first
56
+ end
57
+ alias_method :hi, :highlight
58
+
59
+ def language(name, &block)
60
+ @language = name
61
+ yield if block_given?
62
+ @language = nil
63
+ end
64
+
65
+ def header
66
+ <<-EOT.gsub(/^ {6}/, '')
67
+ " Vim color file
68
+
69
+ set background=#{background}
70
+ hi clear
71
+
72
+ if exists("syntax_on")
73
+ syntax reset
74
+ endif
75
+
76
+ let g:colors_name="#{colors_name}"
77
+ EOT
78
+ end
79
+
80
+ def write
81
+ [header, highlights.map {|h| h.write }].join("\n")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ module Vic
2
+ class Highlight
3
+ VALID_ARGS = {
4
+ :normal_terminal => %w{term start stop},
5
+ :color_terminal => %w{cterm ctermfg ctermbg},
6
+ :gui => %w{gui guifg guibg guisp font}
7
+ }
8
+
9
+ attr_accessor :group_name, *VALID_ARGS.values.flatten
10
+
11
+ def initialize(group_name, args={})
12
+ @group_name = group_name
13
+
14
+ args.each {|arg, val| send("#{arg}=", val) if respond_to? arg }
15
+ end
16
+
17
+ def write
18
+ "hi #{group_name} #{arguments}" unless arguments.empty?
19
+ end
20
+
21
+ private
22
+
23
+ def arguments
24
+ valid_arguments.map do |arg|
25
+ val = send(arg)
26
+ "#{arg}=#{val}" unless val.nil? or val.empty?
27
+ end.compact.join(' ')
28
+ end
29
+
30
+ def valid_arguments
31
+ VALID_ARGS.values.flatten
32
+ end
33
+ end
34
+ end
data/lib/vic.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Vic
2
+ VERSION = '0.0.1'
3
+ end
4
+
5
+ require 'vic/colorscheme'
6
+ require 'vic/highlight'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joel Holdbrooks
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-06 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Create Vim colorschemes with Ruby
15
+ email: cjholdbrooks@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/vic.rb
21
+ - lib/vic/colorscheme.rb
22
+ - lib/vic/highlight.rb
23
+ homepage: https://github.com/noprompt/vic
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.10
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Create Vim colorschemes
47
+ test_files: []