text = args.shift
when 2
obj = args.shift
- text = obj.send(args.shift).to_s
+ attr = args.shift
+ text = obj.send(attr).to_s
else
raise ArgumentError, 'invalid arguments to textilizable'
end
return '' if text.blank?
- text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
+ text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
only_path = options.delete(:only_path) == false ? false : true
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.format_names.collect{|name| [name, name.to_s]}, :blank => :label_none %></p>
+<p><%= setting_check_box :cache_formatted_text %></p>
+
<p><%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %></p>
<p><%= setting_text_field :feeds_limit, :size => 6 %></p>
# Enable page/fragment caching by setting a file-based store
# (remember to create the caching directory and make it readable to the application)
- # config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
+ # config.action_controller.cache_store = :file_store, "#{RAILS_ROOT}/tmp/cache"
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
setting_issue_done_ratio_issue_status: Use the issue status
setting_start_of_week: Start calendars on
setting_rest_api_enabled: Enable REST web service
+ setting_cache_formatted_text: Cache formatted text
permission_add_project: Create project
permission_add_subprojects: Create subprojects
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages\r
+ setting_cache_formatted_text: Cache formatted text\r
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
setting_rest_api_enabled: Activer l'API REST
setting_gravatar_default: Image Gravatar par défaut
setting_start_of_week: Jour de début des calendriers
+ setting_cache_formatted_text: Mettre en cache le texte formaté
permission_add_project: Créer un projet
permission_add_subprojects: Créer des sous-projets
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
enumeration_activities: 作業分類 (時間トラッキング)
enumeration_system_activity: システム作業分類
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_locked: Travado
label_change_log: Registro de alterações
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Прикреплена
label_board_locked: Заблокирована
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
enumeration_activities: Aktiviteter (tidsuppföljning)
enumeration_system_activity: Systemaktivitet
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
enumeration_activities: 活動 (時間追蹤)
enumeration_system_activity: 系統活動
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
label_board_sticky: Sticky
label_board_locked: Locked
permission_export_wiki_pages: Export wiki pages
+ setting_cache_formatted_text: Cache formatted text
default: 0
text_formatting:
default: textile
+cache_formatted_text:
+ default: 0
wiki_compression:
default: ""
default_language:
end
def to_html(format, text, options = {}, &block)
- formatter_for(format).new(text).to_html(&block)
+ text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache && cache_key = cache_key_for(format, 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.fetch cache_key do
+ formatter_for(format).new(text).to_html
+ end.dup
+ else
+ formatter_for(format).new(text).to_html
+ end
+ if block_given?
+ execute_macros(text, block)
+ end
+ text
+ 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)}"
+ end
+ end
+
+ # Returns the cache store used to cache HTML output
+ def cache
+ ActionController::Base.cache_store
+ end
+
+ MACROS_RE = /
+ (!)? # escaping
+ (
+ \{\{ # opening tag
+ ([\w]+) # macro name
+ (\(([^\}]*)\))? # optional arguments
+ \}\} # closing tag
+ )
+ /x unless const_defined?(:MACROS_RE)
+
+ # Macros substitution
+ def execute_macros(text, macros_runner)
+ text.gsub!(MACROS_RE) do
+ esc, all, macro = $1, $2, $3.downcase
+ args = ($5 || '').split(',').each(&:strip)
+ if esc.nil?
+ begin
+ macros_runner.call(macro, args)
+ rescue => e
+ "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
+ end || all
+ else
+ all
+ end
+ end
end
end
class Formatter < RedCloth3
# auto_link rule after textile rules so that it doesn't break !image_url! tags
- RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto, :inline_toc, :inline_macros]
+ RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto, :inline_toc]
def initialize(*args)
super
self.filter_styles=true
end
- def to_html(*rules, &block)
+ def to_html(*rules)
@toc = []
- @macros_runner = block
super(*RULES).to_s
end
end
end
- MACROS_RE = /
- (!)? # escaping
- (
- \{\{ # opening tag
- ([\w]+) # macro name
- (\(([^\}]*)\))? # optional arguments
- \}\} # closing tag
- )
- /x unless const_defined?(:MACROS_RE)
-
- def inline_macros(text)
- text.gsub!(MACROS_RE) do
- esc, all, macro = $1, $2, $3.downcase
- args = ($5 || '').split(',').each(&:strip)
- if esc.nil?
- begin
- @macros_runner.call(macro, args)
- rescue => e
- "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
- end || all
- else
- all
- end
- end
- end
-
AUTO_LINK_RE = %r{
( # leading text
<\w+.*?>| # leading HTML tag, or