pygments.rb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pygments/c.rb CHANGED
@@ -1,18 +1,21 @@
1
- ENV['PYTHONPATH'] = File.expand_path('../../../vendor/Pygments-1.4/', __FILE__)
2
- require 'pygments_ext'
3
- ENV['PYTHONPATH'] = nil
4
-
5
1
  module Pygments
6
2
  module C
7
3
  extend self
8
4
 
9
- def start
5
+ def start(python_path = File.expand_path('../../../vendor/Pygments-1.4/', __FILE__))
6
+ ENV['PYTHONPATH'], prev = python_path, ENV['PYTHONPATH']
7
+ require 'pygments_ext'
8
+ @started = true
9
+ ensure
10
+ ENV['PYTHONPATH'] = prev
10
11
  end
11
12
 
12
13
  def stop
13
14
  end
14
15
 
15
16
  def formatters
17
+ start unless @started
18
+
16
19
  _formatters.inject(Hash.new) do |hash, (name, desc, aliases)|
17
20
  name.sub!(/Formatter$/,'')
18
21
  hash[name] = {
@@ -25,6 +28,8 @@ module Pygments
25
28
  end
26
29
 
27
30
  def lexers
31
+ start unless @started
32
+
28
33
  _lexers.inject(Hash.new) do |hash, (name, aliases, files, mimes)|
29
34
  hash[name] = {
30
35
  :description => name,
@@ -37,6 +42,8 @@ module Pygments
37
42
  end
38
43
 
39
44
  def highlight(code, opts={})
45
+ start unless @started
46
+
40
47
  out = _highlight(code, opts)
41
48
  if opts[:formatter].nil? or opts[:formatter].to_s.downcase == 'html'
42
49
  out.gsub!(%r{</pre></div>\Z}, "</pre>\n</div>")
data/lib/pygments/ffi.rb CHANGED
@@ -4,10 +4,10 @@ module Pygments
4
4
  module FFI
5
5
  extend self
6
6
 
7
- def start
7
+ def start(pygments_path = File.expand_path('../../../vendor/Pygments-1.4/', __FILE__))
8
8
  RubyPython.start
9
9
  sys = RubyPython.import('sys')
10
- sys.path.insert(0, File.expand_path('../../../vendor/Pygments-1.4/', __FILE__))
10
+ sys.path.insert(0, pygments_path)
11
11
  sys.path.insert(0, File.expand_path('../../../vendor/python2-chardet-2.0.1/', __FILE__))
12
12
 
13
13
  @modules = [ :lexers, :formatters, :styles, :filters ].inject(Hash.new) do |hash, name|
@@ -81,6 +81,10 @@ module Pygments
81
81
  def highlight(code, opts={})
82
82
  start unless pygments
83
83
 
84
+ if code.nil? or code.empty?
85
+ return code
86
+ end
87
+
84
88
  opts[:options] ||= {}
85
89
  opts[:options][:encoding] ||= 'chardet'
86
90
  opts[:options][:outencoding] ||= 'utf-8'
@@ -1,3 +1,3 @@
1
1
  module Pygments
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -77,6 +77,11 @@ class PygmentsHighlightTest < Test::Unit::TestCase
77
77
 
78
78
  RUBY_CODE = "#!/usr/bin/ruby\nputs 'foo'"
79
79
 
80
+ def test_highlight_empty
81
+ highlight('')
82
+ highlight(nil)
83
+ end
84
+
80
85
  def test_highlight_defaults_to_html
81
86
  code = highlight(RUBY_CODE)
82
87
  assert_match '<span class="c1">#!/usr/bin/ruby</span>', code
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pygments.rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 -07:00
18
+ date: 2011-08-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -569,7 +569,7 @@ files:
569
569
  - vendor/python2-chardet-2.0.1/docs/supported-encodings.html
570
570
  - vendor/python2-chardet-2.0.1/docs/usage.html
571
571
  - vendor/python2-chardet-2.0.1/setup.py
572
- has_rdoc: true
572
+ has_rdoc: false
573
573
  homepage: http://github.com/tmm1/pygments.rb
574
574
  licenses: []
575
575