diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-12 14:36:33 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-12 14:36:33 +0000 |
commit | 8a8f819d273e25fa28fb492da92125fb06d1ab01 (patch) | |
tree | 110c62a735f1bddcd3996b25a4f0cab56ddd5553 /lib/redmine/wiki_formatting.rb | |
parent | a8419c1425b55b91edf24db044725d099b6065a8 (diff) | |
download | redmine-8a8f819d273e25fa28fb492da92125fb06d1ab01.tar.gz redmine-8a8f819d273e25fa28fb492da92125fb06d1ab01.zip |
Added wiki macros support. 2 builtin macros are defined: hello_world (sample macro that displays the arguments) and macro_list (display the list of installed macros).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@897 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/wiki_formatting.rb')
-rw-r--r-- | lib/redmine/wiki_formatting.rb | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index da04dd932..4aebe9a96 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -1,13 +1,31 @@ +# 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. + require 'redcloth' require 'coderay' -require 'pp' + module Redmine module WikiFormatting private - class TextileFormatter < RedCloth - RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc] + class TextileFormatter < RedCloth + + RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros] def initialize(*args) super @@ -15,8 +33,9 @@ module Redmine self.no_span_caps=true end - def to_html + def to_html(*rules, &block) @toc = [] + @macros_runner = block super(*RULES).to_s end @@ -72,6 +91,25 @@ module Redmine end end + MACROS_RE = / + \{\{ # opening tag + ([\w]+) # macro name + (\(([^\}]*)\))? # optional arguments + \}\} # closing tag + /x unless const_defined?(:MACROS_RE) + + def inline_macros(text) + text.gsub!(MACROS_RE) do + all, macro = $&, $1.downcase + args = ($3 || '').split(',').each(&:strip) + begin + @macros_runner.call(macro, args) + rescue => e + "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>" + end || all + end + end + AUTO_LINK_RE = %r{ ( # leading text <\w+.*?>| # leading HTML tag, or @@ -115,8 +153,8 @@ module Redmine public - def self.to_html(text, options = {}) - TextileFormatter.new(text).to_html + def self.to_html(text, options = {}, &block) + TextileFormatter.new(text).to_html(&block) end end end |