Project

General

Profile

Actions

Feature #2854

closed

macro to make wiki template

Added by Vianney Lecroart almost 16 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
2009-02-27
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

I created a basic system to enable wiki template page, like in MediaWiki.

Just add the attached file in the macros.rb

Use:

  • Create a template wiki page, for example TemplateTest and write:
    My name is t_name and I'm t_nat.
    
  • Create an instance wiki page, for example Test1 and write:
    {{template(TemplateTest, t_name=acemtp, t_nat=French)}}
    

    and it'll display:
    My name is acemtp and I'm French.
    

Files

wiki_template.txt (860 Bytes) wiki_template.txt Vianney Lecroart, 2009-02-27 09:53
Actions #1

Updated by Craig Taverner almost 16 years ago

I wanted to use this immediately, so I wrapped it in a redmine plugin. There was a small trick needed, so here's the relevant code to be put, for example, in redmine_wt/lib/wt.rb and called from redmine_wt/init.rb using require_dependency.

# Dependency loading hell. http://www.ruby-forum.com/topic/166578#new
require 'dispatcher'
Dispatcher.to_prepare do
  Redmine::WikiFormatting::Macros.class_eval do

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

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

      args.collect do |v|
        v[/(\w+)\W*\=\W*(.+)$/]
        key = $1
        value = $2.strip.gsub("<br />", "")
        out = out.gsub(key, value)
      end
      out
    end
  end
end

I've not published this plugin, since it's so simple, but thought I should at least comment on this issue. Basically the above code is 90% Vianney's wiki_template.txt file, with a small wrapper based on code I saw in the init.rb of the task-board plugin by Dan Hodos.

Actions #2

Updated by Vianney Lecroart almost 16 years ago

Thanks for the plugin, I didn't know that we can add new macro with plugin (it's my first redmine and ruby hack), it's nice.

Actions #3

Updated by Javier Barroso over 15 years ago

Hi Craig,

Could you explain a bit more how install your little plugin ? In my redmine init.rb is only in plugins.

So, which should be the content of init.rb.

How could I add this plugin to plugins directory ?

vendor/plugins/redmine_wikitemplate/{init.rb, wt.rb}, any file more ?

Thank you !

Actions #4

Updated by Neil McFarlane almost 14 years ago

This seems quite useful, any chance we could get something like this integrated? Perhaps "custom parameterizable macros"?

Actions #5

Updated by William Roush about 13 years ago

Wiki templates are a huge deal, we should have some official support for them.

Actions #6

Updated by Jan Niggemann (redmine.org team member) almost 12 years ago

Closing this, status is resolved since 400 days and more (issue was last updated more than 400 days ago)...

Actions #7

Updated by Jan Niggemann (redmine.org team member) almost 12 years ago

  • Status changed from Resolved to Closed
Actions #8

Updated by Holger Just about 11 years ago

As one of our customers at Planio Redmine hosting asked for this macro, we adapted it by reducing code duplication and transformed it into a full plugin. You can find the GPL-licensed plugin at https://github.com/planio-gmbh/redmine_wiki_template.

Actions

Also available in: Atom PDF