sbfaulkner-kulriir 1.0.1 → 1.0.2
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/bin/kulriir +5 -1
- data/kulriir.gemspec +1 -1
- data/lib/kulriir.rb +32 -7
- metadata +1 -1
data/bin/kulriir
CHANGED
@@ -8,6 +8,7 @@ require 'kulriir'
|
|
8
8
|
opts = GetoptLong.new(
|
9
9
|
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
|
10
10
|
[ "--numbers", "-n", GetoptLong::NO_ARGUMENT ],
|
11
|
+
[ "--remote", "-r", GetoptLong::NO_ARGUMENT ],
|
11
12
|
[ "--syntaxes", "-S", GetoptLong::NO_ARGUMENT ],
|
12
13
|
[ "--syntax", "-s", GetoptLong::REQUIRED_ARGUMENT ],
|
13
14
|
[ "--themes", "-T", GetoptLong::NO_ARGUMENT ],
|
@@ -17,7 +18,7 @@ opts = GetoptLong.new(
|
|
17
18
|
OPTIONS = {
|
18
19
|
:syntax => 'plain_text',
|
19
20
|
:theme => 'mac_classic',
|
20
|
-
:numbers =>
|
21
|
+
:numbers => false
|
21
22
|
}
|
22
23
|
|
23
24
|
opts.each do |opt, arg|
|
@@ -27,6 +28,7 @@ opts.each do |opt, arg|
|
|
27
28
|
puts "\nOptions:"
|
28
29
|
puts " -h, --help Display this message."
|
29
30
|
puts " -n, --numbers Include line numbers."
|
31
|
+
puts " -r, --remote Force use of remote service (when ultraviolet is installed locally)"
|
30
32
|
puts " -S, --syntaxes List all supported syntaxes."
|
31
33
|
puts " -s, --syntax=name The language for the code to be highlighted."
|
32
34
|
puts " -T, --themes List all supported themes."
|
@@ -34,6 +36,8 @@ opts.each do |opt, arg|
|
|
34
36
|
exit 1
|
35
37
|
when '--numbers'
|
36
38
|
OPTIONS[:numbers] = true
|
39
|
+
when '--remote'
|
40
|
+
OPTIONS[:remote] = true
|
37
41
|
when '--syntaxes'
|
38
42
|
puts Kulriir.syntaxes.join("\n")
|
39
43
|
exit
|
data/kulriir.gemspec
CHANGED
data/lib/kulriir.rb
CHANGED
@@ -2,6 +2,13 @@ require 'rest_client'
|
|
2
2
|
require 'rexml/document'
|
3
3
|
|
4
4
|
module Kulriir
|
5
|
+
LOCAL_UV = begin
|
6
|
+
require 'uv'
|
7
|
+
true
|
8
|
+
rescue LoadError => e
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
5
12
|
KULRII_HOST = 'kulrii.heroku.com'
|
6
13
|
|
7
14
|
def self.included(base)
|
@@ -23,21 +30,39 @@ module Kulriir
|
|
23
30
|
# **theme**: theme for highlighting
|
24
31
|
#
|
25
32
|
def highlight(options = {})
|
33
|
+
force_remote = options.delete(:remote)
|
34
|
+
|
26
35
|
options[:numbers] = options.delete(:line_numbers) if options.include?(:line_numbers)
|
27
36
|
options[:syntax] = options.delete(:language) if options.include?(:language)
|
28
37
|
|
29
|
-
options
|
30
|
-
|
31
|
-
|
38
|
+
options = { :numbers => false, :syntax => 'ruby', :theme => 'mac_classic' }.merge(options)
|
39
|
+
|
40
|
+
if LOCAL_UV && ! force_remote
|
41
|
+
Uv.parse(self, 'xhtml', options[:syntax], options[:numbers], options[:theme])
|
42
|
+
else
|
43
|
+
RestClient.post "http://#{KULRII_HOST}/parse", options.merge(:text => self)
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
47
|
class << self
|
35
|
-
def syntaxes
|
36
|
-
|
48
|
+
def syntaxes(options = {})
|
49
|
+
force_remote = options.delete(:remote)
|
50
|
+
|
51
|
+
if LOCAL_UV && ! force_remote
|
52
|
+
Uv.syntaxes
|
53
|
+
else
|
54
|
+
REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/syntaxes")).elements.collect('syntaxes/syntax') { |e| e.text }
|
55
|
+
end
|
37
56
|
end
|
38
57
|
|
39
|
-
def themes
|
40
|
-
|
58
|
+
def themes(options = {})
|
59
|
+
force_remote = options.delete(:remote)
|
60
|
+
|
61
|
+
if LOCAL_UV && ! force_remote
|
62
|
+
Uv.themes
|
63
|
+
else
|
64
|
+
REXML::Document.new(RestClient.get("http://#{KULRII_HOST}/themes")).elements.collect('themes/theme') { |e| e.text }
|
65
|
+
end
|
41
66
|
end
|
42
67
|
end
|
43
68
|
end
|