Module: Redmine::WikiFormatting
- Defined in:
- lib/redmine/wiki_formatting.rb,
lib/redmine/wiki_formatting/macros.rb,
lib/redmine/wiki_formatting/html_parser.rb,
lib/redmine/wiki_formatting/links_helper.rb,
lib/redmine/wiki_formatting/html_sanitizer.rb,
lib/redmine/wiki_formatting/section_helper.rb,
lib/redmine/wiki_formatting/textile/helper.rb,
lib/redmine/wiki_formatting/textile/formatter.rb,
lib/redmine/wiki_formatting/common_mark/helper.rb,
lib/redmine/wiki_formatting/textile/html_parser.rb,
lib/redmine/wiki_formatting/common_mark/formatter.rb,
lib/redmine/wiki_formatting/common_mark/html_parser.rb,
lib/redmine/wiki_formatting/common_mark/markdown_filter.rb,
lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb,
lib/redmine/wiki_formatting/common_mark/external_links_filter.rb,
lib/redmine/wiki_formatting/common_mark/append_spaces_to_lines.rb,
lib/redmine/wiki_formatting/common_mark/fixup_auto_links_filter.rb,
lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter.rb
Defined Under Namespace
Modules: CommonMark, LinksHelper, Macros, NullFormatter, SectionHelper, Textile
Classes: HtmlParser, HtmlSanitizer, StaleSectionError
Constant Summary
collapse
- @@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
110
111
112
113
114
|
# File 'lib/redmine/wiki_formatting.rb', line 110
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}-#{ActiveSupport::Digest.hexdigest text}"
end
end
|
.cache_store ⇒ Object
Returns the cache store used to cache HTML output
117
118
119
|
# File 'lib/redmine/wiki_formatting.rb', line 117
def cache_store
ActionController::Base.cache_store
end
|
81
82
83
|
# File 'lib/redmine/wiki_formatting.rb', line 81
def format_names
@@formatters.keys.map
end
|
85
86
87
|
# File 'lib/redmine/wiki_formatting.rb', line 85
def formats_for_select
@@formatters.map {|name, options| [options[:label], name]}
end
|
58
59
60
|
# File 'lib/redmine/wiki_formatting.rb', line 58
def formatter
formatter_for(Setting.text_formatting)
end
|
.helper_for(name) ⇒ Object
.html_parser ⇒ Object
62
63
64
|
# File 'lib/redmine/wiki_formatting.rb', line 62
def html_parser
html_parser_for(Setting.text_formatting)
end
|
.html_parser_for(name) ⇒ Object
76
77
78
79
|
# File 'lib/redmine/wiki_formatting.rb', line 76
def html_parser_for(name)
entry = @@formatters[name.to_s]
(entry && entry[:html_parser]) || Redmine::WikiFormatting::HtmlParser
end
|
.map {|_self| ... } ⇒ Object
29
30
31
|
# File 'lib/redmine/wiki_formatting.rb', line 29
def map
yield self
end
|
.register(name, *args) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/redmine/wiki_formatting.rb', line 33
def register(name, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = name.to_s
formatter, helper, parser =
if args.any?
args
else
%w(Formatter Helper HtmlParser).map {|m| "Redmine::WikiFormatting::#{name.classify}::#{m}".constantize rescue nil}
end
raise "A formatter class is required" if formatter.nil?
entry = {
:formatter => formatter,
:helper => helper,
:html_parser => parser,
:label => options[:label] || name.humanize
}
if @@formatters[name] && @@formatters[name] != entry
raise ArgumentError, "format name '#{name}' is already taken"
end
@@formatters[name] = entry
end
|
.supports_section_edit? ⇒ Boolean
Returns true if the text formatter supports single section edit
105
106
107
|
# File 'lib/redmine/wiki_formatting.rb', line 105
def supports_section_edit?
formatter.instance_methods.intersect?(['update_section', :update_section])
end
|
.to_html(format, text, options = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/redmine/wiki_formatting.rb', line 89
def to_html(format, text, options = {})
text =
if Setting.cache_formatted_text? && text.size > 2.kilobytes && 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
|