domain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package domain provides domain specific types, constants, and functions.

Package domain provides domain specific types, constants, and functions.

Index

Constants

View Source
const (
	MetaKeyID               = "id"
	MetaKeyTitle            = "title"
	MetaKeyTags             = "tags"
	MetaKeySyntax           = "syntax"
	MetaKeyRole             = "role"
	MetaKeyCopyright        = "copyright"
	MetaKeyCred             = "cred"
	MetaKeyDefaultCopyright = "default-copyright"
	MetaKeyDefaultLang      = "default-lang"
	MetaKeyDefaultLicense   = "default-license"
	MetaKeyDefaultRole      = "default-role"
	MetaKeyDefaultSyntax    = "default-syntax"
	MetaKeyDefaultTitle     = "default-title"
	MetaKeyIconMaterial     = "icon-material"
	MetaKeyIdent            = "ident"
	MetaKeyLang             = "lang"
	MetaKeyLicense          = "license"
	MetaKeyOwner            = "owner"
	MetaKeySiteName         = "site-name"
	MetaKeyStart            = "start"
	MetaKeyURL              = "url"
	MetaKeyYAMLHeader       = "yaml-header"
	MetaKeyZettelFileSyntax = "zettel-file-syntax"
)

Predefined keys.

View Source
const (
	MetaValueSyntax = "zmk"
	MetaValueTitle  = "Untitled"
)

Predefined default values.

View Source
const (
	MetaTypeBool    = 'b'
	MetaTypeCred    = 'c'
	MetaTypeEmpty   = 'e'
	MetaTypeID      = 'i'
	MetaTypeString  = 's'
	MetaTypeTagSet  = 'T'
	MetaTypeURL     = 'u'
	MetaTypeUnknown = '\000'
	MetaTypeWord    = 'w'
	MetaTypeWordSet = 'W'
)

Supported key types.

View Source
const (
	ConfigurationID  = ZettelID("00000000000000")
	BaseTemplateID   = ZettelID("00000000010100")
	LoginTemplateID  = ZettelID("00000000010200")
	ListTemplateID   = ZettelID("00000000010300")
	DetailTemplateID = ZettelID("00000000010401")
	InfoTemplateID   = ZettelID("00000000010402")
	FormTemplateID   = ZettelID("00000000010403")
	RenameTemplateID = ZettelID("00000000010404")
	DeleteTemplateID = ZettelID("00000000010405")
	RolesTemplateID  = ZettelID("00000000010500")
	TagsTemplateID   = ZettelID("00000000010600")
	BaseCSSID        = ZettelID("00000000020001")
	MaterialIconID   = ZettelID("00000000030001")
)

Some important ZettelIDs

View Source
const RegexpID = "[0-9]{14}"

RegexpID contains the regexp string that determines a valid zettel id.

Variables

This section is empty.

Functions

func BoolValue

func BoolValue(value string) bool

BoolValue returns the value interpreted as a bool.

func IsValidID

func IsValidID(s string) bool

IsValidID returns true, if string is a valid zettel ID.

func KeyIsValid

func KeyIsValid(key string) bool

KeyIsValid returns true, the the key is a valid string.

func KeyType

func KeyType(key string) byte

KeyType returns a type hint for the given key. If no type hint is specified, MetaTypeUnknown is returned.

func ListFromValue

func ListFromValue(value string) []string

ListFromValue transforms a string value into a list value.

Types

type Content

type Content string

Content is just the uninterpreted content of a zettel.

func NewContent

func NewContent(s string) Content

NewContent creates a new content from a string.

func (Content) AsBytes

func (zc Content) AsBytes() []byte

AsBytes returns the content itself is a byte slice.

func (Content) AsString

func (zc Content) AsString() string

AsString returns the content itself is a string.

type Meta

type Meta struct {
	ID ZettelID

	YamlSep bool
	// contains filtered or unexported fields
}

Meta contains all meta-data of a zettel.

func NewMeta

func NewMeta(id ZettelID) *Meta

NewMeta creates a new chunk for storing meta-data

func NewMetaFromInput

func NewMetaFromInput(id ZettelID, inp *input.Input) *Meta

NewMetaFromInput parses the meta data of a zettel.

func (*Meta) Clone

func (m *Meta) Clone() *Meta

Clone returns a new copy of the same meta data that is not frozen.

func (*Meta) Delete

func (m *Meta) Delete(key string)

Delete removes a key from the data.

func (*Meta) Equal

func (m *Meta) Equal(o *Meta) bool

Equal compares to metas for equality.

func (*Meta) Freeze

func (m *Meta) Freeze()

Freeze defines frozen meta data, i.e. changing them will result in a panic.

func (*Meta) Get

func (m *Meta) Get(key string) (string, bool)

Get retrieves the string value of a given key. The bool value signals, whether there was a value stored or not.

func (*Meta) GetBool

func (m *Meta) GetBool(key string) bool

GetBool returns the boolean value of the given key.

func (*Meta) GetDefault

func (m *Meta) GetDefault(key string, def string) string

GetDefault retrieves the string value of the given key. If no value was stored, the given default value is returned.

func (*Meta) GetList

func (m *Meta) GetList(key string) ([]string, bool)

GetList retrieves the string list value of a given key. The bool value signals, whether there was a value stored or not.

func (*Meta) GetListOrNil

func (m *Meta) GetListOrNil(key string) []string

GetListOrNil retrieves the string list value of a given key. If there was nothing stores, a nil list is returned.

func (*Meta) IsFrozen

func (m *Meta) IsFrozen() bool

IsFrozen returns whether meta can be changed or not.

func (*Meta) Pairs

func (m *Meta) Pairs() []MetaPair

Pairs returns all key/values pairs stored, in a specific order. First come the pairs with predefined keys: MetaTitleKey, MetaTagsKey, MetaSyntaxKey, MetaContextKey. Then all other pairs are append to the list, ordered by key.

func (*Meta) PairsRest

func (m *Meta) PairsRest() []MetaPair

PairsRest returns all key/values pairs stored, except the values with predefined keys. The pairs are ordered by key.

func (*Meta) Set

func (m *Meta) Set(key, value string)

Set stores the given string value under the given key.

func (*Meta) SetList

func (m *Meta) SetList(key string, values []string)

SetList stores the given string list value under the given key.

func (*Meta) Type

func (m *Meta) Type(key string) byte

Type returns a type hint for the given key. If no type hint is specified, MetaTypeUnknown is returned.

func (*Meta) Write

func (m *Meta) Write(w io.Writer) (int, error)

Write writes a zettel meta to a writer.

func (*Meta) WriteAsHeader

func (m *Meta) WriteAsHeader(w io.Writer) (int, error)

WriteAsHeader writes the zettel meta to the writer, plus the separators

type MetaPair

type MetaPair struct {
	Key   string
	Value string
}

MetaPair is one key-value-pair of a Zettel meta.

type Zettel

type Zettel struct {
	Meta    *Meta   // Some additional meta-data.
	Content Content // The content of the zettel itself.
}

Zettel is the main data object of a zettelstore.

func (Zettel) Equal

func (z Zettel) Equal(o Zettel) bool

Equal compares two zettel for equality.

type ZettelID

type ZettelID string

ZettelID is the identification of a zettel. Typically, it is a time stamp in the form "YYYYMMDDHHmmSS". The store tries to set the last two digits to "00".

func NewZettelID

func NewZettelID(withSeconds bool) ZettelID

NewZettelID returns a new zettel ID based on the current time.

func (ZettelID) IsValid

func (id ZettelID) IsValid() bool

IsValid returns true, the the zettel id is a valid string.

Jump to

Keyboard shortcuts

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