data

package
v0.0.0-...-917641f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package data impleements data structures for use with rich text

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockQuote

type BlockQuote struct {
	Text *rich.Text
}

BlockQuote represents a block quote with any embedded content

func (BlockQuote) Apply

Apply implements changes.Value.

func (BlockQuote) Name

func (bq BlockQuote) Name() string

Name is the key to use with rich.Attrs

type Col

type Col struct {
	ID    interface{}
	Ord   string
	Value *rich.Text
}

Col represents the information about the column.

The ID field is immutable. The Ord field is meant to help sort the columns and is not meant to be directly modified by the application. Instead, Table methods can be used to effectively manipulate these.

The value field tracks the actual heading/name for the column and should not be nil.

func (Col) Apply

func (col Col) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

type Cols

type Cols map[interface{}]*Col

Cols represents all the columns in the table

func (Cols) Apply

func (cols Cols) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

type Dir

type Dir struct {
	Root    changes.Value
	Objects types.M
}

Dir wraps a value along with a map of objects. The contents of the value can refer to entries in the map using Ref

func (*Dir) Apply

func (d *Dir) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements channges.Value

func (*Dir) Name

func (d *Dir) Name() string

Name returns the key name for use with Attrs

type FontStyle

type FontStyle string

FontStyle is CSS font-style

const (
	FontStyleNormal  FontStyle = "normal"
	FontStyleItalic  FontStyle = "italic"
	FontStyleOblique FontStyle = "oblique"
)

FontStyle values

func (FontStyle) Apply

Apply only accepts one type of change: one that Replace's the value.

func (FontStyle) Name

func (f FontStyle) Name() string

Name is the key to use within rich.Attrs

type FontWeight

type FontWeight int

FontWeight is CSS font-weight

const (
	FontThin FontWeight = 100 * (iota + 1)
	FontExtraLight
	FontLight
	FontNormal
	FontMedium
	FontSemibold
	FontBold
	FontExtraBold
	FontBlack
)

FontWeight constants

func (FontWeight) Apply

Apply only accepts one type of change: one that Replace's the value.

func (FontWeight) Name

func (f FontWeight) Name() string

Name is the key to use within rich.Attrs

type Heading

type Heading struct {
	Level int // 1 => 6
	*rich.Text
}

Heading represents h1 to h6.

Note that the contents of the heading tag can be any rich text.

func (Heading) Apply

func (h Heading) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value.

func (Heading) Name

func (h Heading) Name() string

Name is the key to use with rich.Attrs

type Image

type Image struct {
	Src     string
	AltText string
}

Image represents an image url

func (Image) Apply

func (i Image) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value.

func (Image) Name

func (i Image) Name() string

Name is the key to use with rich.Attrs

type Link struct {
	URL string
	changes.Value
}

Link represents a url link

func (Link) Apply

func (l Link) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value.

func (Link) Name

func (l Link) Name() string

Name is the key to use with rich.Attrs

type List

type List struct {
	Type    string
	Entries types.A
}

List represents an ordered or unordered list

The type can be one of the string values defined here: https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type

(such as disc, circle etc)

func (List) Apply

func (l List) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value.

func (List) Name

func (l List) Name() string

Name is the key to use with rich.Attrs

type Ref

type Ref struct {
	ID interface{}
}

Ref represents a refereence to an embedded object storeed in a Dir. The Dir must be an ancestor of the Ref

func (*Ref) Apply

func (r *Ref) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements channges.Value

func (*Ref) Name

func (r *Ref) Name() string

Name returns the key name for use with Attrs

type Row

type Row struct {
	ID    interface{}
	Ord   string
	Cells types.M
}

Row represents the information about a row

The ID field is immutable. The Ord field is meant to help sort the rows and is not meant to be directly modified by the application. Instead, Table methods can be used to effectively manipulate these.

The Cells field contains a map of Column.ID to actual cell value

func (Row) Apply

func (r Row) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

type Rows

type Rows map[interface{}]*Row

Rows represents all the rows in the table

func (Rows) Apply

func (rows Rows) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

type Table

