models

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAppName   = "notya"
	SettingsName     = ".settings.json"
	DefaultEditor    = "vi"
	DefaultLocalPath = "notya"
)

Constant values of settings.

Variables

View Source
var (
	// Early defined pretties.
	NotePretty   = ""
	FolderPretty = ""
)
View Source
var NotyaIgnoreFiles []string = []string{
	SettingsName,
	".DS_Store",
	".git",
}

NotyaIgnoreFiles are those files that shouldn't be represented as note files.

Functions

func CollectPath

func CollectPath(splitted []string) string

CollectPath is reversed implementation of SplitPath, which collects the fields that is splitted via SplitPath function.

func PrettyFromEntry

func PrettyFromEntry(e os.DirEntry) string

PrettyFromEntry generates a pretty icon appropriate to provided entry.

func SplitPath

func SplitPath(str string) []string

Split splits the path to fields by char:'/'

Types

type EditNode

type EditNode struct {
	Current Node `json:"current"`
	New     Node `json:"new"`
}

EditNote is wrapper structure used to store two new/current nodes.

type Folder

type Folder struct {
	// Title is the name(not path) of "current" folder.
	Title string `json:"title"`

	// Path is the full-path string name of "current" folder.
	Path map[string]string `json:"path"`
}

Folder is a w-directory representation data structure.

EXAMPLE:

╭───────────────╮ │ ~/notya-path/ │ │───────────────╯ │─ new_note.txt │─ todo/ ◀──── Sub directory of main notes folder. │ │── today.md │ │── tomorrow.md │ ╰── insolite-notya/ ◀── Sub directory of "todo" folder. │ │── issues.txt │ ╰── features.txt │─ ted-talks.tx ╰─ psyco.txt

func (*Folder) GetPath

func (f *Folder) GetPath(service string) string

GetPath returns exact path of provided service. If path for provided service doesn't exists result will be empty string.

func (*Folder) ToNode

func (n *Folder) ToNode() Node

ToNode converts Folder model to Node model.

type Node

type Node struct {
	// Type represents the exact type of current node.
	// It can be `file` or `folder`.
	Type NodeType `json:"typ"`

	// Title is the name(not path) of "current" node.
	Title string `json:"title"`

	// Path is the full-path string name of "current" node.
	Path map[string]string `json:"path"`

	// A field representation of [Note]'s [Body].
	Body string `json:"body,omitempty"`

	// Pretty is Title but powered with ascii emojis.
	// Shouldn't used as a production field.
	Pretty []string `json:"pretty,omitempty"`
}

Node is general purpose data object that used as abstract of Folder and Note structure models.

func (*Node) FromJson

func (s *Node) FromJson(data map[string]interface{}) error

FromJson converts provided map data to Node structure.

func (*Node) GenPretty

func (s *Node) GenPretty() string

GenPretty generates default pretty ASCII icon based on pointed node's type.

func (*Node) GetPath

func (n *Node) GetPath(service string) string

GetPath returns exact path of provided service. If path for provided service doesn't exists result will be empty string.

func (*Node) IsFile

func (n *Node) IsFile() bool

func (*Node) IsFolder

func (n *Node) IsFolder() bool

func (*Node) RebuildParent

func (n *Node) RebuildParent(parentCurrent, parentNew Node, service string, s Settings) *Node

RebuildParent updates the parent(s) of node in [Title] and [Path].

func (*Node) ToFolder

func (n *Node) ToFolder() Folder

ToFile converts Node object to Folder.

func (*Node) ToJSON

func (s *Node) ToJSON() map[string]interface{}

ToJSON converts node structure model to map value.

func (*Node) ToNote

func (n *Node) ToNote() Note

ToNote converts Node object to Note.

func (*Node) UpdatePath

func (n *Node) UpdatePath(service, path string) *Node

UpdatePath updates concrete [service]'s path with path.

type NodeType

type NodeType string

NodeType is custom string wrapper to represent node's type.

var (
	FILE   NodeType = "FILE"
	FOLDER NodeType = "FOLDER"
)

type Note

type Note struct {
	Title string            `json:"title"`
	Path  map[string]string `json:"path"`
	Body  string            `json:"body"`
}

Note is the main note model of application.

Example:

╭─────────────────────────────────────────────╮ │ Title: new_note.txt │ │ Path: /User/random-user/notya/new_note.txt │ │ Body: ... Note content here ... │ ╰─────────────────────────────────────────────╯

func (*Note) GetPath

func (n *Note) GetPath(service string) string

GetPath returns exact path of provided service. If path for provided service doesn't exists result will be empty string.

func (*Note) ToJSON

func (s *Note) ToJSON() map[string]interface{}

ToJSON converts string note structure model to map value.

func (*Note) ToNode

func (n *Note) ToNode() Node

ToNode converts Note model to Node model.

type Settings

type Settings struct {
	// Alert: development related field, shouldn't be used in production.
	ID string `json:",omitempty"`

	// The custom name of your notya application.
	Name string `json:"name" default:"notya"`

	// Editor app of application.
	// Could be:
	//   - vi
	//   - vim
	//   - nvim
	//   - code
	//   - code-insiders
	//  and etc. shortly each code editor that could be opened by its command.
	//  like: `code .` or `nvim .`.
	Editor string `json:"editor" default:"vi"`

	// Local "notes" folder path for notes, independently from [~/notya/] folder.
	// Must be given full path, like: "./User/john-doe/.../my-notya-notes/"
	//
	// Does same job as [FirebaseCollection] for local env.
	NotesPath string `json:"notes_path" mapstructure:"notes_path" survey:"notes_path"`

	// The project id of your firebase project.
	//
	// It is required for firebase remote connection.
	FirebaseProjectID string `json:"fire_project_id,omitempty" mapstructure:"fire_project_id,omitempty" survey:"fire_project_id"`

	// The path of key of "firebase-service" account file.
	// Must be given full path, like: "./User/john-doe/.../..."
	//
	// It is required for firebase remote connection.
	FirebaseAccountKey string `json:"fire_account_key,omitempty" mapstructure:"fire_account_key,omitempty" survey:"fire_account_key"`

	// The concrete collection of nodes.
	// Does same job as [NotesPath] but has to take just name of collection.
	FirebaseCollection string `json:"fire_collection,omitempty" mapstructure:"fire_collection,omitempty" survey:"fire_collection"`
}

Settings is a main structure model of application settings.

Example:

╭────────────────────────────────────────────────────╮ │ Name: notya │ │ Editor: vi │ │ Notes Path: /User/random-user/notya/notes │ │ Firebase Project ID: notya-98tf3 │ │ Firebase Account Key: /User/.../notya/key.json │ │ Firebase Collection: notya-notes │ ╰────────────────────────────────────────────────────╯

func DecodeSettings

func DecodeSettings(value string) Settings

DecodeSettings converts string(map) value to Settings structure.

func InitSettings

func InitSettings(notesPath string) Settings

InitSettings returns default variant of settings structure model.

func (*Settings) CopyWith

func (s *Settings) CopyWith(
	ID *string,
	Name *string,
	Editor *string,
	NotesPath *string,
	FirebaseProjectID *string,
	FirebaseAccountKey *string,
	FirebaseCollection *string,
) Settings

CopyWith updates pointed settings with a new data. if given argument is not nil, it will be overwritten inside pointed settings model.

func (*Settings) FirePath

func (s *Settings) FirePath() string

FirePath returns valid firebase collection name.

func (*Settings) IsValid

func (s *Settings) IsValid() bool

IsValid checks validness of settings structure.

func (*Settings) ToJSON

func (s *Settings) ToJSON() map[string]interface{}

ToJSON converts string structure model to map value.

func (*Settings) ToString

func (s *Settings) ToString() string

ToString converts settings model to a formatted JSON string,

type StdArgs

type StdArgs struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

StdArgs is a global std state model for application. Makes is easy to test functionalities by specifying std state.

Jump to

Keyboard shortcuts

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