Class: Thredded::ContentFormatter
- Inherits:
-
Object
- Object
- Thredded::ContentFormatter
- Defined in:
- lib/thredded/content_formatter.rb
Overview
Generates HTML from content source.
Class Method Summary collapse
-
.pipeline_filters ⇒ Object
All the HTML::Pipeline filters, read-only.
-
.quote_content(content) ⇒ String
A quote containing the formatted content.
Instance Method Summary collapse
-
#format_content(content) ⇒ String
Formatted and sanitized html-safe content.
-
#initialize(view_context, pipeline_options = {}) ⇒ ContentFormatter
constructor
A new instance of ContentFormatter.
Constructor Details
#initialize(view_context, pipeline_options = {}) ⇒ ContentFormatter
Returns a new instance of ContentFormatter.
88 89 90 91 |
# File 'lib/thredded/content_formatter.rb', line 88 def initialize(view_context, = {}) @view_context = view_context @pipeline_options = end |
Class Method Details
.pipeline_filters ⇒ Object
All the HTML::Pipeline filters, read-only.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/thredded/content_formatter.rb', line 72 def self.pipeline_filters filters = [ *before_markup_filters, *markup_filters, *after_markup_filters, *sanitization_filters, *after_sanitization_filters ] # Changing the result in-place has no effect on the ContentFormatter output, # and is most likely the result of a programmer error. # Freeze the array so that in-place changes raise an error. filters.freeze end |
.quote_content(content) ⇒ String
Returns a quote containing the formatted content.
105 106 107 108 109 110 111 112 |
# File 'lib/thredded/content_formatter.rb', line 105 def self.quote_content(content) result = String.new(content) result.gsub!(/^(?!$)/, '> ') result.gsub!(/^$/, '>') result << "\n" unless result.end_with?("\n") result << "\n" result end |
Instance Method Details
#format_content(content) ⇒ String
Returns formatted and sanitized html-safe content.
95 96 97 98 99 100 101 |
# File 'lib/thredded/content_formatter.rb', line 95 def format_content(content) pipeline = HTML::Pipeline.new(content_pipeline_filters, .deep_merge(@pipeline_options)) result = pipeline.call(content, view_context: @view_context) # rubocop:disable Rails/OutputSafety result[:output].to_s.html_safe # rubocop:enable Rails/OutputSafety end |