Module: SnapshotInspector::SnapshotsHelper

Defined in:
app/helpers/snapshot_inspector/snapshots_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.snapshot_path(snapshot, enable_javascript:) ⇒ Object



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

def self.snapshot_path(snapshot, enable_javascript:)
  case snapshot.type
  when "mail"
    SnapshotInspector::Engine.routes.url_helpers.mail_snapshot_path(slug: snapshot.slug)
  when "response"
    SnapshotInspector::Engine.routes.url_helpers.response_snapshot_path(slug: snapshot.slug, enable_javascript: enable_javascript)
  end
end

Instance Method Details

#prepare_for_render(body, enable_javascript:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/snapshot_inspector/snapshots_helper.rb', line 3

def prepare_for_render(body, enable_javascript:)
  prepared =
    if enable_javascript == "true"
      body
    else
      remove_traces_of_javascript(body)
    end

  prepared.html_safe
end

#remove_traces_of_javascript(html) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/snapshot_inspector/snapshots_helper.rb', line 14

def remove_traces_of_javascript(html)
  doc = Nokogiri.HTML(html)

  doc.css("script").each do |element|
    element.replace("")
  end

  doc.css('link[href$=".js"]').each do |element|
    element.replace("")
  end

  doc.to_html
end