rack-pygments 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/pygments.rb +10 -2
- data/lib/rack/pygments/version.rb +2 -2
- metadata +3 -3
data/lib/rack/pygments.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require "nokogiri"
|
2
|
+
require "tempfile"
|
2
3
|
|
3
4
|
module Rack
|
4
5
|
class Pygments
|
5
|
-
|
6
6
|
def initialize(app, opts={})
|
7
7
|
@app = app
|
8
8
|
@tag = opts[:html_tag].nil? ? 'highlight' : opts[:html_tag]
|
@@ -31,7 +31,15 @@ module Rack
|
|
31
31
|
nodes = document.css(@tag)
|
32
32
|
nodes.each do |node|
|
33
33
|
lang = node.attribute(@attr).nil? ? 'bash' : node.attribute(@attr).value
|
34
|
-
|
34
|
+
|
35
|
+
file = Tempfile.new('pygments')
|
36
|
+
file.write node.content
|
37
|
+
file.close
|
38
|
+
|
39
|
+
pygmentized = `#{@bin} -l #{lang} -f html #{file.path}`
|
40
|
+
|
41
|
+
file.delete
|
42
|
+
|
35
43
|
node.replace(Nokogiri::HTML(pygmentized).css("div.highlight").first)
|
36
44
|
end
|
37
45
|
document.to_s
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 4
|
8
|
+
version: "0.4"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Bryan Goines
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-24 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|