* macro arguments are no longer parsed by text formatters * macro output is escaped unless it's html safe git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10209 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'digest/md5'
|
||||
|
||||
module Redmine
|
||||
module WikiFormatting
|
||||
class StaleSectionError < Exception; end
|
||||
@@ -50,7 +52,7 @@ module Redmine
|
||||
end
|
||||
|
||||
def to_html(format, text, options = {})
|
||||
text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, options[:object], options[:attribute])
|
||||
text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, text, options[:object], options[:attribute])
|
||||
# Text retrieved from the cache store may be frozen
|
||||
# We need to dup it so we can do in-place substitutions with gsub!
|
||||
cache_store.fetch cache_key do
|
||||
@@ -67,10 +69,10 @@ module Redmine
|
||||
(formatter.instance_methods & ['update_section', :update_section]).any?
|
||||
end
|
||||
|
||||
# Returns a cache key for the given text +format+, +object+ and +attribute+ or nil if no caching should be done
|
||||
def cache_key_for(format, object, attribute)
|
||||
if object && attribute && !object.new_record? && object.respond_to?(:updated_on) && !format.blank?
|
||||
"formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{object.updated_on.to_s(:number)}"
|
||||
# Returns a cache key for the given text +format+, +text+, +object+ and +attribute+ or nil if no caching should be done
|
||||
def cache_key_for(format, text, object, attribute)
|
||||
if object && attribute && !object.new_record? && format.present?
|
||||
"formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{Digest::MD5.hexdigest text}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ module Redmine
|
||||
module WikiFormatting
|
||||
module Macros
|
||||
module Definitions
|
||||
# Returns true if +name+ is the name of an existing macro
|
||||
def macro_exists?(name)
|
||||
Redmine::WikiFormatting::Macros.available_macros.key?(name.to_sym)
|
||||
end
|
||||
|
||||
def exec_macro(name, obj, args)
|
||||
macro_options = Redmine::WikiFormatting::Macros.available_macros[name.to_sym]
|
||||
return unless macro_options
|
||||
@@ -27,7 +32,12 @@ module Redmine
|
||||
unless macro_options[:parse_args] == false
|
||||
args = args.split(',').map(&:strip)
|
||||
end
|
||||
send(method_name, obj, args) if respond_to?(method_name)
|
||||
|
||||
begin
|
||||
send(method_name, obj, args) if respond_to?(method_name)
|
||||
rescue => e
|
||||
"<div class=\"flash error\">Error executing the <strong>#{h name}</strong> macro (#{h e.to_s})</div>".html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def extract_macro_options(args, *keys)
|
||||
@@ -97,7 +107,7 @@ module Redmine
|
||||
# Builtin macros
|
||||
desc "Sample macro."
|
||||
macro :hello_world do |obj, args|
|
||||
"Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")
|
||||
h("Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}"))
|
||||
end
|
||||
|
||||
desc "Displays a list of all available macros, including description if available."
|
||||
|
||||
Reference in New Issue
Block a user