Sha256: 54f538e5f8c0eb2b1f5818f9b1a481a067f60cb5c0c7e47a441cfc8133f9f0bc

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module Asciidoctor
  module Standoc
    module Cleanup
      def requirement_cleanup(reqt)
        requirement_descriptions(reqt)
        requirement_inherit(reqt)
      end

      def requirement_inherit(reqt)
        reqt.xpath("//requirement | //recommendation | //permission")
          .each do |r|
          ins = r.at("./classification") ||
            r.at("./description | ./measurementtarget | ./specification | "\
                 "./verification | ./import | ./description | ./requirement | "\
                 "./recommendation | ./permission")
          r.xpath("./*//inherit").each { |i| ins.previous = i }
        end
      end

      def requirement_descriptions(reqt)
        reqt.xpath("//requirement | //recommendation | //permission")
          .each do |r|
          r.children.each do |e|
            unless e.element? && (reqt_subpart(e.name) ||
                %w(requirement recommendation permission).include?(e.name))
              t = Nokogiri::XML::Element.new("description", reqt)
              e.before(t)
              t.children = e.remove
            end
          end
          requirement_cleanup1(r)
        end
      end

      def requirement_cleanup1(reqt)
        while d = reqt.at("./description[following-sibling::*[1]"\
            "[self::description]]")
          n = d.next.remove
          d << n.children
        end
        reqt.xpath("./description[normalize-space(.)='']").each do |r|
          r.replace("\n")
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
metanorma-standoc-1.10.4 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.10.3.1 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.10.3 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.10.2 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.10.1 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.10.0 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.9.4 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.9.3 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.9.2 lib/asciidoctor/standoc/cleanup_reqt.rb
metanorma-standoc-1.9.1 lib/asciidoctor/standoc/cleanup_reqt.rb