Move to Rails 3 template UI
Move to Rails 3 template UI

It seems that under Rails 3 the old "self.call" method no longer works
in the same fashion. Previously returning the string "template.source.w"
worked because Rails, evidently, ended up eval'ing it in a context where
"template" resolved to the desired object.

In Rails 3, however, this is no longer the case, and it ends up trying
to call a "template" method on the controller, failing.

Googling for different template handlers shows that some use "render"
(for example, liquid) but I am unable to get any variant of "render" to
work under Rails 3.

On the other hand, the three handlers included with Rails itself (ERB,
Builder, and RJS) all use the "compile" method, as does Haml.

It's hard to tell from the scant in-code documentation, but it looks
like "compile" might be "the" supported way to write template handlers
for now. The only reference I can find to this online is this thread
from back in 2008:

  http://www.ruby-forum.com/topic/159810

In which Josh Peek says:

  I'd really like deprecate the TemplateHandler#render all together. If
  you think your handler can not be compiled, you always just compile in
  a delegate call to your "noncompilable" handler. This leaves us with
  only one method, compile.

So I am not sure if this is the "official" stance on the API, but in
light of the fact that I can't get anything else to work, I am going to
go with "compile" for now.

This unfortunately requires a somewhat ugly gsub call in order to escape
any single quotes that might be in the input, but it seems a necessary
evil. For example, a template with this wikitext markup:

  * don't you like this list?

Will be "compiled" to:

  '<ul>
    <li>don\'t you like this list?<li>
  </ul>
  '

Which when evaluated and emitted to the output steam becomes:

  <ul>
    <li>don't you like this list?</li>
  </ul>

Note that this commit makes things work with Rails 3 only, breaking
Rails 2 support. In a subsequent commit I plan to add in a conditional
code path that kicks in when running under Rails 2.

Signed-off-by: Wincent Colaiuta <c76ac2e9cd86441713c7dfae92c451f3e6d17fdc@wincent.com>

geni/wikitext,barnaclebarnes/wikitext,geni/wikitext,wincent/wikitext,geni/wikitext,barnaclebarnes/wikitext,barnaclebarnes/wikitext,wincent/wikitext