Class: Thredded::ContentFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/thredded/content_formatter.rb

Overview

Generates HTML from content source.

Instance Method Summary collapse

Constructor Details

#initialize(view_context, pipeline_options = {}) ⇒ ContentFormatter

Returns a new instance of ContentFormatter.

Parameters:

  • view_context (Object)

    the context of the rendering view.

  • pipeline_options (Hash) (defaults to: {})


57
58
59
60
# File 'lib/thredded/content_formatter.rb', line 57

def initialize(view_context, pipeline_options = {})
  @view_context = view_context
  @pipeline_options = pipeline_options
end

Instance Method Details

#format_content(content) ⇒ String

Returns formatted and sanitized html-safe content.

Parameters:

  • content (String)

Returns:

  • (String)

    formatted and sanitized html-safe content.



64
65
66
67
68
69
70
# File 'lib/thredded/content_formatter.rb', line 64

def format_content(content)
  pipeline = HTML::Pipeline.new(content_pipeline_filters, content_pipeline_options.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