Module: Redmine::WikiFormatting
- Defined in:
- lib/redmine/wiki_formatting.rb,
lib/redmine/wiki_formatting/macros.rb,
lib/redmine/wiki_formatting/textile/helper.rb,
lib/redmine/wiki_formatting/textile/formatter.rb
Defined Under Namespace
Modules: Macros, NullFormatter, Textile
Constant Summary
- MACROS_RE =
/ (!)? # escaping ( \{\{ # opening tag ([\w]+) # macro name (\(([^\}]*)\))? # optional arguments \}\} # closing tag ) /x unless const_defined?(:MACROS_RE)
- @@formatters =
{}
Class Method Summary
-
+ (Object) cache_key_for(format, object, attribute)
Returns a cache key for the given text format, object and attribute or nil if no caching should be done.
-
+ (Object) cache_store
Returns the cache store used to cache HTML output.
-
+ (Object) execute_macros(text, macros_runner)
Macros substitution.
- + (Object) format_names
- + (Object) formatter_for(name)
- + (Object) helper_for(name)
- + (Object) map {|_self| ... }
- + (Object) register(name, formatter, helper)
- + (Object) to_html(format, text, options = {}, &block)
Class Method Details
+ (Object) cache_key_for(format, object, attribute)
Returns a cache key for the given text format, object and attribute or nil if no caching should be done
63 64 65 66 67 |
# File 'lib/redmine/wiki_formatting.rb', line 63 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 |
+ (Object) cache_store
Returns the cache store used to cache HTML output
70 71 72 |
# File 'lib/redmine/wiki_formatting.rb', line 70 def cache_store ActionController::Base.cache_store end |
+ (Object) execute_macros(text, macros_runner)
Macros substitution
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/redmine/wiki_formatting.rb', line 85 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 |
+ (Object) format_names
42 43 44 |
# File 'lib/redmine/wiki_formatting.rb', line 42 def format_names @@formatters.keys.map end |
+ (Object) formatter_for(name)
32 33 34 35 |
# File 'lib/redmine/wiki_formatting.rb', line 32 def formatter_for(name) entry = @@formatters[name.to_s] (entry && entry[:formatter]) || Redmine::WikiFormatting::NullFormatter::Formatter end |
+ (Object) helper_for(name)
37 38 39 40 |
# File 'lib/redmine/wiki_formatting.rb', line 37 def helper_for(name) entry = @@formatters[name.to_s] (entry && entry[:helper]) || Redmine::WikiFormatting::NullFormatter::Helper end |
+ (Object) map {|_self| ... }
23 24 25 |
# File 'lib/redmine/wiki_formatting.rb', line 23 def map yield self end |
+ (Object) register(name, formatter, helper)
27 28 29 30 |
# File 'lib/redmine/wiki_formatting.rb', line 27 def register(name, formatter, helper) raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name.to_s] @@formatters[name.to_s] = {:formatter => formatter, :helper => helper} end |
+ (Object) to_html(format, text, options = {}, &block)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/redmine/wiki_formatting.rb', line 46 def to_html(format, text, = {}, &block) text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, [:object], [: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 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 |