textbackend

package module
v0.0.0-...-312bc2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 4 Imported by: 1

README

textbackend Build Status Coverage Status

simple textbackend to create a row/level organized content array.
it is implemented in golang and docs can be found at GoDoc

pseudo data model...

content[
  { ... }
  { level: 0, text: "some words at one line of the document" }
  { level: 1, text: "the level can be used to tab one inside" }
  { level: 1, text: "..." }
  { ... }
]

License

This code is published under an MIT license. See LICENSE file for more information.

Documentation

Overview

Package textbackend simple usage example:

textContent := TextContent{}
textContent.Writeln("hello world")
textContent.PushLevel()
textContent.Writeln("one more line")
textContent.PopLevel()
theText := textContent.GetStringArray("\t")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TextContent

type TextContent struct {
	Rows         []TextRow
	CurrentLevel uint8 // the current level
}

TextContent store a ContentLine list

func NewTextContent

func NewTextContent() *TextContent

NewTextContent initialize and return a TextContent object

func ReadFile

func ReadFile(filename, whitespace, linebreak string) (*TextContent, error)

ReadFile read a file and return a TextContent object

func (*TextContent) AppendRow

func (t *TextContent) AppendRow(r TextRow)

AppendRow add a TextRow object to the Rows array

func (*TextContent) Get

func (t *TextContent) Get(linebreak, whitespace string) []byte

Get renders out the content as string and you can set the type of linebreak and level char

func (*TextContent) GetJSON

func (t *TextContent) GetJSON() ([]byte, error)

GetJSON return the content as array with row objects.

func (*TextContent) GetLevel

func (t *TextContent) GetLevel() uint8

GetLevel return the current level depth as int.

func (*TextContent) GetStringArray

func (t *TextContent) GetStringArray(whitespace string) []string

GetStringArray return the content as array.

func (*TextContent) GetTotalLines

func (t *TextContent) GetTotalLines() int

GetTotalLines returns the number of lines.

func (*TextContent) PopLevel

func (t *TextContent) PopLevel()

PopLevel pop out from the level.

func (*TextContent) PushLevel

func (t *TextContent) PushLevel()

PushLevel pushes into the next level.

func (*TextContent) Reset

func (t *TextContent) Reset()

Reset the content data and the current level value

func (*TextContent) SetLevel

func (t *TextContent) SetLevel(depth uint8)

SetLevel set the level to a specific depth

func (*TextContent) Write

func (t *TextContent) Write(text string)

Write writes text to the latest row

func (*TextContent) WriteFile

func (t *TextContent) WriteFile(filename string, perm os.FileMode, linebreak, whitespace string) error

WriteFile write the text content to a file.

func (*TextContent) WriteTo

func (t *TextContent) WriteTo(row int, text string)

WriteTo writes text to a specific line.

func (*TextContent) Writeln

func (t *TextContent) Writeln(text string)

Writeln append a line to the content array

type TextRow

type TextRow struct {
	Level uint8  `json:"level"`
	Text  string `json:"text"`
}

TextRow to store the level and text of one row.

func NewTextRow

func NewTextRow(l uint8, t string) *TextRow

NewTextRow initialize and return a TextRow object

func NewTextRowFromString

func NewTextRowFromString(text, whitespace string) *TextRow

NewTextRowFromString read a string and return a TextRow object

func (*TextRow) AppendText

func (t *TextRow) AppendText(text string)

AppendText add the given string to the text row

func (*TextRow) EqualTo

func (t *TextRow) EqualTo(text string) bool

EqualTo returns true if the given string is equal to the row text

func (*TextRow) GetLevel

func (t *TextRow) GetLevel() uint8

GetLevel return the level of the TextRow

func (*TextRow) GetLevelWhitespace

func (t *TextRow) GetLevelWhitespace(whitespace string) string

GetLevelWhitespace returns the whitespace for the TextRow

func (*TextRow) GetString

func (t *TextRow) GetString(whitespace string) string

GetString returns the row with whitespace and text

func (*TextRow) GetText

func (t *TextRow) GetText() string

GetText return the text of the TextRow

func (*TextRow) GetTextLength

func (t *TextRow) GetTextLength() int

GetTextLength return the text of the TextRow

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL