Module: ActionText::ContentHelper

Included in:
Content
Defined in:
app/helpers/action_text/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_action_text_attachment(attachment, locals: {}) ⇒ Object

:nodoc:



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/action_text/content_helper.rb', line 54

def render_action_text_attachment(attachment, locals: {}) # :nodoc:
  options = { locals: locals, object: attachment, partial: attachment }

  if attachment.respond_to?(:to_attachable_partial_path)
    options[:partial] = attachment.to_attachable_partial_path
  end

  if attachment.respond_to?(:model_name)
    options[:as] = attachment.model_name.element
  end

  render(**options).chomp
end

#render_action_text_attachments(content) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/action_text/content_helper.rb', line 37

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_action_text_attachment attachment, locals: { in_gallery: false }
      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_action_text_attachment attachment, locals: { in_gallery: true }
        attachment.to_html
      end.join.html_safe
    end.chomp
  end
end

#render_action_text_content(content) ⇒ Object



14
15
16
17
# File 'app/helpers/action_text/content_helper.rb', line 14

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

#sanitize_action_text_content(content) ⇒ Object



28
29
30
31
32
33
34
35
# File 'app/helpers/action_text/content_helper.rb', line 28

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

#sanitize_content_attachment(content_attachment) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/action_text/content_helper.rb', line 19

def sanitize_content_attachment(content_attachment)
  sanitizer.sanitize(
    content_attachment,
    tags: sanitizer_allowed_tags,
    attributes: sanitizer_allowed_attributes,
    scrubber: scrubber,
  )
end

#sanitizer_allowed_attributesObject



72
73
74
# File 'app/helpers/action_text/content_helper.rb', line 72

def sanitizer_allowed_attributes
  allowed_attributes || (sanitizer.class.allowed_attributes + ActionText::Attachment::ATTRIBUTES)
end

#sanitizer_allowed_tagsObject



68
69
70
# File 'app/helpers/action_text/content_helper.rb', line 68

def sanitizer_allowed_tags
  allowed_tags || (sanitizer.class.allowed_tags + [ ActionText::Attachment.tag_name, "figure", "figcaption" ])
end