Class: Herb::AST::HTMLConditionalOpenTagNode

Inherits:
Node
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/ast/nodes.rb,
ext/herb/nodes.c

Overview

: type serialized_html_conditional_open_tag_node = { | conditional: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?, | tag_name: Herb::Token?, | is_void: bool, | }

Constant Summary

Constants included from Colors

Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR

Instance Attribute Summary collapse

Attributes inherited from Node

#errors, #location, #source, #type

Instance Method Summary collapse

Methods included from Colors

bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow

Methods inherited from Node

#class_name, #inspect_array, #inspect_errors, #node_name, #recursive_errors, #to_json

Constructor Details

#initialize(type, location, errors, conditional, tag_name, is_void) ⇒ HTMLConditionalOpenTagNode

: (String, Location, Array, (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode), Herb::Token, bool) -> void



274
275
276
277
278
279
# File 'lib/herb/ast/nodes.rb', line 274

def initialize(type, location, errors, conditional, tag_name, is_void)
  super(type, location, errors)
  @conditional = conditional
  @tag_name = tag_name
  @is_void = is_void
end

Instance Attribute Details

#conditionalObject (readonly)

: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?



269
270
271
# File 'lib/herb/ast/nodes.rb', line 269

def conditional
  @conditional
end

#is_voidObject (readonly)

: bool



271
272
273
# File 'lib/herb/ast/nodes.rb', line 271

def is_void
  @is_void
end

#tag_nameObject (readonly)

: Herb::Token?



270
271
272
# File 'lib/herb/ast/nodes.rb', line 270

def tag_name
  @tag_name
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



291
292
293
# File 'lib/herb/ast/nodes.rb', line 291

def accept(visitor)
  visitor.visit_html_conditional_open_tag_node(self)
end

#child_nodesObject

: () -> Array



296
297
298
# File 'lib/herb/ast/nodes.rb', line 296

def child_nodes
  [conditional]
end

#compact_child_nodesObject

: () -> Array



301
302
303
# File 'lib/herb/ast/nodes.rb', line 301

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



306
307
308
# File 'lib/herb/ast/nodes.rb', line 306

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_html_conditional_open_tag_node



282
283
284
285
286
287
288
# File 'lib/herb/ast/nodes.rb', line 282

def to_hash
  super.merge({
    conditional: conditional,
    tag_name: tag_name,
    is_void: is_void,
  }) #: Herb::serialized_html_conditional_open_tag_node
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/herb/ast/nodes.rb', line 311

def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
  output = +""

  output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
  output += "\n"

  if depth >= depth_limit
    output += dimmed("└── [depth limit reached ...]\n\n")

    return output.gsub(/^/, "    " * indent)
  end

  output += inspect_errors(prefix: "")

  output += white("├── conditional: ")
  if conditional
    output += "\n"
    output += "│   └── "
    output += conditional.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, "    " * (indent + 1)).lstrip.gsub(/^/, "").delete_prefix("")
  else
    output += magenta("∅\n")
  end
  output += white("├── tag_name: ")
  output += tag_name ? tag_name.tree_inspect : magenta("")
  output += "\n"
  output += white("└── is_void: ")
  output += [true, false].include?(is_void) ? bold(magenta(is_void.to_s)) : magenta("")
  output += "\n"
  output += "\n"

  output.gsub(/^/, "    " * indent)
end