Class: Herb::AST::HTMLTextNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_html_text_node = { | content: String?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
: String?.
Attributes inherited from Node
#errors, #location, #source, #type
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
: (Visitor) -> void.
-
#child_nodes ⇒ Object
: () -> Array.
-
#compact_child_nodes ⇒ Object
: () -> Array.
-
#initialize(type, location, errors, content) ⇒ HTMLTextNode
constructor
: (String, Location, Array, String) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_html_text_node.
-
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String.
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, content) ⇒ HTMLTextNode
: (String, Location, Array, String) -> void
1266 1267 1268 1269 |
# File 'lib/herb/ast/nodes.rb', line 1266 def initialize(type, location, errors, content) super(type, location, errors) @content = content&.force_encoding("utf-8") end |
Instance Attribute Details
#content ⇒ Object (readonly)
: String?
1263 1264 1265 |
# File 'lib/herb/ast/nodes.rb', line 1263 def content @content end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
1279 1280 1281 |
# File 'lib/herb/ast/nodes.rb', line 1279 def accept(visitor) visitor.visit_html_text_node(self) end |
#child_nodes ⇒ Object
: () -> Array
1284 1285 1286 |
# File 'lib/herb/ast/nodes.rb', line 1284 def child_nodes [] end |
#compact_child_nodes ⇒ Object
: () -> Array
1289 1290 1291 |
# File 'lib/herb/ast/nodes.rb', line 1289 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
1294 1295 1296 |
# File 'lib/herb/ast/nodes.rb', line 1294 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_html_text_node
1272 1273 1274 1275 1276 |
# File 'lib/herb/ast/nodes.rb', line 1272 def to_hash super.merge({ content: content, }) #: Herb::serialized_html_text_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 |
# File 'lib/herb/ast/nodes.rb', line 1299 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("└── content: ") + green("#{content.inspect}\n") output += "\n" output.gsub(/^/, " " * indent) end |