pygments.rb 0.2.13 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +45 -19
- data/Rakefile +21 -11
- data/bench.rb +15 -48
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments.rb +3 -6
- data/lib/pygments/mentos.py +343 -0
- data/lib/pygments/popen.rb +383 -0
- data/lib/pygments/version.rb +1 -1
- data/pygments.rb.gemspec +5 -4
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +208 -84
- data/vendor/pygments-main/pygments/lexers/_mapping.py +1 -1
- data/vendor/pygments-main/pygments/lexers/shell.py +1 -1
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +80 -22
- data/ext/extconf.rb +0 -14
- data/ext/pygments.c +0 -466
- data/lib/pygments/c.rb +0 -54
- data/lib/pygments/ffi.rb +0 -155
- data/vendor/.gitignore +0 -1
data/lib/pygments/c.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Pygments
|
2
|
-
module C
|
3
|
-
extend self
|
4
|
-
|
5
|
-
def start(python_path = File.expand_path('../../../vendor/pygments-main/', __FILE__))
|
6
|
-
ENV['PYTHONPATH'], prev = python_path, ENV['PYTHONPATH']
|
7
|
-
require 'pygments_ext'
|
8
|
-
@started = true
|
9
|
-
ensure
|
10
|
-
ENV['PYTHONPATH'] = prev
|
11
|
-
end
|
12
|
-
|
13
|
-
def stop
|
14
|
-
end
|
15
|
-
|
16
|
-
def formatters
|
17
|
-
start unless @started
|
18
|
-
|
19
|
-
_formatters.inject(Hash.new) do |hash, (name, desc, aliases)|
|
20
|
-
name.sub!(/Formatter$/,'')
|
21
|
-
hash[name] = {
|
22
|
-
:name => name,
|
23
|
-
:description => desc,
|
24
|
-
:aliases => aliases
|
25
|
-
}
|
26
|
-
hash
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def lexers
|
31
|
-
start unless @started
|
32
|
-
|
33
|
-
_lexers.inject(Hash.new) do |hash, (name, aliases, files, mimes)|
|
34
|
-
hash[name] = {
|
35
|
-
:description => name,
|
36
|
-
:aliases => aliases,
|
37
|
-
:filenames => files,
|
38
|
-
:mimetypes => mimes
|
39
|
-
}
|
40
|
-
hash
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def highlight(code, opts={})
|
45
|
-
start unless @started
|
46
|
-
|
47
|
-
out = _highlight(code, opts)
|
48
|
-
if opts[:formatter].nil? or opts[:formatter].to_s.downcase == 'html'
|
49
|
-
out.gsub!(%r{</pre></div>\Z}, "</pre>\n</div>")
|
50
|
-
end
|
51
|
-
out
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/pygments/ffi.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'rubypython'
|
2
|
-
|
3
|
-
module Pygments
|
4
|
-
module FFI
|
5
|
-
extend self
|
6
|
-
|
7
|
-
def start(pygments_path = File.expand_path('../../../vendor/pygments-main/', __FILE__))
|
8
|
-
RubyPython.start
|
9
|
-
RubyPython.import('pkg_resources') rescue nil
|
10
|
-
sys = RubyPython.import('sys')
|
11
|
-
sys.path.insert(0, pygments_path)
|
12
|
-
|
13
|
-
@modules = [ :lexers, :formatters, :styles, :filters ].inject(Hash.new) do |hash, name|
|
14
|
-
hash[name] = RubyPython.import("pygments.#{name}")
|
15
|
-
hash
|
16
|
-
end
|
17
|
-
|
18
|
-
@pygments = RubyPython.import('pygments')
|
19
|
-
end
|
20
|
-
|
21
|
-
def stop
|
22
|
-
RubyPython.stop
|
23
|
-
@pygments = nil
|
24
|
-
@modules = {}
|
25
|
-
end
|
26
|
-
|
27
|
-
def formatters
|
28
|
-
start unless pygments
|
29
|
-
@modules[:formatters].get_all_formatters.to_enum.inject(Hash.new) do |hash, fmt|
|
30
|
-
name = fmt.__name__.rubify.sub!(/Formatter$/,'')
|
31
|
-
|
32
|
-
hash[name] = {
|
33
|
-
:name => name,
|
34
|
-
:description => fmt.name.rubify,
|
35
|
-
:aliases => fmt.aliases.rubify
|
36
|
-
}
|
37
|
-
hash
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def lexers
|
42
|
-
start unless pygments
|
43
|
-
@modules[:lexers].get_all_lexers.to_enum.inject(Hash.new) do |hash, lxr|
|
44
|
-
lxr = lxr.rubify
|
45
|
-
name = lxr.first
|
46
|
-
|
47
|
-
hash[name] = {
|
48
|
-
:name => name,
|
49
|
-
:aliases => lxr[1],
|
50
|
-
:filenames => lxr[2],
|
51
|
-
:mimetypes => lxr[3]
|
52
|
-
}
|
53
|
-
hash
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def filters
|
58
|
-
start unless pygments
|
59
|
-
@modules[:filters].get_all_filters.to_enum.map{ |o| o.rubify }
|
60
|
-
end
|
61
|
-
|
62
|
-
def styles
|
63
|
-
start unless pygments
|
64
|
-
@modules[:styles].get_all_styles.to_enum.map{ |o| o.rubify }
|
65
|
-
end
|
66
|
-
|
67
|
-
def css(klass='', opts={})
|
68
|
-
if klass.is_a?(Hash)
|
69
|
-
opts = klass
|
70
|
-
klass = ''
|
71
|
-
end
|
72
|
-
fmt = formatter_for('html', opts)
|
73
|
-
fmt.get_style_defs(klass).rubify
|
74
|
-
end
|
75
|
-
|
76
|
-
def lexer_name_for(*args)
|
77
|
-
lxr = lexer_for(*args)
|
78
|
-
lxr.aliases[0].rubify if lxr
|
79
|
-
end
|
80
|
-
|
81
|
-
def highlight(code, opts={})
|
82
|
-
start unless pygments
|
83
|
-
|
84
|
-
if code.nil? or code.empty?
|
85
|
-
return code
|
86
|
-
end
|
87
|
-
|
88
|
-
opts[:options] ||= {}
|
89
|
-
opts[:options][:outencoding] ||= 'utf-8'
|
90
|
-
|
91
|
-
lexer = lexer_for(code, opts)
|
92
|
-
|
93
|
-
kwargs = opts[:options] || {}
|
94
|
-
fmt_name = (opts[:formatter] || 'html').downcase
|
95
|
-
formatter = formatter_for(fmt_name, kwargs)
|
96
|
-
|
97
|
-
out = pygments.highlight(code, lexer, formatter)
|
98
|
-
str = out.rubify
|
99
|
-
|
100
|
-
# ruby's GC will clean these up eventually, but we explicitly
|
101
|
-
# decref to avoid unncessary memory/gc pressure.
|
102
|
-
[ lexer, formatter, out ].each do |obj|
|
103
|
-
obj.pObject.xDecref
|
104
|
-
end
|
105
|
-
|
106
|
-
str.force_encoding(opts[:options][:outencoding]) if str.respond_to?(:force_encoding)
|
107
|
-
if fmt_name == 'html'
|
108
|
-
str.gsub!(%r{</pre></div>\Z}, "</pre>\n</div>")
|
109
|
-
end
|
110
|
-
|
111
|
-
str
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
|
116
|
-
attr_reader :pygments
|
117
|
-
|
118
|
-
def formatter_for(name, opts={})
|
119
|
-
start unless pygments
|
120
|
-
@modules[:formatters].get_formatter_by_name!(name, opts)
|
121
|
-
end
|
122
|
-
|
123
|
-
def lexer_for(code, opts={})
|
124
|
-
start unless pygments
|
125
|
-
|
126
|
-
if code.is_a?(Hash)
|
127
|
-
opts = code
|
128
|
-
code = nil
|
129
|
-
end
|
130
|
-
|
131
|
-
mod = @modules[:lexers]
|
132
|
-
kwargs = opts[:options] || {}
|
133
|
-
|
134
|
-
if name = opts[:lexer]
|
135
|
-
mod.get_lexer_by_name!(name, kwargs)
|
136
|
-
|
137
|
-
elsif name = opts[:mimetype]
|
138
|
-
mod.get_lexer_for_mimetype!(name, kwargs)
|
139
|
-
|
140
|
-
elsif name = opts[:filename]
|
141
|
-
if code
|
142
|
-
mod.guess_lexer_for_filename!(name, code, kwargs)
|
143
|
-
else
|
144
|
-
mod.get_lexer_for_filename!(name, kwargs)
|
145
|
-
end
|
146
|
-
|
147
|
-
elsif code
|
148
|
-
mod.guess_lexer!(code, kwargs)
|
149
|
-
|
150
|
-
else
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
data/vendor/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*.pyc
|