Project

General

Profile

Feature #2854 ยป wiki_template.txt

Vianney Lecroart, 2009-02-27 09:53

 
1
      # wiki template macro
2
      desc "Replace token inside a template. Example:\n\n !{{template(WikiTemplatePage,token=foo,token2=bar)}}."
3
      macro :template do |obj, args|
4
        page = Wiki.find_page(args.shift.to_s, :project => @project)
5
        raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
6

    
7
        @included_wiki_pages ||= []
8
        raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
9
        @included_wiki_pages << page.title
10
        out = textilizable(page.content, :text, :attachments => page.attachments)
11
        @included_wiki_pages.pop
12

    
13
        args.collect do |v|
14
          v[/(\w+)\W*\=\W*(.+)$/]
15
          key = $1
16
          value = $2.strip.gsub("<br />", "")
17
          out = out.gsub(key, value)
18
        end
19
        out
20
      end
    (1-1/1)