Class: Lilac::CLI::Directive

Inherits:
Struct
  • Object
show all
Defined in:
lib/lilac/cli/build/directive.rb

Overview

A single data-* directive occurrence on a template element.

kind is the directive family symbol (e.g. :text, :on, :attr, :each). For X-family directives (data-on-X, data-attr-X, data-arg-X, data-css-X), name carries the X part as it appears in the source (kebab-case, e.g. "click" / "background-color"). For non-X-family directives name is nil.

value is the raw attribute value string (e.g. "@count" / "increment" / "{ active: @s }"). TemplateAST only collects the raw string; grammar validation lives in the lint layer.

ref_id is the synthetic or explicit ref name assigned by TemplateAST, used by the lint layer to group directives sharing an element and to detect duplicate data-ref declarations.

line is the source line in the template body (1-based, Nokogiri's node.line), used for error reporting.

element_tag is the HTML element name (e.g. "div", "button"), consumed by Lilac::Directives::Lints to enforce applicability rules.

scope_id is the ref_id of the enclosing data-each element, or nil for directives at the component's top level. The lint layer uses it to scope duplicate-ref detection per iteration body.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#element_tagObject

Returns the value of attribute element_tag

Returns:

  • (Object)

    the current value of element_tag



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def element_tag
  @element_tag
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def kind
  @kind
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def line
  @line
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def name
  @name
end

#ref_idObject

Returns the value of attribute ref_id

Returns:

  • (Object)

    the current value of ref_id



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def ref_id
  @ref_id
end

#scope_idObject

Returns the value of attribute scope_id

Returns:

  • (Object)

    the current value of scope_id



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def scope_id
  @scope_id
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



32
33
34
# File 'lib/lilac/cli/build/directive.rb', line 32

def value
  @value
end

Instance Method Details

#source_location(file) ⇒ Object

Pair the directive's line with the source file (which the Directive itself doesn't carry) for use in BuildError / LintWarning at: kwargs. Saves callers from writing SourceLocation.new(file: f, line: directive.line) over and over.



46
47
48
# File 'lib/lilac/cli/build/directive.rb', line 46

def source_location(file)
  SourceLocation.new(file: file, line: line)
end