# Copyright 2008 Wincent Colaiuta
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'wikitext/string'

module Wikitext
  class TemplateHandler
    def initialize view; end

    def render text, locals = {}
      text.w
    end
  end
end

if ActionView::Template.respond_to? :register_template_handler  # Rails 2.1.0_RC1 and above
  ActionView::Template.register_template_handler :wikitext, Wikitext::TemplateHandler
elsif ActionView::Base.respond_to? :register_template_handler   # Rails 2.0.2
  ActionView::Base.register_template_handler :wikitext, Wikitext::TemplateHandler
else
  raise "Incompatible Rails API version (can't find register_template_handler method)"
end

# Copyright 2008-2009 Wincent Colaiuta
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'wikitext/string'

module Wikitext
  class TemplateHandler

    # tested with Rails 2.2.2: the API has now changed so many times that I'm no longer going to support older versions of Rails
    def self.call template
      'template.source.w'
    end
  end
end

Fix breakage caused by recent Rails API changes
Fix breakage caused by recent Rails API changes

The API has now changed so many times in unfathomable (uncommented) ways
that I'm no longer going to support older versions of Rails. The runtime
checks for all the myriad variations are just getting too complicated
and I can't justify maintaining them, especially seeing as I have no
intention of keeping old Rails installations on hand for the purposes of
testing.

The present version is tested and works with Rails 2.2.2. I actually had
a couple of intermediate, but uncommitted, unreleased changes, that I
needed to keep other versions of Rails working (2.1.0RC1, for example).
In the end those changes were short-lived because the API was changed
repeatedly afterwards.

In the latest rounds of changes, the "compilable?" method is no longer
checked, "call" is now invoked anyway, and Rails then proceeds to
evaluate the returned string as Ruby code in some unknown context where
"template" is a local variable! The "render" method is no longer called.

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