From 08725eb2348cb4b2a1802fe4dde0b18de04c7d21 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Sun, 6 Mar 2011 01:57:08 -0800 Subject: [PATCH] use the new albino gem --- jekyll.gemspec | 1 + lib/jekyll.rb | 2 +- lib/jekyll/albino.rb | 120 ------------------------------------------- 3 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 lib/jekyll/albino.rb diff --git a/jekyll.gemspec b/jekyll.gemspec index b3a1b6dc..84780365 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -27,6 +27,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency('classifier', ">= 1.3.1") s.add_runtime_dependency('directory_watcher', ">= 1.1.1") s.add_runtime_dependency('maruku', ">= 0.5.9") + s.add_runtime_dependency('albino', ">= 1.3.2") s.add_runtime_dependency('rdiscount', ">= 1.6.8") s.add_development_dependency('redgreen', ">= 1.2.2") diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 7928850c..d6258a61 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -23,6 +23,7 @@ require 'yaml' # 3rd party require 'liquid' require 'maruku' +require 'albino' # internal requires require 'jekyll/core_ext' @@ -32,7 +33,6 @@ require 'jekyll/layout' require 'jekyll/page' require 'jekyll/post' require 'jekyll/filters' -require 'jekyll/albino' require 'jekyll/static_file' require 'jekyll/errors' diff --git a/lib/jekyll/albino.rb b/lib/jekyll/albino.rb deleted file mode 100644 index f71e6382..00000000 --- a/lib/jekyll/albino.rb +++ /dev/null @@ -1,120 +0,0 @@ -## -# Wrapper for the Pygments command line tool, pygmentize. -# -# Pygments: http://pygments.org/ -# -# Assumes pygmentize is in the path. If not, set its location -# with Albino.bin = '/path/to/pygmentize' -# -# Use like so: -# -# @syntaxer = Albino.new('/some/file.rb', :ruby) -# puts @syntaxer.colorize -# -# This'll print out an HTMLized, Ruby-highlighted version -# of '/some/file.rb'. -# -# To use another formatter, pass it as the third argument: -# -# @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode) -# puts @syntaxer.colorize -# -# You can also use the #colorize class method: -# -# puts Albino.colorize('/some/file.rb', :ruby) -# -# Another also: you get a #to_s, for somewhat nicer use in Rails views. -# -# ... helper file ... -# def highlight(text) -# Albino.new(text, :ruby) -# end -# -# ... view file ... -# <%= highlight text %> -# -# The default lexer is 'text'. You need to specify a lexer yourself; -# because we are using STDIN there is no auto-detect. -# -# To see all lexers and formatters available, run `pygmentize -L`. -# -# Chris Wanstrath // chris@ozmm.org -# GitHub // http://github.com -# - -class Albino - @@bin = Rails.development? ? 'pygmentize' : '/usr/bin/pygmentize' rescue 'pygmentize' - - def self.bin=(path) - @@bin = path - end - - def self.colorize(*args) - new(*args).colorize - end - - def initialize(target, lexer = :text, format = :html) - @target = target - @options = { :l => lexer, :f => format, :O => 'encoding=utf-8' } - end - - def execute(command) - output = '' - IO.popen(command, mode='r+') do |p| - p.write @target - p.close_write - output = p.read.strip - end - output - end - - def colorize(options = {}) - html = execute(@@bin + convert_options(options)) - # Work around an RDiscount bug: http://gist.github.com/97682 - html.to_s.sub(%r{\Z}, "\n") - end - alias_method :to_s, :colorize - - def convert_options(options = {}) - @options.merge(options).inject('') do |string, (flag, value)| - string + " -#{flag} #{value}" - end - end -end - -if $0 == __FILE__ - require 'rubygems' - require 'test/spec' - require 'mocha' - begin require 'redgreen'; rescue LoadError; end - - context "Albino" do - setup do - @syntaxer = Albino.new(__FILE__, :ruby) - end - - specify "defaults to text" do - syntaxer = Albino.new(__FILE__) - syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true) - syntaxer.colorize - end - - specify "accepts options" do - @syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true) - @syntaxer.colorize - end - - specify "works with strings" do - syntaxer = Albino.new('class New; end', :ruby) - assert_match %r(highlight), syntaxer.colorize - end - - specify "aliases to_s" do - assert_equal @syntaxer.colorize, @syntaxer.to_s - end - - specify "class method colorize" do - assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby) - end - end -end