Fixed collision with render on pygments_code.rb

This commit is contained in:
Brandon Mathis 2012-05-24 10:18:44 -05:00
parent e81e1c8289
commit 4de8189651

View File

@ -16,19 +16,16 @@ module HighlightCode
end end
def pygments(code, lang) def pygments(code, lang)
if defined?(PYGMENTS_CACHE_DIR) path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html") if defined?(PYGMENTS_CACHE_DIR)
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html")
if File.exist?(path) if File.exist?(path)
highlighted_code = File.read(path) highlighted_code = File.read(path)
else else
highlighted_code = render(code, lang) highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
File.open(path, 'w') {|f| f.print(highlighted_code) } File.open(path, 'w') {|f| f.print(highlighted_code) } if path
end
else
highlighted_code = render(code, lang)
end end
highlighted_code highlighted_code
end end
def tableize_code (str, lang = '') def tableize_code (str, lang = '')
table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">' table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
code = '' code = ''
@ -38,8 +35,4 @@ module HighlightCode
end end
table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
end end
def render(code, lang)
Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
end
end end