Sha256: b6b85de651bafb0af8b99a50c79ad1d89bf8afb5a149d9b9320c856bb10ddea0

Contents?: true

Size: 1.75 KB

Versions: 24

Compression:

Stored size: 1.75 KB

Contents

module Metanorma
  module Standoc
    module Cleanup
      def change_clauses(docxml)
        docxml.xpath("//clause[@change]").each do |c|
          create_amend(c)
        end
      end

      def create_amend(clause)
        a = clause.add_child("<amend id='_#{UUIDTools::UUID.random_create}'/>")
          .first
        clause.elements.each do |e|
          e.parent = a unless %w(amend title).include? e.name
        end
        create_amend1(clause, a)
      end

      def create_amend1(clause, amend)
        create_amend2(clause, amend)
        d = amend.at("./description")
        d.xpath(".//autonumber").each { |e| d.previous = e }
        d.xpath(".//p[normalize-space(.)='']").each(&:remove)
        move_attrs_to_amend(clause, amend)
        amend
      end

      def create_amend2(_clause, amend)
        q = amend.at("./quote") and q.name = "newcontent"
        if q.nil?
          amend.children = "<description>#{amend.children.to_xml}</description>"
          return
        end
        pre = q&.xpath("./preceding-sibling::*")&.remove
        post = q&.xpath("./following-sibling::*")&.remove
        pre.empty? or amend << "<description>#{pre.to_xml}</description>"
        amend << q.remove
        post.empty? or amend << "<description>#{post.to_xml}</description>"
      end

      def move_attrs_to_amend(clause, amend)
        %w(change path path_end title).each do |e|
          next unless clause[e]

          amend[e] = clause[e]
          clause.delete(e)
        end
        return unless amend["locality"]

        loc = amend.children.add_previous_sibling("<location/>")
        extract_localities1(loc, amend["locality"])
        loc1 = loc.at("./localityStack") and loc.replace(loc1.elements)
        amend.delete("locality")
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
metanorma-standoc-2.2.6 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.5 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.4 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.3.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.3 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.2.2 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.2.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.2 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.1.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.0.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.2.0 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.5 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.4 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.3 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.2 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.1 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.1.0 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.0.7 lib/metanorma/standoc/cleanup_amend.rb
metanorma-standoc-2.0.6 lib/metanorma/standoc/cleanup_amend.rb