Make html_ext Available as a Helper

... and protected.
This commit is contained in:
Jacques Distler 2009-12-16 00:59:33 -06:00
parent f3b69bc57b
commit fe877a10b4
3 changed files with 19 additions and 13 deletions

View file

@ -19,13 +19,22 @@ class ApplicationController < ActionController::Base
Wiki.new
end
helper_method :xhtml_enabled?, :html_ext
protected
def xhtml_enabled?
in_a_web? and [:markdownMML, :markdownPNG, :markdown].include?(@web.markup)
end
helper_method :xhtml_enabled?
def html_ext
if xhtml_enabled? && request.env.include?('HTTP_ACCEPT') &&
Mime::Type.parse(request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
'xhtml'
else
'html'
end
end
def check_authorization
if in_a_web? and authorization_needed? and not authorized?

View file

@ -380,15 +380,6 @@ class WikiController < ApplicationController
end
end
def html_ext
if xhtml_enabled? && request.env.include?('HTTP_ACCEPT') &&
Mime::Type.parse(request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
'xhtml'
else
'html'
end
end
protected
def do_caching?

View file

@ -64,7 +64,7 @@ class UrlGenerator < AbstractUrlGenerator
case mode
when :export
if known_file
%{<a class="existingWikiWord" title="#{description}" href="#{CGI.escape(name)}.#{@controller.html_ext}">#{text}</a>}
%{<a class="existingWikiWord" title="#{description}" href="#{CGI.escape(name)}.#{html_ext}">#{text}</a>}
else
%{<span class="newWikiWord">#{text}</span>}
end
@ -92,7 +92,7 @@ class UrlGenerator < AbstractUrlGenerator
case mode
when :export
if known_page
%{<a class="existingWikiWord" href="#{CGI.escape(name)}.#{@controller.html_ext}">#{text}</a>}
%{<a class="existingWikiWord" href="#{CGI.escape(name)}.#{html_ext}">#{text}</a>}
else
%{<span class="newWikiWord">#{text}</span>}
end
@ -182,4 +182,10 @@ class UrlGenerator < AbstractUrlGenerator
:id => name, :only_path => true
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
end
def html_ext
@html_ext ||= @controller.method(:html_ext).call
# Why method().call ? A Ruby 1.9.2preview1 bug:
# http://redmine.ruby-lang.org/issues/show/1802
end
end