type Table struct {
	Cols
	Rows
}

Table represents a table with named columns and rows

This is an immutable type and all mutation methods (like AppendCol) return changes.Change (which can be applied to get the new Table)

The rows and columns are stored in a map structure but ordered IDs can be obtained via RowIDs and ColIDs

Example
package main

import (
	"fmt"
	"strings"

	"github.com/dotchain/dot/x/rich"
	"github.com/dotchain/dot/x/rich/data"
)

func main() {
	t := &data.Table{}
	col1, col2 := rich.NewText("col1"), rich.NewText("col2")
	t = t.Apply(nil, t.AppendCol(data.Col{ID: "col2", Value: col2})).(*data.Table)
	t = t.Apply(nil, t.InsertColBefore(data.Col{ID: "col1", Value: col1}, *t.Cols["col2"])).(*data.Table)

	t = t.Apply(nil, t.AppendRow(data.Row{ID: "row1"})).(*data.Table)
	t = t.Apply(nil, t.SetCellValue("row1", "col1", rich.NewText("1-1"))).(*data.Table)
	t = t.Apply(nil, t.SetCellValue("row1", "col2", rich.NewText("1-2"))).(*data.Table)

	fmt.Println(tableToText(t))

}

func tableToText(t *data.Table) string {
	lines := []string{}
	colIDs := t.ColIDs()
	for _, rowID := range t.RowIDs() {
		cells := []string{}
		r := *t.Rows[rowID]
		for _, colID := range colIDs {
			cell := ""
			if v, ok := r.Cells[colID]; ok {
				cell = v.(*rich.Text).PlainText()
			}
			cells = append(cells, cell)
		}
		lines = append(lines, strings.Join(cells, " "))
	}
	return strings.Join(lines, "\n")
}
Output:

1-1 1-2

func (*Table) AppendCol

func (t *Table) AppendCol(col Col) changes.Change

AppendCol adds a new column to the end of the sorted list.

The column can already exist in which case it is simply moved.

func (Table) AppendRow

func (t Table) AppendRow(row Row) changes.Change

AppendRow adds a new row to the end of the sorted list.

The row can already exist in which case it is simply moved.

func (*Table) Apply

func (t *Table) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

func (*Table) ColIDs

func (t *Table) ColIDs() []interface{}

ColIDs returns all the column IDs sorted in order

func (*Table) DeleteCol

func (t *Table) DeleteCol(colID interface{}) changes.Change

DeleteCol deletes a column by ID

func (*Table) DeleteRow

func (t *Table) DeleteRow(rowID interface{}) changes.Change

DeleteRow deletes a row by ID

func (*Table) InsertColBefore

func (t *Table) InsertColBefore(col Col, beforeCol Col) changes.Change

InsertColBefore inserts a new column before another

The column may already exist in which case it is simply moved

func (*Table) InsertRowBefore

func (t *Table) InsertRowBefore(row Row, beforeRow Row) changes.Change

InsertRowBefore inserts a new row before another

The row may already exist in which case it is simply moved

func (*Table) Name

func (t *Table) Name() string

Name returns the key for use with rich text Attrs

func (*Table) RowIDs

func (t *Table) RowIDs() []interface{}

RowIDs returns all the row IDs sorted in order

func (Table) SetCellValue

func (t Table) SetCellValue(rowID, colID interface{}, r *rich.Text) changes.Change

SetCellValue sets the rich text for a cell. It works for rows which don't have values for specific columns as well as rows where the columns have a value already.

func (*Table) UpdateCellValue

func (t *Table) UpdateCellValue(rowID, colID interface{}, c changes.Change) changes.Change

UpdateCellValue takes a change meant for a cell value and wraps it with the path of the column -- the resulting change can be applied directly on the table.

Note that the cell must exist (i.e the row must have a entry for the colID)

func (Table) UpdateCol

func (t Table) UpdateCol(colID interface{}, c changes.Change) changes.Change

UpdateCol takes a change meant for a columm value and wraps it with the path of the column -- the resulting change can be applied directly on the table.

Jump to

Keyboard shortcuts

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