Sha256: 58baf79ec7a1d47f0989eb8e05c053fd773565d8a918679f38b95749c3eacdaf

Contents?: true

Size: 632 Bytes

Versions: 26

Compression:

Stored size: 632 Bytes

Contents

module Wovnrb
  class TextReplacer < ReplacerBase
    def initialize(text_index)
      @text_index = text_index
    end

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

        node_text = node.content.strip
        # shouldn't need size check, but for now...
        if @text_index[node_text] && @text_index[node_text][lang.lang_code] && @text_index[node_text][lang.lang_code].size > 0
          add_comment_node(node, node_text)
          node.content = replace_text(node.content, @text_index[node_text][lang.lang_code][0]['data'])
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
wovnrb-1.0.6 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.5 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.4 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.2 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.1 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.0 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.30 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.29 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.28 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.27 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.26 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.25 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.24 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.23 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.22 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.21 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.20 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.19 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.18 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-0.2.17 lib/wovnrb/html_replacers/text_replacer.rb