Documentation ¶
Overview ¶
Package room provides a tool to compile and build HTML pages out of data structures defined here.
Index ¶
- Constants
- func CompileStyles(styles map[string]string, css *PageCSS) (classes []string)
- func ElementOpenTag(tagName string, idAttr string, classes []string, buf *bytes.Buffer)
- func WriteClassAttr(classes []string, b *bytes.Buffer)
- func WriteIdAttr(id string, b *bytes.Buffer)
- type Column
- func (*Column) Descriptor() ([]byte, []int)
- func (m *Column) GetModules() []*Module
- func (*Column) ProtoMessage()
- func (m *Column) Reset()
- func (m *Column) String() string
- func (m *Column) XXX_DiscardUnknown()
- func (m *Column) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Column) XXX_Merge(src proto.Message)
- func (m *Column) XXX_Size() int
- func (m *Column) XXX_Unmarshal(b []byte) error
- type Common
- func (*Common) Descriptor() ([]byte, []int)
- func (m *Common) GetClasses() []string
- func (m *Common) GetIdAttr() string
- func (m *Common) GetOptions() map[string]string
- func (m *Common) GetStyles() map[string]string
- func (m *Common) GetType() string
- func (*Common) ProtoMessage()
- func (m *Common) Reset()
- func (m *Common) String() string
- func (m *Common) XXX_DiscardUnknown()
- func (m *Common) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Common) XXX_Merge(src proto.Message)
- func (m *Common) XXX_Size() int
- func (m *Common) XXX_Unmarshal(b []byte) error
- type DataStore
- type Datum
- type ErrMissingModuleBuilder
- type ErrMissingModuleCompiler
- type Module
- func (*Module) Descriptor() ([]byte, []int)
- func (m *Module) GetData() []byte
- func (m *Module) GetDyn() int64
- func (m *Module) GetType() string
- func (*Module) ProtoMessage()
- func (m *Module) Reset()
- func (m *Module) String() string
- func (m *Module) XXX_DiscardUnknown()
- func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Module) XXX_Merge(src proto.Message)
- func (m *Module) XXX_Size() int
- func (m *Module) XXX_Unmarshal(b []byte) error
- type ModuleBuilder
- type ModuleCompiler
- type ModuleCustomizer
- type PageCSS
- type Row
- func (*Row) Descriptor() ([]byte, []int)
- func (m *Row) GetColumns() []*Column
- func (m *Row) GetCommon() *Common
- func (m *Row) GetDyn() int64
- func (m *Row) GetHtml() []byte
- func (*Row) ProtoMessage()
- func (m *Row) Reset()
- func (m *Row) String() string
- func (m *Row) XXX_DiscardUnknown()
- func (m *Row) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Row) XXX_Merge(src proto.Message)
- func (m *Row) XXX_Size() int
- func (m *Row) XXX_Unmarshal(b []byte) error
- type Section
- func (*Section) Descriptor() ([]byte, []int)
- func (m *Section) GetCommon() *Common
- func (m *Section) GetDyn() int64
- func (m *Section) GetHtml() []byte
- func (m *Section) GetRows() []*Row
- func (*Section) ProtoMessage()
- func (m *Section) Reset()
- func (m *Section) String() string
- func (m *Section) XXX_DiscardUnknown()
- func (m *Section) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Section) XXX_Merge(src proto.Message)
- func (m *Section) XXX_Size() int
- func (m *Section) XXX_Unmarshal(b []byte) error
- type Tree
- func (t *Tree) BuildHTML(ds DataStore, mc ModuleCustomizer, compiled *Module, page *bytes.Buffer, ...) error
- func (t *Tree) Compile(ds DataStore, mc ModuleCustomizer, m *Module, css *PageCSS) (*Module, error)
- func (*Tree) Descriptor() ([]byte, []int)
- func (t *Tree) DynamicDataIDs() []int64
- func (m *Tree) GetSections() []*Section
- func (*Tree) ProtoMessage()
- func (m *Tree) Reset()
- func (m *Tree) String() string
- func (m *Tree) XXX_DiscardUnknown()
- func (m *Tree) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Tree) XXX_Merge(src proto.Message)
- func (m *Tree) XXX_Size() int
- func (m *Tree) XXX_Unmarshal(b []byte) error
Constants ¶
const ( // ColumnOpen is the tag that opens a column. ColumnOpen = `<div class="room-col">` // ColumnClose is the tag that closes a column. ColumnClose = "</div>" )
const RowTagName = "div"
RowTagName is the HTML tag name given to Row elements.
const SectionTagName = "section"
SectionTagName is the HTML tag name given to Section elements.
const StaticElementType = "_static"
StaticElementType is the Type given to those Section, Row, and Module elements whose final HTML form is known after compilation.
const TreeType = "room_tree"
TreeType is the Type given to the Module elements that contain a Tree in the Data.
Variables ¶
This section is empty.
Functions ¶
func CompileStyles ¶
CompileStyles writes CSS code out to the css buffer and gives a list of additional classes the element being processed should be given. The styles map has CSS property keys and values, though most keys are shortened, not standard CSS property names.
func ElementOpenTag ¶
ElementOpenTag writes to buf an opening HTML tag.
func WriteClassAttr ¶
WriteClassAttr checks if classes is not empty, and if it's not empty this function writes to the buffer the string ` class="classes given"` where "classes given" is the classes argument's values joined by a space.
func WriteIdAttr ¶
WriteIdAttr checks if id is not an empty string, and if it's not empty this function writes to the buffer the string ` id="id-given"` where "id-given" is the id argument.
Types ¶
type Column ¶
type Column struct { Modules []*Module `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Column) Descriptor ¶
func (*Column) GetModules ¶
func (*Column) ProtoMessage ¶
func (*Column) ProtoMessage()
func (*Column) XXX_DiscardUnknown ¶
func (m *Column) XXX_DiscardUnknown()
func (*Column) XXX_Marshal ¶
func (*Column) XXX_Unmarshal ¶
type Common ¶
type Common struct { // Type indicates the broad type of the structure. Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // IdAttr is the user's custom ID attribute for the element. IdAttr string `protobuf:"bytes,2,opt,name=id_attr,json=idAttr,proto3" json:"id_attr,omitempty"` // Classes is the user's custom classes. // For compiled sections and rows, this includes classes added by module compilers for styling. Classes []string `protobuf:"bytes,3,rep,name=classes,proto3" json:"classes,omitempty"` // Styles is the user's styles for the row. Styles map[string]string `` /* 153-byte string literal not displayed */ // Options contains additional options. Options map[string]string `` /* 155-byte string literal not displayed */ XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
Common is a data structure commonly used in this package in various other types.
func (*Common) Descriptor ¶
func (*Common) GetClasses ¶
func (*Common) GetOptions ¶
func (*Common) ProtoMessage ¶
func (*Common) ProtoMessage()
func (*Common) XXX_DiscardUnknown ¶
func (m *Common) XXX_DiscardUnknown()
func (*Common) XXX_Marshal ¶
func (*Common) XXX_Unmarshal ¶
type DataStore ¶
type DataStore interface { // Store saves the Data field of a Datum in a data store and returns the ID it was given. Store([]byte) (int64, error) // Get retrieves a single Datum. This function may be called repeatedly with a single ID throughout the // compiling of a Tree or building of a CompiledTree, so all data already queried should be cached for // efficient access. Get(int64) (*Datum, error) // GetMulti retrieves the Datum entities identified by their IDs. GetMulti([]int64) ([]Datum, error) }
A DataStore represents a database: it is able to save Datum entities and retrieve them by ID. An instance of a DataStore should cache internally the Datum entities already retrieved.
type Datum ¶
A Datum represents a generic container in which the dynamic data for a Section, Row, or Module may be saved. The Id of each Datum is a unique identifier.
type ErrMissingModuleBuilder ¶
type ErrMissingModuleBuilder struct {
*Module
}
ErrMissingModuleBuilder is an error type that reports that a ModuleCompiler could not be found to compile a particular Module.
func (ErrMissingModuleBuilder) Error ¶
func (em ErrMissingModuleBuilder) Error() string
Error implements the error interface for ErrMissingModuleBuilder.
type ErrMissingModuleCompiler ¶
type ErrMissingModuleCompiler struct {
*Module
}
ErrMissingModuleCompiler is an error type that reports that a ModuleCompiler could not be found to compile a particular Module.
func (ErrMissingModuleCompiler) Error ¶
func (em ErrMissingModuleCompiler) Error() string
Error implements the error interface for ErrMissingModuleCompiler.
type Module ¶
type Module struct { // Type indicates broadly the kind of module that this is. It is used to identify what ModuleCompiler or // ModuleBuilder to use. Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // Dyn is the ID of the record holding the module's dynamic settings. Using the Dyn field is optional for // each module type, but if it is non-zero then it must be the ID of the Datum entity which holds the // dynamic settings. (This requirement is intended to make it possible to get all of the data for the // entire page tree with a single query before the page is built.) Dyn int64 `protobuf:"varint,2,opt,name=dyn,proto3" json:"dyn,omitempty"` // Data contains all of the configuration data needed for the module. The data can be encoded in any // format, and it's up to the corresponding ModuleCompiler and ModuleBuilder to be able to decode it. // // When a Module is compiled, if Compile returns true then Data must already contain all the pre-built // HTML. Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
A Module represents the smallest unit of composition that appears as an element in the HTML of a page. We know how to deal with the Data field when we know the Type and have a matching ModuleCompiler to compile it or a matching ModuleBuilder to build its final HTML.
A compiled module may be fully static and ready to be written out to the page without building, in which case the data contains the final HTML and the type is "_static".
func (*Module) Descriptor ¶
func (*Module) ProtoMessage ¶
func (*Module) ProtoMessage()
func (*Module) XXX_DiscardUnknown ¶
func (m *Module) XXX_DiscardUnknown()
func (*Module) XXX_Marshal ¶
func (*Module) XXX_Unmarshal ¶
type ModuleBuilder ¶
type ModuleBuilder interface { // BuildHTML writes to the Buffer the HTML output of the Module. The CSS for the module that should be used // with the page is written to the PageCSS buffer. BuildHTML(DataStore, ModuleCustomizer, *Module, *bytes.Buffer, *PageCSS) error }
A ModuleBuilder is able to build out the HTML of a Module. Each Module will be built dynamically upon each request to display if it is not built out into its final static form at compile time.
type ModuleCompiler ¶
type ModuleCompiler interface { // Compile compiles a Module. The Type field of the returned *Module must be StaticElementType if the compiled module // can be saved as is, using the Data field as the pre-built HTML not needing any building. // // A ModuleCustomizer is passed in to make recursive Tree compilation possible. // // The *Module passed in points to the same Module that the ModuleCustomizer got at first. Compile can decode the // Data field as needed. // // As much of the CSS as possible should be written out to PageCSS at compile time. Compile(DataStore, ModuleCustomizer, *Module, *PageCSS) (*Module, error) }
A ModuleCompiler compiles a Module as much as possible to minimize building HTML upon requests to display the module.
type ModuleCustomizer ¶
type ModuleCustomizer interface { // GetModuleCompiler returns a ModuleCompiler to customize the way a Module is compiled. // This function should not unmarshall the Data field in the Module because the same Module will be passed in // to the ModuleCompiler's Compile method. GetModuleCompiler(*Module) ModuleCompiler // GetModuleBuilder returns a ModuleBuilder to customize the HTML output of a Module. // This function should not unmarshall the Data field in the Module because the same Module will be passed in // to the ModuleBuilder's BuildHTML method. GetModuleBuilder(*Module) ModuleBuilder }
A ModuleCustomizer is able to customize what ModuleCompiler is used to compile a Module and what ModuleBuilder is used to build its HTML.
type PageCSS ¶
PageCSS embeds the bytes.Buffer type and contains the state of the CSS on the page, which is a record of the modules that have written their CSS to the page. Before a module writes anything to a PageCSSState, it should first check if another module of the same type in the Tree has already written the same CSS.
After the compilation of a Tree, if PageCSS turns out to be not empty then it should be stored and passed in to the Tree upon building.
func (*PageCSS) IsWritten ¶
IsWritten says if a module with the given type has already written its CSS to the page.
func (*PageCSS) ProtoMessage ¶
ProtoMessage returns a proto.Message that can be used to The concrete type of the message is special.PageCSS.
func (*PageCSS) RecordWriting ¶
RecordWriting records that a module with the given type just now wrote its CSS to the page.
func (*PageCSS) UnmarshalProto ¶
UnmarshalProto reads the Protocol Buffers encoded message into the internal data structure. The struct is first reset.
type Row ¶
type Row struct { // Common includes common fields. The Type is the column layout type of the row. Common *Common `protobuf:"bytes,1,opt,name=common,proto3" json:"common,omitempty"` // Dyn is the ID of the row's dynamic settings, if not zero. Dyn int64 `protobuf:"varint,2,opt,name=dyn,proto3" json:"dyn,omitempty"` // Columns contains the row's columns. For compiled Rows, this field is not empty only if there is content // within the row that is dynamic. Columns []*Column `protobuf:"bytes,3,rep,name=columns,proto3" json:"columns,omitempty"` // Html is used only for compiled rows when the entire row is static HTML. Html []byte `protobuf:"bytes,4,opt,name=html,proto3" json:"html,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
A Row holds the settings of both static and dynamic page rows. Directly within a Row are columns. A compiled Row only needs to be built, along with everything it contains, to be displayed.
func (*Row) Descriptor ¶
func (*Row) GetColumns ¶
func (*Row) ProtoMessage ¶
func (*Row) ProtoMessage()
func (*Row) XXX_DiscardUnknown ¶
func (m *Row) XXX_DiscardUnknown()
func (*Row) XXX_Unmarshal ¶
type Section ¶
type Section struct { // Common includes common fields. The Type must be either "standard" or "full". Common *Common `protobuf:"bytes,1,opt,name=common,proto3" json:"common,omitempty"` // Dyn is the ID of the section's dynamic settings, if not zero. Dyn int64 `protobuf:"varint,2,opt,name=dyn,proto3" json:"dyn,omitempty"` // Rows contains the section's rows. Rows []*Row `protobuf:"bytes,3,rep,name=rows,proto3" json:"rows,omitempty"` // Html is used only for compiled rows when the entire row is static HTML. Html []byte `protobuf:"bytes,4,opt,name=html,proto3" json:"html,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
A Section holds the settings of a section in a Tree. Within a Section are Row elements. A compiled Section only needs to be built, along with everything it contains, to be displayed.
func (*Section) Descriptor ¶
func (*Section) ProtoMessage ¶
func (*Section) ProtoMessage()
func (*Section) XXX_DiscardUnknown ¶
func (m *Section) XXX_DiscardUnknown()
func (*Section) XXX_Marshal ¶
func (*Section) XXX_Unmarshal ¶
type Tree ¶
type Tree struct { Sections []*Section `protobuf:"bytes,1,rep,name=sections,proto3" json:"sections,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
A Tree represents the structure of a page. Each Section within a Tree may contain Row elements, which contain Column elements, which contain Module elements.
Tree implements the ModuleCompiler and ModuleBuilder interfaces, so a Tree can be nested as a Module.
A compiled Tree represents the structure of a compiled page, though some elements may need to be compiled dynamically. Each compiled Section within a Tree contains compiled Row elements, each of which may in turn contain Column elements with compiled Module elements.
func (*Tree) BuildHTML ¶
func (t *Tree) BuildHTML(ds DataStore, mc ModuleCustomizer, compiled *Module, page *bytes.Buffer, css *PageCSS) error
BuildHTML implements ModuleBuilder for Tree. This function writes the built HTML to the page buffer. The Data field of the compiled Module is unmarshalled and used to construct the Tree.
func (*Tree) Compile ¶
Compile takes the contents of the Tree and compiles all sections, rows, and modules as much as possible, the remaining elements left to being built dynamically at the time a page is requested.
The m.Data field is unmarshalled and used to construct the Tree.
func (*Tree) Descriptor ¶
func (*Tree) DynamicDataIDs ¶
DynamicDataIDs returns the IDs of the Datum entities that contain the dynamic settings for this Tree.
func (*Tree) GetSections ¶
func (*Tree) ProtoMessage ¶
func (*Tree) ProtoMessage()
func (*Tree) XXX_DiscardUnknown ¶
func (m *Tree) XXX_DiscardUnknown()
func (*Tree) XXX_Unmarshal ¶
Directories ¶
Path | Synopsis |
---|---|
Package roomutil provides a few utility functions and types for changing a room.Tree structure.
|
Package roomutil provides a few utility functions and types for changing a room.Tree structure. |
sample
Package sample has sample Tree structures useful for testing.
|
Package sample has sample Tree structures useful for testing. |