diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-10-27 11:08:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-10-27 11:08:29 +0000 |
commit | a3b9a5aa5fe344cf33a47ccbf1d26a95fbe4e255 (patch) | |
tree | 6b19387c81e2d865a57cf3357340deffdbc5e858 /app | |
parent | 9b624fd1d6f66bbe60d738522d9fc5fd547ef3af (diff) | |
download | redmine-a3b9a5aa5fe344cf33a47ccbf1d26a95fbe4e255.tar.gz redmine-a3b9a5aa5fe344cf33a47ccbf1d26a95fbe4e255.zip |
Makes wiki text formatter pluggable.
Original patch #2025 by Yuki Sonoda slightly edited.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1955 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/wiki_controller.rb | 9 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 28 | ||||
-rw-r--r-- | app/views/layouts/base.rhtml | 2 | ||||
-rw-r--r-- | app/views/mailer/layout.text.html.rhtml | 2 | ||||
-rw-r--r-- | app/views/settings/_general.rhtml | 2 |
5 files changed, 24 insertions, 19 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 114010dff..04bc33a82 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -63,7 +63,7 @@ class WikiController < ApplicationController @page.content = WikiContent.new(:page => @page) if @page.new_record? @content = @page.content_for_version(params[:version]) - @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? + @content.text = initial_page_content(@page) if @content.text.blank? # don't keep previous comment @content.comments = nil if request.get? @@ -208,4 +208,11 @@ private def editable?(page = @page) page.editable_by?(User.current) end + + # Returns the default content of a new wiki page + def initial_page_content(page) + helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) + extend helper unless self.instance_of?(helper) + helper.instance_method(:initial_page_content).bind(self).call(page) + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c72763dbb..aad2c5bec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,10 +17,14 @@ require 'coderay' require 'coderay/helpers/file_type' +require 'forwardable' module ApplicationHelper include Redmine::WikiFormatting::Macros::Definitions + extend Forwardable + def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + def current_role @current_role ||= User.current.role_for_project(@project) end @@ -259,9 +263,7 @@ module ApplicationHelper end end - text = (Setting.text_formatting == 'textile') ? - Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : - simple_format(auto_link(h(text))) + text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) } # different methods for formatting wiki links case options[:wiki_links] @@ -549,18 +551,6 @@ module ApplicationHelper end end - def wikitoolbar_for(field_id) - return '' unless Setting.text_formatting == 'textile' - - help_link = l(:setting_text_formatting) + ': ' + - link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'), - :onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;") - - javascript_include_tag('jstoolbar/jstoolbar') + - javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") + - javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();") - end - def content_for(name, content = nil, &block) @has_content ||= {} @has_content[name] = true @@ -570,4 +560,12 @@ module ApplicationHelper def has_content?(name) (@has_content && @has_content[name]) || false end + + private + + def wiki_helper + helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) + extend helper + return self + end end diff --git a/app/views/layouts/base.rhtml b/app/views/layouts/base.rhtml index 86d23d62f..8cdfcb8e6 100644 --- a/app/views/layouts/base.rhtml +++ b/app/views/layouts/base.rhtml @@ -7,7 +7,7 @@ <meta name="keywords" content="issue,bug,tracker" /> <%= stylesheet_link_tag 'application', :media => 'all' %> <%= javascript_include_tag :defaults %> -<%= stylesheet_link_tag 'jstoolbar' %> +<%= heads_for_wiki_formatter %> <!--[if IE]> <style type="text/css"> * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); } diff --git a/app/views/mailer/layout.text.html.rhtml b/app/views/mailer/layout.text.html.rhtml index c95c94501..12fb654d6 100644 --- a/app/views/mailer/layout.text.html.rhtml +++ b/app/views/mailer/layout.text.html.rhtml @@ -32,6 +32,6 @@ hr { <body> <%= yield %> <hr /> -<span class="footer"><%= Redmine::WikiFormatting.to_html(Setting.emails_footer) %></span> +<span class="footer"><%= Redmine::WikiFormatting.to_html(Setting.text_formatting, Setting.emails_footer) %></span> </body> </html> diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml index bb56c43db..f8d4e67fb 100644 --- a/app/views/settings/_general.rhtml +++ b/app/views/settings/_general.rhtml @@ -39,7 +39,7 @@ <%= select_tag 'settings[protocol]', options_for_select(['http', 'https'], Setting.protocol) %></p> <p><label><%= l(:setting_text_formatting) %></label> -<%= select_tag 'settings[text_formatting]', options_for_select([[l(:label_none), "0"], ["textile", "textile"]], Setting.text_formatting) %></p> +<%= select_tag 'settings[text_formatting]', options_for_select([[l(:label_none), "0"], *Redmine::WikiFormatting.format_names.collect{|name| [name, name]} ], Setting.text_formatting.to_sym) %></p> <p><label><%= l(:setting_wiki_compression) %></label> <%= select_tag 'settings[wiki_compression]', options_for_select( [[l(:label_none), 0], ["gzip", "gzip"]], Setting.wiki_compression) %></p> |