Sha256: cc5f5f708c451683490098adfa92827584aa4cd709959cc9c2169c39dbc7de72

Contents?: true

Size: 658 Bytes

Versions: 5

Compression:

Stored size: 658 Bytes

Contents

module Wovnrb
  class TextReplacer < ReplacerBase
    def initialize(store, text_index)
      super(store)
      @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

5 entries across 5 versions & 1 rubygems

Version Path
wovnrb-1.0.11 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.10 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.9 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.8 lib/wovnrb/html_replacers/text_replacer.rb
wovnrb-1.0.7 lib/wovnrb/html_replacers/text_replacer.rb