Document BlockStack and make linter happ[y/ier].

This commit is contained in:
Christian Muehlhaeuser
2019-12-25 05:26:18 +01:00
parent a1da1963cb
commit 9157a40ab2
9 changed files with 17 additions and 8 deletions
+9
View File
@@ -8,14 +8,17 @@ import (
// indentation & margin level during the rendering process.
type BlockStack []BlockElement
// Len returns the length of the stack.
func (s *BlockStack) Len() int {
return len(*s)
}
// Push appends an item to the stack.
func (s *BlockStack) Push(e BlockElement) {
*s = append(*s, e)
}
// Pop removes the last item on the stack.
func (s *BlockStack) Pop() {
stack := *s
if len(stack) == 0 {
@@ -26,6 +29,7 @@ func (s *BlockStack) Pop() {
*s = stack
}
// Indent returns the current indentation level of all elements in the stack.
func (s BlockStack) Indent() uint {
var i uint
@@ -39,6 +43,7 @@ func (s BlockStack) Indent() uint {
return i
}
// Margin returns the current margin level of all elements in the stack.
func (s BlockStack) Margin() uint {
var i uint
@@ -52,6 +57,7 @@ func (s BlockStack) Margin() uint {
return i
}
// Width returns the available rendering width
func (s BlockStack) Width(ctx RenderContext) uint {
if s.Indent()+s.Margin()*2 > uint(ctx.options.WordWrap) {
return 0
@@ -59,6 +65,7 @@ func (s BlockStack) Width(ctx RenderContext) uint {
return uint(ctx.options.WordWrap) - s.Indent() - s.Margin()*2
}
// Parent returns the current BlockElement's parent.
func (s BlockStack) Parent() BlockElement {
if len(s) == 1 {
return BlockElement{
@@ -69,6 +76,7 @@ func (s BlockStack) Parent() BlockElement {
return s[len(s)-2]
}
// Current returns the current BlockElement.
func (s BlockStack) Current() BlockElement {
if len(s) == 0 {
return BlockElement{
@@ -79,6 +87,7 @@ func (s BlockStack) Current() BlockElement {
return s[len(s)-1]
}
// With returns a StylePrimitive that inherits the current BlockElement's style.
func (s BlockStack) With(child StylePrimitive) StylePrimitive {
sb := StyleBlock{}
sb.StylePrimitive = child