Feature #2854
macro to make wiki template
| Status: | Resolved | Start date: | 2009-02-27 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | Plugin API | |||
| Target version: | - | |||
| 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.
History
#1 Updated by Craig Taverner about 3 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.
1# Dependency loading hell. http://www.ruby-forum.com/topic/166578#new
2require 'dispatcher'
3Dispatcher.to_prepare do
4 Redmine::WikiFormatting::Macros.class_eval do
5
6 # wiki template macro
7 desc "Replace token inside a template. Example:\n\n !{{template(WikiTemplatePage,token=foo,token2=bar)}}."
8 macro :template do |obj, args|
9 page = Wiki.find_page(args.shift.to_s, :project => @project)
10 raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
11
12 @included_wiki_pages ||= []
13 raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
14 @included_wiki_pages << page.title
15 out = textilizable(page.content, :text, :attachments => page.attachments)
16 @included_wiki_pages.pop
17
18 args.collect do |v|
19 v[/(\w+)\W*\=\W*(.+)$/]
20 key = $1
21 value = $2.strip.gsub("<br />", "")
22 out = out.gsub(key, value)
23 end
24 out
25 end
26 end
27end
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.
#2 Updated by Vianney Lecroart about 3 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.
#3 Updated by Javier Barroso almost 3 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 !
#4 Updated by Neil McFarlane over 1 year ago
This seems quite useful, any chance we could get something like this integrated? Perhaps "custom parameterizable macros"?
#5 Updated by William Roush 7 months ago
Wiki templates are a huge deal, we should have some official support for them.
