Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simplify helper

  • Loading branch information...
commit 295519681c5edeadb36bb7c46f04d5d9d4e3e2d4 1 parent 3015421
@saysjonathan authored
Showing with 8 additions and 26 deletions.
  1. +8 −26 lib/sinatra/pygments.rb
View
34 lib/sinatra/pygments.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.