Class: Herb::Engine::ValidationErrorOverlay
- Inherits:
-
Object
- Object
- Herb::Engine::ValidationErrorOverlay
- Defined in:
- lib/herb/engine/validation_error_overlay.rb
Constant Summary collapse
- CONTEXT_LINES =
2- VALIDATOR_BADGES =
{ "SecurityValidator" => { label: "Security", color: "#dc2626" }, "NestingValidator" => { label: "Nesting", color: "#f59e0b" }, "AccessibilityValidator" => { label: "A11y", color: "#3b82f6" }, }.freeze
- SEVERITY_COLORS =
{ "error" => "#dc2626", "warning" => "#f59e0b", "info" => "#3b82f6", }.freeze
Instance Method Summary collapse
- #generate_fragment ⇒ Object
-
#initialize(source, error, filename: nil) ⇒ ValidationErrorOverlay
constructor
A new instance of ValidationErrorOverlay.
Constructor Details
#initialize(source, error, filename: nil) ⇒ ValidationErrorOverlay
Returns a new instance of ValidationErrorOverlay.
20 21 22 23 24 25 |
# File 'lib/herb/engine/validation_error_overlay.rb', line 20 def initialize(source, error, filename: nil) @source = source @error = error @filename = filename || "unknown" @lines = source.lines end |
Instance Method Details
#generate_fragment ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/herb/engine/validation_error_overlay.rb', line 27 def generate_fragment location = @error[:location] line_num = location&.start&.line || 1 col_num = location&.start&.column || 1 validator_info = VALIDATOR_BADGES[@error[:source]] || { label: @error[:source], color: "#6b7280" } severity_color = SEVERITY_COLORS[@error[:severity].to_s] || "#6b7280" code_snippet = generate_code_snippet(line_num, col_num) <<~HTML <div class="herb-validation-item" data-severity="#{escape_attr(@error[:severity].to_s)}"> <div class="herb-validation-header"> <span class="herb-validation-badge" style="background: #{validator_info[:color]}"> #{escape_html(validator_info[:label])} </span> <span class="herb-validation-location"> #{escape_html(@filename)}:#{line_num}:#{col_num} </span> </div> <div class="herb-validation-message" style="color: #{severity_color}"> #{escape_html(@error[:])} </div> #{code_snippet} #{generate_suggestion_html if @error[:suggestion]} </div> HTML end |