Sha256: 636aba0ea0c7b48440f229fb8a5239df95c05f7ad95e10ce2fb8beadb6d8c3d4

Contents?: true

Size: 951 Bytes

Versions: 21

Compression:

Stored size: 951 Bytes

Contents

module Wovnrb
  class ReplacerBase
    def replace(dom, lang)
      raise NotImplementedError.new('replace is not defined')
    end

    protected
    def wovn_ignore?(node)
      if !node.get_attribute('wovn-ignore').nil?
        return true
      elsif node.name === 'html'
        return false
      end
      wovn_ignore?(node.parent)
    end

    # Add comment-node node to remember original src
    # <title> may not contain other markup, so add comment-node to node's previous
    # @see https://www.w3.org/TR/html401/struct/global.html#h-7.4.2
    def add_comment_node(node, text)
      comment_node = Nokogiri::XML::Comment.new(node.document, "wovn-src:#{text}")
      if node.parent.name == 'title'
        node.parent.add_previous_sibling(comment_node)
      else
        node.add_previous_sibling(comment_node)
      end
    end

    def replace_text(from, to)
      from.gsub(/\A(\s*)[\S\s]*?(\s*)\Z/, '\1' + to + '\2')
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

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