Sha256: fa0f74c9ce1538083cdac293221983a9083cd5d3209611935322b635798b05ac

Contents?: true

Size: 1.78 KB

Versions: 21

Compression:

Stored size: 1.78 KB

Contents

require "metanorma-generic"

module IsoDoc
  module Ribose
    class Counter < IsoDoc::XrefGen::Counter
    end

    class Xref < IsoDoc::Generic::Xref
      def annex_name_lbl(clause, num)
        obl = l10n("(#{@labels['inform_annex']})")
        clause["obligation"] == "normative" and
          obl = l10n("(#{@labels['norm_annex']})")
        l10n("#{@labels['annex']} #{num}<br/>#{obl}")
      end

      def initial_anchor_names(doc)
        super
        if blank?(@parse_settings) || @parse_settings[:clauses]
          introduction_names(doc.at(ns("//introduction")))
        end
        if blank?(@parse_settings)
          sequential_asset_names(
            doc.xpath(
              ns("//preface/abstract | //foreword | //introduction | " \
                 "//preface/clause | //acknowledgements | //executivesummary"),
            ),
          )
        end
      end

      def section_names1(clause, num, level)
        @anchors[clause["id"]] =
          { label: num, level: level, xref: num }
        # subclauses are not prefixed with "Clause"
        i = Counter.new(0, prefix: "#{num}.")
        clause.xpath(ns("./clause | ./terms | ./term | ./definitions | " \
                        "./references")).each do |c|
          section_names1(c, i.increment(c).print, level + 1)
        end
      end

      # we can reference 0-number clauses in introduction
      def introduction_names(clause)
        clause.nil? and return
        clause.at(ns("./clause")) and
          @anchors[clause["id"]] = { label: "0", level: 1, type: "clause",
                                     xref: clause.at(ns("./title"))&.text }
        i = Counter.new(0, prefix: "0.")
        clause.xpath(ns("./clause")).each do |c|
          section_names1(c, i.increment(c).print, 2)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
metanorma-ribose-2.5.4 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.5.3 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.5.2 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.5.1 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.5.0 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.12 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.11 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.10 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.9 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.8 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.7 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.6 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.5 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.4 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.3 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.2 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.1 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.4.0 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.3.6 lib/isodoc/ribose/xref.rb
metanorma-ribose-2.3.4 lib/isodoc/ribose/xref.rb