Class: Banzai::Filter::RedactorFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/redactor_filter.rb

Overview

HTML filter that removes references to records that the current user does not have permission to view.

Expected to be run in its own post-processing pipeline.

Instance Method Summary collapse

Instance Method Details

#callObject


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/banzai/filter/redactor_filter.rb', line 9

def call
  Querying.css(doc, 'a.gfm').each do |node|
    unless user_can_see_reference?(node)
      # The reference should be replaced by the original text,
      # which is not always the same as the rendered text.
      text = node.attr('data-original') || node.text
      node.replace(text)
    end
  end

  doc
end