Class: Chaskiq::LinkRenamer

Inherits:
Object
  • Object
show all
Defined in:
lib/chaskiq/link_renamer.rb

Class Method Summary collapse

Class Method Details

.convert(html, url_prefix = "") ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/chaskiq/link_renamer.rb', line 6

def self.convert(html, url_prefix="")
  content = Nokogiri::HTML(html)
  content.css("a").each do |link|
    next if link.attr("class").present? && link.attr("class").include?("tpl-block")
    val = link.attributes["href"].value
    link.attributes["href"].value = self.rename_link(val, url_prefix)
  end

  #content.css("div").each do |node|
  #  if node.content !~ /\A\s*\Z/
  #    node.replace(content.create_element('p', node.inner_html.html_safe))
  #  end
  #end

  content.css('div.mojoMcContainerEmptyMessage').remove

  #make sure nokogiri does not rips off my mustaches
  content.to_html.gsub("%7B%7B", "{{").gsub("%7D%7D", "}}")
end


26
27
28
# File 'lib/chaskiq/link_renamer.rb', line 26

def self.rename_link(value, url_prefix)
  "#{url_prefix}" + value
end