Work with Redmine 2.1 without patch. Tested only on plantuml
This commit is contained in:
parent
0fb61eed3e
commit
b93256fc74
|
@ -5,7 +5,7 @@ module WikiExternalFilterHelper
|
||||||
|
|
||||||
def load_config
|
def load_config
|
||||||
unless @config
|
unless @config
|
||||||
config_file = "#{Rails.root}/plugins/wiki_external_filter/config/wiki_external_filter.yml"
|
config_file = "#{Rails.root}/config/wiki_external_filter.yml"
|
||||||
unless File.exists?(config_file)
|
unless File.exists?(config_file)
|
||||||
raise "Config not found: #{config_file}"
|
raise "Config not found: #{config_file}"
|
||||||
end
|
end
|
||||||
|
@ -22,10 +22,10 @@ module WikiExternalFilterHelper
|
||||||
module_function :load_config, :has_macro
|
module_function :load_config, :has_macro
|
||||||
|
|
||||||
def construct_cache_key(macro, name)
|
def construct_cache_key(macro, name)
|
||||||
['wiki_external_filter', macro, name].join("/")
|
['wiki_external_filter', macro, name].join("_")
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(text, attachments, macro, info)
|
def build(args, text, attachments, macro, info)
|
||||||
|
|
||||||
name = Digest::SHA256.hexdigest(text.to_s)
|
name = Digest::SHA256.hexdigest(text.to_s)
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -53,12 +53,12 @@ module WikiExternalFilterHelper
|
||||||
result[:content] = content
|
result[:content] = content
|
||||||
Rails.logger.debug "from cache: #{cache_key}"
|
Rails.logger.debug "from cache: #{cache_key}"
|
||||||
else
|
else
|
||||||
result = self.build_forced(text, attachments, info)
|
result = self.build_forced(args, text, attachments, info)
|
||||||
if result[:status]
|
if result[:status]
|
||||||
if expires > 0
|
if expires > 0
|
||||||
begin
|
begin
|
||||||
Rails.cache.write cache_key, result[:content], :expires_in => expires.seconds
|
Rails.cache.write cache_key, result[:content], :expires_in => expires.seconds
|
||||||
Rails.logger.debug "cache saved: #{cache_key} expires #{expires.seconds}"
|
Rails.logger.debug "cache saved: #{cache_key} expires #{expires.seconds}"
|
||||||
rescue
|
rescue
|
||||||
Rails.logger.error "Failed to save cache: #{cache_key}, result content #{result[:content]}, error: $!"
|
Rails.logger.error "Failed to save cache: #{cache_key}, result content #{result[:content]}, error: $!"
|
||||||
end
|
end
|
||||||
|
@ -78,11 +78,11 @@ module WikiExternalFilterHelper
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_forced(text, attachments, info)
|
def build_forced(args, text, attachments, info)
|
||||||
|
|
||||||
# joining splitted args
|
# joining splitted args
|
||||||
# not necessary from v2.1.0
|
# not necessary from v2.1.0
|
||||||
text = text.join(", ")
|
# text = text.join(", ")
|
||||||
|
|
||||||
if info['replace_attachments'] and attachments
|
if info['replace_attachments'] and attachments
|
||||||
attachments.each do |att|
|
attachments.each do |att|
|
||||||
|
@ -168,10 +168,10 @@ module WikiExternalFilterHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
class Macro
|
class Macro
|
||||||
def initialize(view, source, attachments, macro, info)
|
def initialize(view, args, source, attachments, macro, info)
|
||||||
@view = view
|
@view = view
|
||||||
@view.controller.extend(WikiExternalFilterHelper)
|
@view.controller.extend(WikiExternalFilterHelper)
|
||||||
@result = @view.controller.build(source, attachments, macro, info)
|
@result = @view.controller.build(args, source, attachments, macro, info)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render()
|
def render()
|
||||||
|
|
10
init.rb
10
init.rb
|
@ -21,22 +21,22 @@ Redmine::Plugin.register :wiki_external_filter do
|
||||||
Redmine::WikiFormatting::Macros.register do
|
Redmine::WikiFormatting::Macros.register do
|
||||||
info = config[name]
|
info = config[name]
|
||||||
desc info['description']
|
desc info['description']
|
||||||
macro name do |obj, args|
|
macro name do |obj, args, text|
|
||||||
m = WikiExternalFilterHelper::Macro.new(self, args, obj.respond_to?('page') ? obj.page.attachments : nil, name, info)
|
m = WikiExternalFilterHelper::Macro.new(self, args, text, obj.respond_to?('page') ? obj.page.attachments : nil, name, info)
|
||||||
m.render
|
m.render.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
# code borrowed from wiki latex plugin
|
# code borrowed from wiki latex plugin
|
||||||
# code borrowed from wiki template macro
|
# code borrowed from wiki template macro
|
||||||
desc info['description']
|
desc info['description']
|
||||||
macro (name + "_include").to_sym do |obj, args|
|
macro (name + "_include").to_sym do |obj, args, text|
|
||||||
page = Wiki.find_page(args.to_s, :project => @project)
|
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)
|
raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
||||||
|
|
||||||
@included_wiki_pages ||= []
|
@included_wiki_pages ||= []
|
||||||
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
|
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
|
||||||
@included_wiki_pages << page.title
|
@included_wiki_pages << page.title
|
||||||
m = WikiExternalFilterHelper::Macro.new(self, page.content.text, page.attachments, name, info)
|
m = WikiExternalFilterHelper::Macro.new(self, args, page.content.text, page.attachments, name, info)
|
||||||
@included_wiki_pages.pop
|
@included_wiki_pages.pop
|
||||||
m.render_block(args.to_s)
|
m.render_block(args.to_s)
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue