2010-01-11 13:38:44 +01:00
|
|
|
require 'redmine'
|
2012-08-02 12:09:00 +02:00
|
|
|
require "#{Rails.root}/plugins/wiki_external_filter/app/helpers/wiki_external_filter_helper"
|
2010-01-11 13:38:44 +01:00
|
|
|
|
2012-08-02 12:09:00 +02:00
|
|
|
Rails.logger.info 'Starting wiki_external_filter plugin for Redmin'
|
2010-01-11 13:38:44 +01:00
|
|
|
|
|
|
|
Redmine::Plugin.register :wiki_external_filter do
|
|
|
|
name 'Wiki External Filter Plugin'
|
|
|
|
author 'Alexander Tsvyashchenko'
|
|
|
|
description 'Processes given text using external command and renders its output'
|
|
|
|
author_url 'http://www.ndl.kiev.ua'
|
2010-03-26 23:58:29 +01:00
|
|
|
version '0.0.2'
|
2012-08-02 12:09:00 +02:00
|
|
|
requires_redmine :version_or_higher => '2.0.0'
|
|
|
|
|
2010-01-11 13:38:44 +01:00
|
|
|
settings :default => {'cache_seconds' => '0'}, :partial => 'wiki_external_filter/settings'
|
|
|
|
|
|
|
|
config = WikiExternalFilterHelper.load_config
|
2012-08-02 12:09:00 +02:00
|
|
|
Rails.logger.debug "Config: #{config.inspect}"
|
2010-01-11 13:38:44 +01:00
|
|
|
|
|
|
|
config.keys.each do |name|
|
2012-08-02 12:09:00 +02:00
|
|
|
Rails.logger.info "Registering #{name} macro with wiki_external_filter"
|
2010-01-11 13:38:44 +01:00
|
|
|
Redmine::WikiFormatting::Macros.register do
|
|
|
|
info = config[name]
|
|
|
|
desc info['description']
|
2012-11-23 07:38:40 +01:00
|
|
|
macro name do |obj, args, text|
|
|
|
|
m = WikiExternalFilterHelper::Macro.new(self, args, text, obj.respond_to?('page') ? obj.page.attachments : nil, name, info)
|
|
|
|
m.render.html_safe
|
2010-01-11 13:38:44 +01:00
|
|
|
end
|
2013-05-10 13:42:51 +02:00
|
|
|
# code borrowed from wiki latex plugin
|
|
|
|
# code borrowed from wiki template macro
|
|
|
|
desc info['description']
|
|
|
|
macro (name + "_include").to_sym do |obj, args, text|
|
|
|
|
page = Wiki.find_page(args.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
|
|
|
|
m = WikiExternalFilterHelper::Macro.new(self, args, page.content.text, page.attachments, name, info)
|
|
|
|
@included_wiki_pages.pop
|
|
|
|
m.render_block(args.to_s)
|
|
|
|
end
|
2010-01-11 13:38:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-10 13:42:51 +02:00
|
|
|
|