Class: Pygmentize

Inherits:
Object
  • Object
show all
Defined in:
lib/pygmentize.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.binObject



6
7
8
# File 'lib/pygmentize.rb', line 6

def self.bin
  "/usr/bin/env python #{File.expand_path("../vendor/pygmentize.py", File.dirname(__FILE__))}"
end

.process(source, lexer, args = []) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pygmentize.rb', line 10

def self.process(source, lexer, args = [])
  args += [
    "-l", lexer.to_s,
    "-f", "html",
    "-O", "encoding=#{source.encoding}"
  ]

  IO.popen("#{bin} #{Shellwords.shelljoin args}", "r+") do |io|
    io.write(source)
    io.close_write
    io.read
  end
end