Created
February 8, 2009 22:03
-
-
Save xwmx/60527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax_helper.rb | |
module SyntaxHelper | |
WhiteListHelper.tags.merge(UV_SYNTAX_TAGS) | |
def colorize_code(body, options = {}) | |
options = {:line_numbers => false, :theme => DEFAULT_SYNTAX_STYLE}.merge(options) | |
r = RedCloth.new(body || '') | |
output = r.gsub(/<code[\.|\:]([\w\-]+)>(.*?)<\/code[\.|\:]?\1?>/m) do | |
lang, text = $1, $2 | |
html = "<notextile>" + code((text || ''), {:syntax => (lang if UV_SYNTAXES.include?(lang))}.merge(options)) + "</notextile>" | |
end.to_html | |
end | |
def colorize_paste(paste, options = {}) | |
options = {:line_numbers => true, :theme => DEFAULT_SYNTAX_STYLE}.merge(options) | |
code((paste.body || ''), {:syntax => ( paste.language if UV_SYNTAXES.include?(paste.language))}.merge(options)) | |
end | |
end | |
# initializers/uv_syntax.rb | |
require 'uv' | |
UV_THEMES = %w{active4d all_hallows_eve amy blackboard brilliance_black brilliance_dull cobalt dawn eiffel espresso_libre idle iplastic lazy mac_classic magicwb_amiga pastels_on_dark spacecadet sunburst twilight zenburnesque} | |
DEFAULT_SYNTAX_STYLE = 'mac_classic' | |
UV_SYNTAXES = Uv.syntaxes.dup | |
UV_SYNTAX_TAGS = UV_SYNTAXES.map {|s| "code:#{s}" } + UV_SYNTAXES.map {|s| "code.#{s}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment