Sha256: e38f110c80e8570005425a1ae47e15474103dd781b6517125d3d2410defb314d

Contents?: true

Size: 1.45 KB

Versions: 21

Compression:

Stored size: 1.45 KB

Contents

require "singleton"

module IsoDoc::Function
  module XrefGen
    class Seen_Anchor
      include Singleton

      def initialize
        @seen = {}
      end

      def seen(x)
        @seen.has_key?(x)
      end
      
      def add(x)
        @seen[x] = true
      end
    end

    @anchors = {}

    def get_anchors
      @anchors
    end

    def anchor(id, lbl, warning = true)
      return nil if id.nil? || id.empty?
      unless @anchors[id]
        if warning
          @seen ||= Seen_Anchor.instance
          @seen.seen(id) or warn "No label has been processed for ID #{id}"
          @seen.add(id)
          return "[#{id}]"
        end
      end
      @anchors.dig(id, lbl)
    end

    def anchor_struct_label(lbl, elem)
      case elem
      when @appendix_lbl then l10n("#{elem} #{lbl}")
      else
        lbl.to_s
      end
    end

    def anchor_struct_xref(lbl, elem)
      case elem
      when @formula_lbl then l10n("#{elem} (#{lbl})")
      when @inequality_lbl then l10n("#{elem} (#{lbl})")
      else
        l10n("#{elem} #{lbl}")
      end
    end

    def anchor_struct(lbl, container, elem, type, unnumbered = false)
      ret = {}
      ret[:label] = unnumbered == "true" ? nil : anchor_struct_label(lbl, elem)
      ret[:xref] = anchor_struct_xref(unnumbered == "true" ? "(??)" : lbl, elem)
      ret[:xref].gsub!(/ $/, "")
      ret[:container] = get_clause_id(container) unless container.nil?
      ret[:type] = type
      ret
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
isodoc-1.0.29 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.28 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.27 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.26 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.25 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.24 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.23 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.22 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.21 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.20 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.19 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.18 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.17 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.16 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.15 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.14 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.13 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.12 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.11 lib/isodoc/function/xref_anchor.rb
isodoc-1.0.10 lib/isodoc/function/xref_anchor.rb