Permalink
Browse files

simplify helper

  • Loading branch information...
saysjonathan committed Jan 21, 2011
1 parent 3015421 commit 295519681c5edeadb36bb7c46f04d5d9d4e3e2d4
Showing with 8 additions and 26 deletions.
  1. +8 −26 lib/sinatra/pygments.rb
View
@@ -2,31 +2,13 @@
module Sinatra
module Pygments
- @@pygments = '/usr/bin/pygmentize'
-
- @@options = {
- :lexer => '-l',
- :filter => '-F',
- :format => '-f',
- :options => '-O'
- }
-
- def initialize(string, lexer = :text, format = :html, filter = nil, options = nil)
- args = []
- @@options.each do |k, v|
- args << '#{v} {k}' unless k.nil?
- end
- color(string, args)
- end
-
- def color(string, *options)
- html = ''
- IO.popen(@@pygments + options.join(' ')).each do |p|
- p.write string
- p.close_write
- html = p.read.strip
- end
- html
- end
+ def pygmentize(string, lexer = 'text')
+ pygmentize = IO.popen("pygmentize -f html -l #{lexer}", "w+")
+ pygmentize.puts string
+ pygmentize.close_write
+ result = pygmentize.read
+ pygmentize.close
+ result
+ end
end
end

0 comments on commit 2955196

Please sign in to comment.