Class: Hexp::TextNode
- Inherits:
-
String
- Object
- String
- Hexp::TextNode
- Defined in:
- lib/hexp/text_node.rb
Overview
Represents text inside HTML. Instances behave like Strings, but also support the most of `Hexp::Node` interface, so you don't have to treat them differently when traversing across trees.
Strings used inside Hexp literals like `H[:span, "Hi!"]` automatically get converted to `TextNode` instances, so there is usually no reason to instantiate these yourself.
Instance Method Summary (collapse)
-
- (Hash) attributes
The attributes of this Node.
-
- (Array) children
Children of the node.
-
- (FalseClass) class?(klz)
Is a certain CSS class present on this node?.
-
- (String) inspect
Inspect the TextNode.
-
- (String) pp
Same as inspect, used by `Hexp::Node#pp`.
-
- (Hexp::TextNode) rewrite(&blk)
Rewrite a node.
- - (Object) select(&block)
-
- (NilClass) tag
The tag of this node.
-
- (TrueClass) text?
Is this a text node?.
-
- (Hexp::TextNode) to_hexp
Standard conversion protocol, returns self.
Instance Method Details
- (Hash) attributes
The attributes of this Node
Text nodes can not have attributes, so this always returns an empty Hash.
37 38 39 |
# File 'lib/hexp/text_node.rb', line 37 def attributes {}.freeze end |
- (Array) children
Children of the node
A text node has no children, this always returns an empty array.
92 93 94 |
# File 'lib/hexp/text_node.rb', line 92 def children [].freeze end |
- (FalseClass) class?(klz)
Is a certain CSS class present on this node?
Text nodes have no attributes, so this always returns false.
121 122 123 |
# File 'lib/hexp/text_node.rb', line 121 def class?(klz) false end |
- (String) inspect
Inspect the TextNode
This delegates to the underlying String, making it non-obvious that you're dealing with something else. However, a TextNode supports the full API of String, so this might not be a big problem. The benefit is that inspection of complete nodes containing text looks nice
25 26 27 |
# File 'lib/hexp/text_node.rb', line 25 def inspect __getobj__.inspect end |
- (String) pp
Same as inspect, used by `Hexp::Node#pp`
50 51 52 |
# File 'lib/hexp/text_node.rb', line 50 def pp inspect end |
- (Hexp::TextNode) rewrite(&blk)
Rewrite a node
See Hexp::Node#rewrite for more info. On a TextNode this simply return self.
138 139 140 |
# File 'lib/hexp/text_node.rb', line 138 def rewrite(&blk) self end |
- (Object) select(&block)
142 143 144 |
# File 'lib/hexp/text_node.rb', line 142 def select(&block) Node::Selector.new(self, block) end |
- (NilClass) tag
The tag of this node
A text node does not have a tag, so this returns nil
65 66 |
# File 'lib/hexp/text_node.rb', line 65 def tag end |
- (TrueClass) text?
Is this a text node?
106 107 108 |
# File 'lib/hexp/text_node.rb', line 106 def text? true end |
- (Hexp::TextNode) to_hexp
Standard conversion protocol, returns self
77 78 79 |
# File 'lib/hexp/text_node.rb', line 77 def to_hexp self end |