unit

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2018 License: Apache-2.0 Imports: 6 Imported by: 4

README

unit

Documentation

Overview

Package unit provides structures and interfaces to deal with different content units

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(u1, u2 Unit) bool

Equal compares two units and returns true if they are equal and false otherwise

func NotEqual

func NotEqual(u1, u2 Unit) bool

NotEqual two units and returns true if they are not equal and false otherwise

func OptionClockMock

func OptionClockMock(t ...time.Time) func(u interface{})

OptionClockMock is an option that sets internal clock for a unit to return mocked values

func OptionClockMockPartial

func OptionClockMockPartial(t ...time.Time) func(u interface{})

OptionClockMockPartial is an option that sets internal clock for a unit to return mocked value once

func OptionClockReal

func OptionClockReal() func(u interface{})

OptionClockReal is an option that sets internal clock for a unit to return real time

func OptionIDGeneratorMock

func OptionIDGeneratorMock(s string) func(u interface{})

OptionIDGeneratorMock is an option that sets internal UUID generator for a unit to return same value each time

func OptionIDGeneratorUUID

func OptionIDGeneratorUUID() func(u interface{})

OptionIDGeneratorUUID is an option that sets internal UUID generator for a unit to UUID implementation

func OptionListItem

func OptionListItem(item Unit) func(u interface{})

OptionListItem is an option that adds new item to the list unit

func OptionListMarshalItems

func OptionListMarshalItems(m bool) func(u interface{})

OptionListMarshalItems is an option that sets marshalItems flag for a list unit to the provided value

func OptionTextCodeData

func OptionTextCodeData(t string) func(u interface{})

OptionTextCodeData is an option that sets data for a text code unit to the provided value

func OptionTextCodeLanguage

func OptionTextCodeLanguage(l string) func(u interface{})

OptionTextCodeLanguage is an option that sets language for a text code unit to the provided value

func OptionTextMarkdownData

func OptionTextMarkdownData(t string) func(u interface{})

OptionTextMarkdownData is an option that sets data for a text markdown unit to the provided value

func OptionTextPlainData

func OptionTextPlainData(t string) func(u interface{})

OptionTextPlainData is an option that sets data for a text plain unit to the provided value

func OptionTitle

func OptionTitle(t string) func(u interface{})

OptionTitle is an option that sets title for a unit to the provided value

func OptionTodoItem

func OptionTodoItem(data string, done bool) func(u interface{})

OptionTodoItem is an option that adds new todo item to the unit

Types

type List

type List interface {
	Unit
	Items() []Unit
	SetItems(items []Unit)
	AddItem(item Unit)
	GetItem(index int) Unit
	SetItem(index int, item Unit)
	RemoveItem(index int)
	SetMarshalItems(m bool)
	MarshalItems() bool
}

List represents unit which contains other units

func NewList

func NewList(options ...func(u interface{})) List

NewList creates new List unit with given title

type TextCode

type TextCode interface {
	TextPlain
	Language() string
	SetLanguage(language string)
}

TextCode represents unit which contains some source code as plain text and it's language

func NewTextCode

func NewTextCode(options ...func(u interface{})) TextCode

NewTextCode creates new TextCode unit with given title, data and language

type TextMarkdown

type TextMarkdown interface {
	TextPlain
}

TextMarkdown represents unit which has some plain markdown content

func NewTextMarkdown

func NewTextMarkdown(options ...func(u interface{})) TextMarkdown

NewTextMarkdown creates new TextMarkdown unit with given title and data

type TextPlain

type TextPlain interface {
	Unit
	Data() string
	SetData(data string)
}

TextPlain represents unit which has some plain text content

func NewTextPlain

func NewTextPlain(options ...func(u interface{})) TextPlain

NewTextPlain creates new TextPlain unit with given title and data

type Todo

type Todo interface {
	Unit
	NewItem() TodoItem
	Items() []TodoItem
	SetItems(items []TodoItem)
	AddItem(item TodoItem)
	GetItem(index int) TodoItem
	SetItem(index int, item TodoItem)
	RemoveItem(index int)
}

Todo represents unit which contains todo items

func NewTodo

func NewTodo(options ...func(u interface{})) Todo

NewTodo creates new Todo unit with given title

type TodoItem

type TodoItem interface {
	Data() string
	SetData(data string)
	Done() bool
	SetDone(done bool)
}

TodoItem represents single item which can have some string data and done status

type Type

type Type int

Type represents type enumeration for unit types

const (
	// TypeUnit represents type "Unit" for unit
	TypeUnit Type = 1 + iota
	// TypeList represents type "List" for unit
	TypeList
	// TypeTodo represents type "Todo" for unit
	TypeTodo
	// TypeTextPlain represents type "TextPlain" for unit
	TypeTextPlain
	// TypeTextMarkdown represents type "TextMarkdown" for unit
	TypeTextMarkdown
	// TypeTextCode represents type "TextCode" for unit
	TypeTextCode
)

func TypeFromString

func TypeFromString(s string) (Type, error)

TypeFromString returns type by it's string representation

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON converts type to it's json representation (normally string)

func (*Type) NewObject

func (t *Type) NewObject(options ...func(u interface{})) Unit

NewObject creates new empty object of given type

func (Type) String

func (t Type) String() string

String returns string representation of type

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON converts json type representation (normally string) to type object

type Unit

type Unit interface {
	json.Marshaler
	json.Unmarshaler
	ID() string
	Title() string
	SetTitle(title string)
	Type() Type
	Created() time.Time
	Updated() time.Time
}

Unit represents simplest unit which actually does nothing but used as a base for all other units

func NewUnit

func NewUnit(options ...func(u interface{})) Unit

NewUnit creates new Unit with given title. Unit id is generated automatically

Jump to

Keyboard shortcuts

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