Documentation ¶
Index ¶
- Constants
- func ForEachTag(node *lhtml.HtmlNode, model *Model, evaluator *Evaluator) error
- func GetVariableTag(node *lhtml.HtmlNode, model *Model, evaluator *Evaluator) error
- func IfElseTag(node *lhtml.HtmlNode, model *Model, evaluator *Evaluator) error
- func SetVariableTag(node *lhtml.HtmlNode, model *Model, evaluator *Evaluator) error
- type CustomTagProcessor
- type Evaluator
- func (evaluator *Evaluator) EvaluateExpression(expr string, model *Model) (interface{}, error)
- func (evaluator *Evaluator) EvaluateExpressionAsString(expr string, model *Model) (string, error)
- func (evaluator *Evaluator) EvaluateNode(node *lhtml.HtmlNode, model *Model) error
- func (evaluator *Evaluator) EvaluateNodes(nodes []*lhtml.HtmlNode, model *Model) error
- func (evaluator *Evaluator) GetAttributeValue(node *lhtml.HtmlNode, attributeName string, model *Model) (interface{}, error)
- func (evaluator *Evaluator) GetAttributeValueAsString(node *lhtml.HtmlNode, attributeName string, model *Model) (string, error)
- func (evaluator *Evaluator) GetEvaluation() string
- func (evaluator *Evaluator) Write(b []byte) (int, error)
- func (evaluator *Evaluator) WriteByte(b byte) error
- func (evaluator *Evaluator) WriteRune(r rune) (int, error)
- func (evaluator *Evaluator) WriteString(s string) (int, error)
- type HtmlPageProcessor
- func (pageProcessor *HtmlPageProcessor) AddCustomTag(name string, tagProcessor CustomTagProcessor) (bool, error)
- func (pageProcessor *HtmlPageProcessor) GetCustomTag(name string) (CustomTagProcessor, bool)
- func (pageProcessor *HtmlPageProcessor) HasCustomTag(name string) bool
- func (pageProcessor *HtmlPageProcessor) Merge(elements *lhtml.HtmlElements, model *Model) (string, error)
- func (pageProcessor *HtmlPageProcessor) MergeHtml(html string, model *Model) (string, error)
- func (pageProcessor *HtmlPageProcessor) RemoveCustomTag(name string) (bool, error)
- type Model
- func (model *Model) Clear()
- func (model *Model) Get(key string) (interface{}, bool)
- func (model *Model) GetBool(key string, defaultValue bool) bool
- func (model *Model) GetFloat64(key string, defaultValue float64) float64
- func (model *Model) GetInt64(key string, defaultValue int64) int64
- func (model *Model) GetMap() map[string]interface{}
- func (model *Model) GetString(key string, defaultValue string) string
- func (model *Model) GetUInt64(key string, defaultValue uint64) uint64
- func (model *Model) IsEmpty() bool
- func (model *Model) Put(key string, value interface{})
- func (model *Model) PutIfNotExists(key string, value interface{}) bool
- func (model *Model) Remove(key string)
- func (model *Model) Replace(key string, value interface{}) bool
- func (model *Model) Size() int
Constants ¶
const PREFIX = "expr:"
Variables ¶
This section is empty.
Functions ¶
func ForEachTag ¶
A for-each tag that takes in a `collection` and then adds it as the given variable name. If the collection is a `slice` the variable gets one collection object at a time.
<foreach collection="mySlice" item="sliceItem"> <get var="sliceItem" /> </foreach>
If the collection is a `map` the variable gets an object that contains two properties: `key` and `value` representing the key/value pair for each entry in the map.
<foreach collection="myMap" item="mapItem"> <get var="mapItem.key" /> <get var="mapItem.value" /> </foreach>
func GetVariableTag ¶
A simple tag to get the value of any variable inside the model.
<get value="name" />
func IfElseTag ¶
A simple if-else tag.
<custom:if condition="age > 10"> <custom:then> </custom:then> </custom:else> </custom:else> </custom:if>
func SetVariableTag ¶
You can use it in two ways. For a self-closing tag, the model will be modified immediately and any older value will not be preserved. For example, the variable `hello` is set to `world` for the rest of processing.
<setVar var="hello" value="world" />
Another way is to use children, in which case the older value (if any) will be restored at the closing of tag. In the following example, the value of variable `hello` is only available to the children of the `setVar` node.
<setVar var="hello" value="world"> ... </setVar>
Types ¶
type CustomTagProcessor ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
The Evaluator instance.
func (*Evaluator) EvaluateExpression ¶
Evaluate an expression against the model.
func (*Evaluator) EvaluateExpressionAsString ¶
Evaluate an expression against the model and return resulting value as a `string` using default platform conversion.
func (*Evaluator) EvaluateNode ¶
Evaluate the given node against the model.
func (*Evaluator) EvaluateNodes ¶
Evaluate multiple nodes against the model.
func (*Evaluator) GetAttributeValue ¶
func (evaluator *Evaluator) GetAttributeValue(node *lhtml.HtmlNode, attributeName string, model *Model) (interface{}, error)
Get an attribute's value from the node. It also checks if an expression attribute with same name is present, and if yes, if will evalue the expression and return the value.
func (*Evaluator) GetAttributeValueAsString ¶
func (*Evaluator) GetEvaluation ¶
type HtmlPageProcessor ¶
type HtmlPageProcessor struct {
// contains filtered or unexported fields
}
The main interface that allows you to add custom tag processors and then use this instance to merge HTML templates.
func NewHtmlPageProcessor ¶
func NewHtmlPageProcessor() *HtmlPageProcessor
Create a new instance of HTML page processor.
func (*HtmlPageProcessor) AddCustomTag ¶
func (pageProcessor *HtmlPageProcessor) AddCustomTag(name string, tagProcessor CustomTagProcessor) (bool, error)
Add a custom tag to the processor which will make use of the provided `func` to work upon. The tag name is case insensitive. If a tag with the same name already exists, an error is returned.
func (*HtmlPageProcessor) GetCustomTag ¶
func (pageProcessor *HtmlPageProcessor) GetCustomTag(name string) (CustomTagProcessor, bool)
Return the custom tag processor attached for the given name. If the name is empty or blank, a `nil` is returned.
func (*HtmlPageProcessor) HasCustomTag ¶
func (pageProcessor *HtmlPageProcessor) HasCustomTag(name string) bool
Check if a custom tag processor is attached for the given name.
func (*HtmlPageProcessor) Merge ¶
func (pageProcessor *HtmlPageProcessor) Merge(elements *lhtml.HtmlElements, model *Model) (string, error)
Merge given parsed HTML document with the given model.
func (*HtmlPageProcessor) MergeHtml ¶
func (pageProcessor *HtmlPageProcessor) MergeHtml(html string, model *Model) (string, error)
Merge given HTML string with the given model.
func (*HtmlPageProcessor) RemoveCustomTag ¶
func (pageProcessor *HtmlPageProcessor) RemoveCustomTag(name string) (bool, error)
Remove a custom tag with given name. An error is returned if the name is empty, or blank. No error is returned if no custom tag processor can be found attached to this name.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Represents a model of values that are used to merge with a page or a fragment.
func (*Model) GetBool ¶
Get a `bool` value for a key from the model, or the default value if the key does not exist, or is not a `bool`.
func (*Model) GetFloat64 ¶
Get a `float64` value for a key from the model, or the default value if the key does not exist, or is not a `float64`.
func (*Model) GetInt64 ¶
Get a `int64` value for a key from the model, or the default value if the key does not exist, or is not a `int64`.
func (*Model) GetString ¶
Get a `string` value for a key from the model, or the default value if the key does not exist, or is not a `string`.
func (*Model) GetUInt64 ¶
Get a `uint64` value for a key from the model, or the default value if the key does not exist, or is not a `uint64`.
func (*Model) IsEmpty ¶
Check if model is empty or not. Returns `true` if there are no keys in model, `false` otherwise.
func (*Model) PutIfNotExists ¶
Put the value in model if the key does not exist. Returns `true` if value was added to model, `false` otherwise.