Sha256: 4b19e9bd1d809ab938a148173684a27d489c8bac0c0df4d27cbcab627710dd61

Contents?: true

Size: 515 Bytes

Versions: 10

Compression:

Stored size: 515 Bytes

Contents

module Wovnrb
  class LinkReplacer < ReplacerBase
    def initialize(pattern, headers)
      @pattern = pattern
      @headers = headers
    end

    def replace(dom, lang)
      dom.xpath('//a').each do |node|
        next if wovn_ignore?(node)

        href = node.get_attribute('href')
        next if href =~ /^\s*\{\{.+\}\}\s*$/
        next if href =~ /javascript:void\(/
        new_href = lang.add_lang_code(href, @pattern, @headers)
        node.set_attribute('href', new_href)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
wovnrb-0.2.23 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.22 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.21 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.20 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.19 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.18 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.17 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.16 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.15 lib/wovnrb/html_replacers/link_replacer.rb
wovnrb-0.2.14 lib/wovnrb/html_replacers/link_replacer.rb