Markup, CSS and Helper cataloging
At work, we have a catalog of markup and CSS and any ruby helpers. I wrote this helper for it which takes a code string and spits it out, evals it, and provides the eval’ed html wrapped and indented. The code-highligher does all the highlighting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def code_helper(code) help_block = %{ <pre class="helper">\n<code class="ruby">\n<%= #{h(code)} %>\n</code>\n</pre> } result = instance_eval code, "generated code (#{__FILE__}:#{__LINE__})" result_block = %{ <div class="eval">#{result}</div> } doc = REXML::Document.new(result) markup = "" doc.write(markup, 2) markup_block = %{ <pre class="markup">\n<code class="html">\n#{h(markup)}\n</code>\n</pre>\n } %{ #{help_block} #{markup_block} #{result_block} } end |
And usage:
|
|
<%= code_helper %{ will_paginate(@count, @per_page, @page_num, { :extra_param => "extra1" }) } %> |
would display the code, the (escaped) markup that it generates, and then the straight up html.