Module: Redmine::WikiFormatting
- Defined in:
- lib/redmine/wiki_formatting.rb,
lib/redmine/wiki_formatting/textile/helper.rb,
lib/redmine/wiki_formatting/textile/formatter.rb,
lib/redmine/wiki_formatting/textile/html_parser.rb,
lib/redmine/wiki_formatting/markdown/helper.rb,
lib/redmine/wiki_formatting/markdown/formatter.rb,
lib/redmine/wiki_formatting/markdown/html_parser.rb,
lib/redmine/wiki_formatting/macros.rb,
lib/redmine/wiki_formatting/html_parser.rb
Defined Under Namespace
Modules: LinksHelper, Macros, Markdown, NullFormatter, Textile
Classes: HtmlParser, StaleSectionError
Constant Summary
- @@formatters =
{}
Class Method Summary
collapse
Class Method Details
.cache_key_for(format, text, object, attribute) ⇒ Object
Returns a cache key for the given text format
,
text
, object
and attribute
or nil if
no caching should be done
100
101
102
103
104
|
# File 'lib/redmine/wiki_formatting.rb', line 100
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
|
.cache_store ⇒ Object
Returns the cache store used to cache HTML output
107
108
109
|
# File 'lib/redmine/wiki_formatting.rb', line 107
def cache_store
ActionController::Base.cache_store
end
|
73
74
75
|
# File 'lib/redmine/wiki_formatting.rb', line 73
def format_names
@@formatters.keys.map
end
|
77
78
79
|
# File 'lib/redmine/wiki_formatting.rb', line 77
def formats_for_select
@@formatters.map {|name, options| [options[:label], name]}
end
|
50
51
52
|
# File 'lib/redmine/wiki_formatting.rb', line 50
def formatter
formatter_for(Setting.text_formatting)
end
|
58
59
60
61
|
# File 'lib/redmine/wiki_formatting.rb', line 58
def formatter_for(name)
entry = @@formatters[name.to_s]
(entry && entry[:formatter]) || Redmine::WikiFormatting::NullFormatter::Formatter
end
|
.helper_for(name) ⇒ Object
63
64
65
66
|
# File 'lib/redmine/wiki_formatting.rb', line 63
def helper_for(name)
entry = @@formatters[name.to_s]
(entry && entry[:helper]) || Redmine::WikiFormatting::NullFormatter::Helper
end
|
.html_parser ⇒ Object
54
55
56
|
# File 'lib/redmine/wiki_formatting.rb', line 54
def html_parser
html_parser_for(Setting.text_formatting)
end
|
.html_parser_for(name) ⇒ Object
68
69
70
71
|
# File 'lib/redmine/wiki_formatting.rb', line 68
def html_parser_for(name)
entry = @@formatters[name.to_s]
(entry && entry[:html_parser]) || Redmine::WikiFormatting::HtmlParser
end
|
.map {|_self| ... } ⇒ Object
27
28
29
|
# File 'lib/redmine/wiki_formatting.rb', line 27
def map
yield self
end
|
.register(name, *args) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/redmine/wiki_formatting.rb', line 31
def register(name, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = name.to_s
raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name]
formatter, helper, parser = args.any? ?
args :
%w(Formatter Helper HtmlParser).map {|m| "Redmine::WikiFormatting::#{name.classify}::#{m}".constantize rescue nil}
raise "A formatter class is required" if formatter.nil?
@@formatters[name] = {
:formatter => formatter,
:helper => helper,
:html_parser => parser,
:label => options[:label] || name.humanize
}
end
|
.supports_section_edit? ⇒ Boolean
Returns true if the text formatter supports single section edit
95
96
97
|
# File 'lib/redmine/wiki_formatting.rb', line 95
def supports_section_edit?
(formatter.instance_methods & ['update_section', :update_section]).any?
end
|
.to_html(format, text, options = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/redmine/wiki_formatting.rb', line 81
def to_html(format, text, options = {})
text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, text, options[:object], options[:attribute])
cache_store.fetch cache_key do
formatter_for(format).new(text).to_html
end.dup
else
formatter_for(format).new(text).to_html
end
text
end
|