Class: Jade::Diagnostics::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/jade/diagnostics/renderer.rb

Defined Under Namespace

Classes: Location

Constant Summary collapse

SEVERITY_COLOR =
{
  error: "\e[31m",
  warning: "\e[33m",
  note: "\e[36m",
  help: "\e[32m",
}.freeze
BLUE =
"\e[34m".freeze
BOLD =
"\e[1m".freeze
RESET =
"\e[0m".freeze

Instance Method Summary collapse

Constructor Details

#initialize(colors: $stdout.tty?) ⇒ Renderer

Returns a new instance of Renderer.



16
17
18
# File 'lib/jade/diagnostics/renderer.rb', line 16

def initialize(colors: $stdout.tty?)
  @colors = colors
end

Instance Method Details

#render(diagnostic) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jade/diagnostics/renderer.rb', line 20

def render(diagnostic)
  [
    header(diagnostic),
    diagnostic.primary&.then { span_block(it, severity: diagnostic.severity) if it.source },
    *diagnostic
      .secondary
      .map { span_block(_1, severity: :secondary) },
    *diagnostic
      .annotations
      .map { annotation(_1) },
  ]
    .compact
    .join("\n")
end

#render_all(diagnostics) ⇒ Object



35
36
37
38
39
40
# File 'lib/jade/diagnostics/renderer.rb', line 35

def render_all(diagnostics)
  diagnostics
    .items
    .map { render(_1) }
    .join("\n\n")
end