Class: Psychgus::StyledTreeBuilder
- Inherits:
-
Psych::TreeBuilder
- Object
- Psych::TreeBuilder
- Psychgus::StyledTreeBuilder
- Defined in:
- lib/psychgus/styled_tree_builder.rb
Overview
Use this wherever Psych::TreeBuilder would have been used, to enable styling.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#deref_aliases ⇒ true, false
(also: #deref_aliases?)
Whether to dereference aliases; output the actual value instead of the alias.
-
#sniffer ⇒ SuperSniffer
readonly
The SuperSniffer being used to sniff the YAML nodes, level, etc.
-
#stylers ⇒ Array<Stylers>
readonly
The Styler(s) being used to style the YAML nodes.
Instance Method Summary collapse
-
#add_styler(*stylers) ⇒ self
Add Styler(s) onto the end of the data structure.
-
#alias ⇒ Psych::Nodes::Alias
Calls super, styler(s), and sniffer.
-
#end_document ⇒ Object
Calls super and sniffer.
-
#end_mapping ⇒ Object
Calls super and sniffer.
-
#end_sequence ⇒ Object
Calls super and sniffer.
-
#end_stream ⇒ Object
Calls super and sniffer.
-
#initialize(*stylers, deref_aliases: false, **options) ⇒ StyledTreeBuilder
constructor
Initialize this class with Styler(s).
-
#insert_styler(index, *stylers) ⇒ self
Insert Styler(s) at
index
into the data structure. -
#pop_styler(count = 1) ⇒ Styler, ...
Remove the last Styler(s) from the data structure.
-
#remove_styler(styler, &block) ⇒ Styler?
Remove the Styler that matches
styler
from the data structure. -
#remove_styler_at(index) ⇒ Styler?
Remove the Styler at
index
from the data structure. -
#scalar ⇒ Psych::Nodes::Scalar
Calls super, styler(s), and sniffer.
-
#start_document ⇒ Psych::Nodes::Document
Calls super, styler(s), and sniffer.
-
#start_mapping ⇒ Psych::Nodes::Mapping
Calls super, styler(s), and sniffer.
-
#start_sequence ⇒ Psych::Nodes::Sequence
Calls super, styler(s), and sniffer.
-
#start_stream ⇒ Psych::Nodes::Stream
Calls super, styler(s), and sniffer.
Constructor Details
#initialize(*stylers, deref_aliases: false, **options) ⇒ StyledTreeBuilder
Initialize this class with Psychgus::Styler(s).
40 41 42 43 44 45 46 47 48 |
# File 'lib/psychgus/styled_tree_builder.rb', line 40 def initialize(*stylers,deref_aliases: false,**) super() @deref_aliases = deref_aliases @sniffer = SuperSniffer.new @stylers = [] add_styler(*stylers) end |
Instance Attribute Details
#deref_aliases ⇒ true, false Also known as: deref_aliases?
Returns whether to dereference aliases; output the actual value instead of the alias.
26 27 28 |
# File 'lib/psychgus/styled_tree_builder.rb', line 26 def deref_aliases @deref_aliases end |
#sniffer ⇒ SuperSniffer (readonly)
Returns the Psychgus::SuperSniffer being used to sniff the YAML nodes, level, etc.
30 31 32 |
# File 'lib/psychgus/styled_tree_builder.rb', line 30 def sniffer @sniffer end |
#stylers ⇒ Array<Stylers> (readonly)
Returns the Psychgus::Styler(s) being used to style the YAML nodes.
33 34 35 |
# File 'lib/psychgus/styled_tree_builder.rb', line 33 def stylers @stylers end |
Instance Method Details
#add_styler(*stylers) ⇒ self
Add Psychgus::Styler(s) onto the end of the data structure.
55 56 57 58 59 |
# File 'lib/psychgus/styled_tree_builder.rb', line 55 def add_styler(*stylers) @stylers.push(*stylers) return self end |
#alias ⇒ Psych::Nodes::Alias
Calls super, styler(s), and sniffer.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/psychgus/styled_tree_builder.rb', line 69 def alias(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_alias(sniffer,node) end @sniffer.add_alias(node) return node end |
#end_document ⇒ Object
Calls super and sniffer.
86 87 88 89 90 91 92 |
# File 'lib/psychgus/styled_tree_builder.rb', line 86 def end_document(*) result = super @sniffer.end_document return result end |
#end_mapping ⇒ Object
Calls super and sniffer.
98 99 100 101 102 103 104 |
# File 'lib/psychgus/styled_tree_builder.rb', line 98 def end_mapping(*) result = super @sniffer.end_mapping return result end |
#end_sequence ⇒ Object
Calls super and sniffer.
110 111 112 113 114 115 116 |
# File 'lib/psychgus/styled_tree_builder.rb', line 110 def end_sequence(*) result = super @sniffer.end_sequence return result end |
#end_stream ⇒ Object
Calls super and sniffer.
122 123 124 125 126 127 128 |
# File 'lib/psychgus/styled_tree_builder.rb', line 122 def end_stream(*) result = super @sniffer.end_stream return result end |
#insert_styler(index, *stylers) ⇒ self
Insert Psychgus::Styler(s) at index
into the data structure.
135 136 137 138 139 |
# File 'lib/psychgus/styled_tree_builder.rb', line 135 def insert_styler(index,*stylers) @stylers.insert(index,*stylers) return self end |
#pop_styler(count = 1) ⇒ Styler, ...
Remove the last Psychgus::Styler(s) from the data structure.
146 147 148 149 150 151 |
# File 'lib/psychgus/styled_tree_builder.rb', line 146 def pop_styler(count=1) return nil if count == 0 return @stylers.pop if count == 1 return @stylers.pop(count) end |
#remove_styler(styler, &block) ⇒ Styler?
Remove the Psychgus::Styler that matches styler
from the data structure.
An optional block
can return a default value if not found.
161 162 163 |
# File 'lib/psychgus/styled_tree_builder.rb', line 161 def remove_styler(styler,&block) return @stylers.delete(styler,&block) end |
#remove_styler_at(index) ⇒ Styler?
Remove the Psychgus::Styler at index
from the data structure.
170 171 172 |
# File 'lib/psychgus/styled_tree_builder.rb', line 170 def remove_styler_at(index) return @stylers.delete_at(index) end |
#scalar ⇒ Psych::Nodes::Scalar
Calls super, styler(s), and sniffer.
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/psychgus/styled_tree_builder.rb', line 182 def scalar(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_scalar(sniffer,node) end @sniffer.add_scalar(node) return node end |
#start_document ⇒ Psych::Nodes::Document
Calls super, styler(s), and sniffer.
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/psychgus/styled_tree_builder.rb', line 203 def start_document(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_document(sniffer,node) end @sniffer.start_document(node) return node end |
#start_mapping ⇒ Psych::Nodes::Mapping
Calls super, styler(s), and sniffer.
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/psychgus/styled_tree_builder.rb', line 224 def start_mapping(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_mapping(sniffer,node) end @sniffer.start_mapping(node) return node end |
#start_sequence ⇒ Psych::Nodes::Sequence
Calls super, styler(s), and sniffer.
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/psychgus/styled_tree_builder.rb', line 245 def start_sequence(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_sequence(sniffer,node) end @sniffer.start_sequence(node) return node end |
#start_stream ⇒ Psych::Nodes::Stream
Calls super, styler(s), and sniffer.
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/psychgus/styled_tree_builder.rb', line 266 def start_stream(*) node = super @stylers.each do |styler| styler.style(sniffer,node) styler.style_stream(sniffer,node) end @sniffer.start_stream(node) return node end |