Module: Herb::AST::Helpers

Included in:
Visitor
Defined in:
lib/herb/ast/helpers.rb

Instance Method Summary collapse

Instance Method Details

#erb_comment?(opening) ⇒ Boolean

: (String) -> bool

Returns:

  • (Boolean)


16
17
18
# File 'lib/herb/ast/helpers.rb', line 16

def erb_comment?(opening)
  opening.start_with?("<%#")
end

#erb_graphql?(opening) ⇒ Boolean

: (String) -> bool

Returns:

  • (Boolean)


21
22
23
# File 'lib/herb/ast/helpers.rb', line 21

def erb_graphql?(opening)
  opening.start_with?("<%graphql")
end

#erb_output?(opening) ⇒ Boolean

: (String) -> bool

Returns:

  • (Boolean)


26
27
28
# File 'lib/herb/ast/helpers.rb', line 26

def erb_output?(opening)
  opening.include?("=")
end

#erb_outputs?(node) ⇒ Boolean

: (Herb::AST::Node?) -> bool

Returns:

  • (Boolean)


8
9
10
11
12
13
# File 'lib/herb/ast/helpers.rb', line 8

def erb_outputs?(node)
  return false unless node.is_a?(Herb::AST::ERBContentNode)

  opening = node.tag_opening&.value || ""
  opening.include?("=") && !opening.start_with?("<%#")
end

#inline_ruby_comment?(node) ⇒ Boolean

: (Herb::AST::ERBContentNode) -> bool

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/herb/ast/helpers.rb', line 31

def inline_ruby_comment?(node)
  return false unless node.is_a?(Herb::AST::ERBContentNode)
  return false if erb_comment?(node.tag_opening&.value || "")

  content = node.content&.value || ""
  stripped = content.lstrip

  stripped.start_with?("#") && node.location.start.line == node.location.end.line
end