class Sheen::Tree::Branch

Overview

A node in a tree.

An implementation of Node with children and a builder API.

Defined in:

sheen/tree.cr

Constructors

Instance Method Summary

Instance methods inherited from class Sheen::Tree::Node

children : Children children, hidden? : Bool hidden?, to_s(io : IO) : Nil to_s, value : String value

Constructor Detail

def self.new(value : String = "", hidden : Bool = false) #

[View source]
def self.root(value) : Branch #

Builds a tree already rooted at value. Shorthand for new.root(value)


[View source]

Instance Method Detail

def child(value : Branch) : Branch #

Appends a child Branch. A rootless value auto-nests onto the previous sibling, otherwise it is appended.

Returns self.


[View source]
def child(value : Children) : Branch #

Appends each node from value as a child.

Returns self.


[View source]
def child(value : Node) : Branch #

Appends value as a child node.

Returns self.


[View source]
def child(value : Array) : Branch #

Appends each element of value as a child.

Returns self.


[View source]
def child(value : Nil) : Branch #

Skips nil, adding no child.

Returns self.


[View source]
def child(value) : Branch #

Appends value of any type that responds to #to_s as a Leaf child.

Returns self.


[View source]
def child(*values) : Branch #

Appends one or more child values to the tree.

Returns self.


[View source]
def children : Children #

A copy of the tree's children.


[View source]
def config : Config | Nil #

This node's render configuration, or nil while it inherits its parent's.


[View source]
def enumerator(enumr : Enumerator) : Branch #

Sets the branch-prefix enumerator.

Returns self.


[View source]
def enumerator(&block : Children, Int32 -> String) : Branch #

Sets the branch-prefix enumerator from a block.

Returns self.


[View source]
def enumerator(kind : Enumerators) : Branch #

Convenience method to set one of the builtin enumerator styles by kind. eg #enumerator(:rounded)

Returns self.


[View source]
def enumerator_style(style : Style) : Branch #

Sets one static style for every enumerator prefix.

Returns self.


[View source]
def enumerator_style(&block : Children, Int32 -> Style) : Branch #

Sets the enumerator style block, invoked per child.

Returns self.


[View source]
def hidden? : Bool #
Description copied from class Sheen::Tree::Node

If this node is hidden from rendering or not.


[View source]
def hide(hidden : Bool = true) : Branch #

Sets whether the tree is hidden from rendering.

Returns self.


[View source]
def indenter(ind : Indenter) : Branch #

Sets the indenter used for nested children.

Returns self.


[View source]
def indenter(&block : Children, Int32 -> String) : Branch #

Sets the indenter used for nested children from a block.

Returns self.


[View source]
def item_style(style : Style) : Branch #

Sets one static style for every item's value.

Returns self.


[View source]
def item_style(&block : Children, Int32 -> Style) : Branch #

Sets the item style block, invoked per child for conditional styling.

Returns self.


[View source]
def render : String #

Renders the whole tree to a string using this node's configuration, or Config defaults if none have been set.


[View source]
def root(value : Branch) : Branch #

Sets value as the root and appends its children.

Returns self.


[View source]
def root(value) : Branch #

Sets value as the root.

Returns self.


[View source]
def root_style(style : Style) : Branch #

Sets the style applied to the root node's value.

Returns self.


[View source]
def to_s(io : IO) : Nil #

Render the tree to io. Overrides Node#.to_s which emits only the bare value.


[View source]
def value : String #
Description copied from class Sheen::Tree::Node

The node's display value.


[View source]