Skip to content

Instantly share code, notes, and snippets.

@robhurring
Created March 24, 2009 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robhurring/84143 to your computer and use it in GitHub Desktop.
Save robhurring/84143 to your computer and use it in GitHub Desktop.
object debugging with syntax highlight
<!-- using -->
<%= syntax_debug @object %>
# requires the syntax gem: `gem install syntax`
def syntax_debug(object, lang = :yaml)
require 'syntax/convertors/html'
concat(content_tag(:style, :type => 'text/css', :media => 'screen'){
%{
.debug_dump .keyword,
.debug_dump .key { font-weight: bold; }
.debug_dump .class,
.debug_dump .type { color:#445588;
font-weight: bold; }
.debug_dump .method { color:#990000;
font-weight:bold; }
.debug_dump .constant,
.debug_dump .document { color: #177F80; }
.debug_dump .global { color: #177F80; }
.debug_dump .punct { color: #333; }
.debug_dump .attribute { color: #0086B3; }
.debug_dump .comment { color: #999988;
font-style: italic; }
.debug_dump .regex { color: #159828; }
.debug_dump .string { color:#D81745; }
.debug_dump .expr { color:#D81745; }
.debug_dump .number { color: #1C9898; }
.debug_dump .symbol { color: #960B73; }
.debug_dump .pre-strong { font-weight: bold; }
.debug_dump .escape { }
.debug_dump .ident { }
}
})
convertor = Syntax::Convertors::HTML.for_syntax lang.to_s
begin
Marshal::dump(object)
data = object.to_yaml
rescue Exception => e
data = object.inspect
end
concat(content_tag(:div, convertor.convert(data), :class => 'debug_dump'))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment