Class: TextFilter
- Inherits:
-
Object
- Object
- TextFilter
- Defined in:
- app/models/text_filter.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#markup ⇒ Object
Returns the value of attribute markup.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
- .all ⇒ Object
- .find_or_default(name) ⇒ Object
- .make_filter(name) ⇒ Object
- .markdown ⇒ Object
- .markdown_smartypants ⇒ Object
- .none ⇒ Object
- .smartypants ⇒ Object
Instance Method Summary collapse
- #commenthelp ⇒ Object
- #filter_text(text) ⇒ Object
- #help ⇒ Object
-
#initialize(name: nil, description: nil, markup: nil, filters: [], params: nil) ⇒ TextFilter
constructor
A new instance of TextFilter.
- #sanitize ⇒ Object
Constructor Details
#initialize(name: nil, description: nil, markup: nil, filters: [], params: nil) ⇒ TextFilter
Returns a new instance of TextFilter.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/text_filter.rb', line 8 def initialize(name: nil, description: nil, markup: nil, filters: [], params: nil) @name = name @description = description @markup = markup @filters = filters @params = params end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'app/models/text_filter.rb', line 6 def description @description end |
#filters ⇒ Object
Returns the value of attribute filters.
6 7 8 |
# File 'app/models/text_filter.rb', line 6 def filters @filters end |
#markup ⇒ Object
Returns the value of attribute markup.
6 7 8 |
# File 'app/models/text_filter.rb', line 6 def markup @markup end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'app/models/text_filter.rb', line 6 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'app/models/text_filter.rb', line 6 def params @params end |
Class Method Details
.all ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/models/text_filter.rb', line 63 def self.all [ markdown, smartypants, markdown_smartypants, none ] end |
.find_or_default(name) ⇒ Object
24 25 26 |
# File 'app/models/text_filter.rb', line 24 def self.find_or_default(name) make_filter(name) || none end |
.make_filter(name) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/text_filter.rb', line 72 def self.make_filter(name) case name when "markdown" markdown when "smartypants" smartypants when "markdown smartypants" markdown_smartypants when "none" none end end |
.markdown ⇒ Object
85 86 87 88 89 |
# File 'app/models/text_filter.rb', line 85 def self.markdown new(name: "markdown", description: "Markdown", markup: "markdown") end |
.markdown_smartypants ⇒ Object
98 99 100 101 102 |
# File 'app/models/text_filter.rb', line 98 def self.markdown_smartypants new(name: "markdown smartypants", description: "Markdown with smart quotes", markup: "markdownsmartquotes") end |
.none ⇒ Object
104 105 106 107 108 |
# File 'app/models/text_filter.rb', line 104 def self.none new(name: "none", description: "None", markup: "none") end |
.smartypants ⇒ Object
91 92 93 94 95 96 |
# File 'app/models/text_filter.rb', line 91 def self.smartypants new(name: "smartypants", description: "SmartyPants", markup: "none", filters: [:smartypants]) end |
Instance Method Details
#commenthelp ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/text_filter.rb', line 54 def commenthelp help_filters = TextFilterPlugin .([markup, filters].flatten) help_filters.map do |f| f.help_text.blank? ? "" : CommonMarker.render_html(f.help_text) end.join("\n") end |
#filter_text(text) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/text_filter.rb', line 28 def filter_text(text) all_filters = TextFilterPlugin .([:macropre, markup, :macropost, filters].flatten) all_filters.each do |filter| text = filter.filtertext(text) end text end |
#help ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/text_filter.rb', line 39 def help help_filters = TextFilterPlugin .([markup, :macropre, :macropost, filters].flatten) help_text = help_filters.map do |f| if f.help_text.blank? "" else "<h3>#{f.display_name}</h3>\n#{CommonMarker.render_html(f.help_text, :DEFAULT)}" end end help_text.join("\n") end |
#sanitize ⇒ Object
20 21 22 |
# File 'app/models/text_filter.rb', line 20 def sanitize(...) self.class.sanitize(...) end |