Sha256: a37990870cbfeadc07b389c546c7913072cac6c4f30594fa9553e6ff8f30d35d

Contents?: true

Size: 1.48 KB

Versions: 37

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require "rails-html-sanitizer"

module ActionText
  module ContentHelper
    mattr_accessor(:sanitizer) { Rails::Html::Sanitizer.safe_list_sanitizer.new }
    mattr_accessor(:allowed_tags) { sanitizer.class.allowed_tags + [ ActionText::Attachment::TAG_NAME, "figure", "figcaption" ] }
    mattr_accessor(:allowed_attributes) { sanitizer.class.allowed_attributes + ActionText::Attachment::ATTRIBUTES }
    mattr_accessor(:scrubber)

    def render_action_text_content(content)
      self.prefix_partial_path_with_controller_namespace = false
      sanitize_action_text_content(render_action_text_attachments(content))
    end

    def sanitize_action_text_content(content)
      sanitizer.sanitize(content.to_html, tags: allowed_tags, attributes: allowed_attributes, scrubber: scrubber).html_safe
    end

    def render_action_text_attachments(content)
      content.render_attachments do |attachment|
        unless attachment.in?(content.gallery_attachments)
          attachment.node.tap do |node|
            node.inner_html = render(attachment, in_gallery: false).chomp
          end
        end
      end.render_attachment_galleries do |attachment_gallery|
        render(layout: attachment_gallery, object: attachment_gallery) do
          attachment_gallery.attachments.map do |attachment|
            attachment.node.inner_html = render(attachment, in_gallery: true).chomp
            attachment.to_html
          end.join.html_safe
        end.chomp
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
actiontext-6.1.7.10 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.9 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.8 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.7 app/helpers/action_text/content_helper.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-6.1.6.1/app/helpers/action_text/content_helper.rb
actiontext-6.1.7.6 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.5 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.4 app/helpers/action_text/content_helper.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actiontext-6.1.6.1/app/helpers/action_text/content_helper.rb
actiontext-6.1.7.3 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.2 app/helpers/action_text/content_helper.rb
actiontext-6.1.7.1 app/helpers/action_text/content_helper.rb
actiontext-6.1.7 app/helpers/action_text/content_helper.rb
actiontext-6.1.6.1 app/helpers/action_text/content_helper.rb
actiontext-6.1.6 app/helpers/action_text/content_helper.rb
actiontext-6.1.5.1 app/helpers/action_text/content_helper.rb
actiontext-6.1.5 app/helpers/action_text/content_helper.rb
actiontext-6.1.4.7 app/helpers/action_text/content_helper.rb
actiontext-6.1.4.6 app/helpers/action_text/content_helper.rb
actiontext-6.1.4.5 app/helpers/action_text/content_helper.rb