Skip to content

Instantly share code, notes, and snippets.

@femto113
Created February 10, 2011 22:01
Show Gist options
  • Save femto113/821445 to your computer and use it in GitHub Desktop.
Save femto113/821445 to your computer and use it in GitHub Desktop.
Server-side view source for Rails via after_filter with SyntaxHighlighter
class MyController < ApplicationController
after_filter { response.body = %Q{<html><body><pre>#{CGI.escapeHTML(response.body)}</pre></body></html>} }
#...
end
class MyController < ApplicationController
after_filter { response.body = %Q{
<html>
<head>
<title>source for #{request.url}</title>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
</head>
<body>
<pre class="brush: xml">#{CGI.escapeHTML(response.body)}</pre>
<script type="text/javascript">SyntaxHighlighter.all()</script>
</body>
</html>
} if request.url =~ /VS$/ }
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment