Sha256: 1fea0e8bdcea6d240237f6e8734ee669023069f4afa8d8fb5536de021f7a2376

Contents?: true

Size: 1.52 KB

Versions: 19

Compression:

Stored size: 1.52 KB

Contents

module Asciidoctor
  module Standoc
    class Log
      def initialize
        @log = {}
      end

      def add(category, loc, msg)
        return if @novalid
        @log[category] = [] unless @log[category]
        @log[category] << { location: current_location(loc), message: msg }
        loc = loc.nil? ? "" : "(#{current_location(loc)}): "
        warn "#{category}: #{loc}#{msg}" 
      end

      def current_location(n)
        return "" if n.nil?
        return n if n.is_a? String
        return "Asciidoctor Line #{"%06d" % n.lineno}" if n.respond_to?(:lineno) &&
          !n.lineno.nil? && !n.lineno.empty?
        return "XML Line #{"%06d" % n.line}" if n.respond_to?(:line) &&
          !n.line.nil?
        return "ID #{n.id}" if n.respond_to?(:id) && !n.id.nil?
        while !n.nil? &&
            (!n.respond_to?(:level) || n.level.positive?) &&
            (!n.respond_to?(:context) || n.context != :section)
          n = n.parent
          return "Section: #{n.title}" if n&.respond_to?(:context) &&
            n&.context == :section
        end
        "??"
      end

      def write(file)
        File.open(file, "w:UTF-8") do |f|
          f.puts "#{file} errors"
          @log.keys.each do |key|
            f.puts "\n\n== #{key}\n\n"
            @log[key].sort do |a, b|
              a[:location] <=> b[:location]
            end.each do |n|
              loc = n[:location] ? "(#{n[:location]}): " : ""
              f.puts "#{loc}#{n[:message]}" 
            end
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 18 versions & 2 rubygems

Version Path
metanorma-standoc-1.5.1 lib/asciidoctor/standoc/log.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-standoc-1.4.4/lib/asciidoctor/standoc/log.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-standoc-1.5.0/lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.5.0 lib/asciidoctor/standoc/log.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/metanorma-standoc-1.4.4/lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.4.4 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.4.3 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.4.2 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.4.1 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.4.0 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.29 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.28 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.27 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.26 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.25 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.24 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.23 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.22 lib/asciidoctor/standoc/log.rb
metanorma-standoc-1.3.21 lib/asciidoctor/standoc/log.rb