-
-
Save martinrehfeld/395331 to your computer and use it in GitHub Desktop.
Syntax highlighting for Ruby code (webby helper)
This file contains 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
require 'syntax/convertors/html' | |
require 'uv' | |
module Code | |
BACKGROUND_COLOR = '#2B2B2B' | |
COLOR = '#E6E1DC' | |
COLORS = { | |
:keyword => '#CC7833', | |
:symbol => '#6E9CBE', | |
:constant => '#DA4939', | |
:attribute => '#D0D0FF', | |
:string => '#A5C261' | |
} | |
def code(opts={}, &block) | |
text = capture_erb(&block) | |
return if text.empty? | |
text.gsub!("<%%", "<%") | |
the_code = Uv.parse( text, "xhtml", opts[:type] || "ruby", false, "twilight") | |
concat_erb(the_code, block.binding) | |
end | |
end | |
Webby::Helpers.register(Code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment