diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-10 15:09:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-10 15:09:49 +0000 |
commit | c514316a2efcf4e8df4bc2f2681548ebffa30adf (patch) | |
tree | b9b7bc9ccbbbad1cce2701430788f4dfbf872610 /app/helpers | |
parent | 8b98ceb92c8fba72315d28c3b7664f481547bf24 (diff) | |
download | redmine-c514316a2efcf4e8df4bc2f2681548ebffa30adf.tar.gz redmine-c514316a2efcf4e8df4bc2f2681548ebffa30adf.zip |
wiki branch merged into trunk
git-svn-id: http://redmine.rubyforge.org/svn/trunk@323 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 42 | ||||
-rw-r--r-- | app/helpers/wiki_helper.rb | 19 |
2 files changed, 56 insertions, 5 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ef82c90f..f9010df15 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -63,7 +63,7 @@ module ApplicationHelper end
def format_time(time)
- l_datetime(time) if time
+ l_datetime((time.is_a? String) ? time.to_time : time) if time
end
def day_name(day)
@@ -92,10 +92,42 @@ module ApplicationHelper html
end
- def textilizable(text)
- text = (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") ? RedCloth.new(h(text)).to_html : simple_format(auto_link(h(text)))
- # turn "#id" patterns into links to issues
- text = text.gsub(/#(\d+)([^;\d])/, "<a href='/issues/show/\\1'>#\\1</a>\\2")
+ # textilize text according to system settings and RedCloth availability
+ def textilizable(text, options = {})
+ # different methods for formatting wiki links
+ case options[:wiki_links]
+ when :local
+ # used for local links to html files
+ format_wiki_link = Proc.new {|title| "#{title}.html" }
+ when :anchor
+ # used for single-file wiki export
+ format_wiki_link = Proc.new {|title| "##{title}" }
+ else
+ if @project
+ format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
+ else
+ format_wiki_link = Proc.new {|title| title }
+ end
+ end
+
+ # turn wiki links into textile links:
+ # example:
+ # [[link]] -> "link":link
+ # [[link|title]] -> "title":link
+ text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
+
+ # turn issue ids to textile links
+ # example:
+ # #52 -> "#52":/issues/show/52
+ text = text.gsub(/#(\d+)([\s\.\(\)\-,:;])/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) + $2 }
+
+ # turn revision ids to textile links (@project needed)
+ # example:
+ # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
+ text = text.gsub(/r(\d+)([\s\.\(\)\-,:;])/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) + $2 } if @project
+
+ # finally textilize text
+ text = (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") ? auto_link(RedCloth.new(text, [:filter_html]).to_html) : simple_format(auto_link(h(text)))
end
def error_messages_for(object_name, options = {})
diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb new file mode 100644 index 000000000..32b376925 --- /dev/null +++ b/app/helpers/wiki_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module WikiHelper +end |