Class: Asciidoctor::Standoc::Log
- Inherits:
-
Object
- Object
- Asciidoctor::Standoc::Log
- Defined in:
- lib/asciidoctor/standoc/log.rb
Instance Method Summary collapse
- #add(category, loc, msg) ⇒ Object
- #current_location(n) ⇒ Object
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #write(file) ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
4 5 6 |
# File 'lib/asciidoctor/standoc/log.rb', line 4 def initialize @log = {} end |
Instance Method Details
#add(category, loc, msg) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/asciidoctor/standoc/log.rb', line 8 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 |
#current_location(n) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/asciidoctor/standoc/log.rb', line 16 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 |
#write(file) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/asciidoctor/standoc/log.rb', line 34 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 |