Feature #2854
closedmacro to make wiki template
0%
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
Updated by Craig Taverner over 15 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.
Updated by Vianney Lecroart over 15 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.
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 !
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"?
Updated by William Roush about 13 years ago
Wiki templates are a huge deal, we should have some official support for them.
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)...
Updated by Jan Niggemann (redmine.org team member) almost 12 years ago
- Status changed from Resolved to Closed
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.