Class: Browsable::Analyzers::ERB

Inherits:
Base
  • Object
show all
Defined in:
lib/browsable/analyzers/erb.rb

Overview

Audits ERB templates (and plain HTML) by parsing them in-process with the Herb gem, then looking up every HTML element and global attribute against the bundled MDN browser-compat-data snapshot.

No external tools are needed — Herb is a gem dependency — so ERB/HTML analysis works on a machine with nothing else installed.

Direct Known Subclasses

HTML

Defined Under Namespace

Classes: Usage

Instance Attribute Summary

Attributes inherited from Base

#config, #target

Instance Method Summary collapse

Methods inherited from Base

compat_data, #initialize

Constructor Details

This class inherits a constructor from Browsable::Analyzers::Base

Instance Method Details

#analyze(files) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/browsable/analyzers/erb.rb', line 16

def analyze(files)
  files.flat_map do |file|
    analyze_source(File.read(file), file: file)
  rescue StandardError
    []
  end
end

#analyze_source(source, file:) ⇒ Object

Analyze one template’s source text. Exposed directly for the LSP server, which audits unsaved, in-memory buffer contents.



26
27
28
29
30
# File 'lib/browsable/analyzers/erb.rb', line 26

def analyze_source(source, file:)
  extract_usages(source)
    .uniq { |usage| [usage.kind, usage.name, usage.line] }
    .filter_map { |usage| build_finding(usage, file: file) }
end

#required_toolsObject

Herb is in-process



14
# File 'lib/browsable/analyzers/erb.rb', line 14

def required_tools = [] # Herb is in-process