Sha256: 8abbdd11e545a450f03d65aafaf4faab8bc7a85accb99cb12ffb74d81cafcd53

Contents?: true

Size: 1.95 KB

Versions: 18

Compression:

Stored size: 1.95 KB

Contents

require_relative "xref/xref_anchor"
require_relative "xref/xref_counter"
require_relative "xref/xref_gen_seq"
require_relative "xref/xref_gen"
require_relative "xref/xref_sect_gen"
require_relative "class_utils"
require_relative "function/utils"

module IsoDoc
  class Xref
    include XrefGen::Anchor
    include XrefGen::Blocks
    include XrefGen::Sections
    include Function::Utils

    attr_reader :klass

    def initialize(lang, script, klass, i18n, options = {})
      @anchors = {}
      @lang = lang
      @script = script
      @klass = klass
      @options = options
      @i18n = i18n
      @labels = @i18n.get
      @klass.i18n = @i18n
      @locale = options[:locale]
      @reqt_models = @klass.requirements_processor
        .new({
               default: "default", lang: lang, script: script,
               labels: @i18n.get
             })
      @i18n
      @parse_settings = {}
    end

    def get
      @anchors
    end

    # parse only the elements set, if any are set
    # defined are: clause: true, refs: true
    def parse_inclusions(options)
      @parse_settings.merge!(options)
      self
    end

    def anchor(ident, lbl, warning = true)
      return nil if ident.nil? || ident.empty?

      if warning && !@anchors[ident]
        @seen.seen(ident) or warn "No label has been processed for ID #{ident}"
        @seen.add(ident)
        return "[#{ident}]"
      end
      @anchors.dig(ident, lbl)
    end

    # extract names for all anchors, xref and label
    def parse(docxml)
      @doctype = docxml.at(ns("//bibdata/ext/doctype"))&.text
      @seen = SeenAnchor.new(docxml)
      amend_preprocess(docxml) if @parse_settings.empty?
      initial_anchor_names(docxml)
      back_anchor_names(docxml)
      asset_anchor_names(docxml)
      @parse_settings = {}
    end

    def ns(xpath)
      Common::ns(xpath)
    end

    def l10n(text, lang = @lang, script = @script, locale = @locale)
      @i18n.l10n(text, lang, script, locale)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
isodoc-2.9.2 lib/isodoc/xref.rb
isodoc-2.9.1 lib/isodoc/xref.rb
isodoc-2.9.0 lib/isodoc/xref.rb
isodoc-2.8.5 lib/isodoc/xref.rb
isodoc-2.8.4 lib/isodoc/xref.rb
isodoc-2.8.3 lib/isodoc/xref.rb
isodoc-2.8.2 lib/isodoc/xref.rb
isodoc-2.8.1 lib/isodoc/xref.rb
isodoc-2.8.0 lib/isodoc/xref.rb
isodoc-2.7.4 lib/isodoc/xref.rb
isodoc-2.7.3 lib/isodoc/xref.rb
isodoc-2.7.2 lib/isodoc/xref.rb
isodoc-2.7.1 lib/isodoc/xref.rb
isodoc-2.7.0 lib/isodoc/xref.rb
isodoc-2.6.6 lib/isodoc/xref.rb
isodoc-2.6.5 lib/isodoc/xref.rb
isodoc-2.6.4 lib/isodoc/xref.rb
isodoc-2.6.3 lib/isodoc/xref.rb