]> source.dussan.org Git - redmine.git/commitdiff
Added:
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Feb 2008 15:34:17 +0000 (15:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Feb 2008 15:34:17 +0000 (15:34 +0000)
* the 'include' macro to include a wiki page
* macro escaping support (with exclamation mark)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1153 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/wiki_formatting.rb
lib/redmine/wiki_formatting/macros.rb
test/unit/helpers/application_helper_test.rb

index f7fa803a6b415b3951db3f53d4cf4182ff6930be..79da2a38a5bbdef07a745f2e804044eef7023112 100644 (file)
@@ -93,21 +93,28 @@ module Redmine
       end
       
       MACROS_RE = /
+                    (!)?                        # escaping
+                    (
                     \{\{                        # 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
+          esc, all, macro = $1, $2, $3.downcase
+          args = ($5 || '').split(',').each(&:strip)
+          if esc.nil?
+            begin
+              @macros_runner.call(macro, args)
+            rescue => e
+              "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
+            end || all
+          else
+            all
+          end
         end
       end
       
index f9920afdb0a8ef898cee865c21ab7f8083181992..c0f2b222a5a42e31f0b6b8410dae1d3480021e77 100644 (file)
@@ -62,7 +62,7 @@ module Redmine
       end
           
       # Builtin macros
-      desc "Example macro."
+      desc "Sample macro."
       macro :hello_world do |obj, args|
         "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")
       end
@@ -72,10 +72,27 @@ module Redmine
         out = ''
         @@available_macros.keys.collect(&:to_s).sort.each do |macro|
           out << content_tag('dt', content_tag('code', macro))
-          out << content_tag('dd', simple_format(@@available_macros[macro.to_sym]))
+          out << content_tag('dd', textilizable(@@available_macros[macro.to_sym]))
         end
         content_tag('dl', out)
       end
+      
+      desc "Include a wiki page. Example:\n\n  !{{include(Foo)}}"
+      macro :include do |obj, args|
+        if @project && !@project.wiki.nil?
+          page = @project.wiki.find_page(args.first)
+          if page && page.content
+            @included_wiki_pages ||= []
+            raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
+            @included_wiki_pages << page.title
+            out = textilizable(page.content, :text)
+            @included_wiki_pages.pop
+            out
+          else
+            raise "Page #{args.first} doesn't exist"
+          end
+        end
+      end
     end
   end
 end
index 33509cfc02e5233ed09e8d83f98b728998ec3f50..4e617f69936241b7ccdee581a23a08284dec828d 100644 (file)
@@ -120,6 +120,9 @@ class ApplicationHelperTest < HelperTestCase
   def test_macro_hello_world
     text = "{{hello_world}}"
     assert textilizable(text).match(/Hello world!/)
+    # escaping
+    text = "!{{hello_world}}"
+    assert_equal '<p>{{hello_world}}</p>', textilizable(text)
   end
   
   def test_date_format_default