godoc'd the source
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
// Package ui holds the support for the Amsterdam user interface, wrapping Echo and Jet templates.
|
||||
package ui
|
||||
|
||||
import (
|
||||
@@ -16,6 +18,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// AmContext is the interface for Amsterdam's wapper context that exposes the required functionality.
|
||||
type AmContext interface {
|
||||
RC() int
|
||||
OutputType() string
|
||||
@@ -27,6 +30,7 @@ type AmContext interface {
|
||||
VarMap() jet.VarMap
|
||||
}
|
||||
|
||||
// amContext is the internal structure that implements AmContext.
|
||||
type amContext struct {
|
||||
echoContext echo.Context
|
||||
httprc int
|
||||
@@ -34,18 +38,33 @@ type amContext struct {
|
||||
outputType string
|
||||
}
|
||||
|
||||
// RC returns the HTTP result code for the current operation.
|
||||
func (c *amContext) RC() int {
|
||||
return c.httprc
|
||||
}
|
||||
|
||||
// OutputType returns the MIME output type set for the current operation.
|
||||
func (c *amContext) OutputType() string {
|
||||
return c.outputType
|
||||
}
|
||||
|
||||
/* Render renders a template to the output. Called at the top level only.
|
||||
* Parameters:
|
||||
* name = The name of the tempate to be rendered.
|
||||
* Returns:
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func (c *amContext) Render(name string) error {
|
||||
return c.echoContext.Render(c.httprc, name, c)
|
||||
}
|
||||
|
||||
/* SubRender renders a subtemplate to the output.
|
||||
* Parameters:
|
||||
* name = The name of the template to be rendered.
|
||||
* Returns:
|
||||
* Byte array with the rendered data to be output
|
||||
* Standard Go error status
|
||||
*/
|
||||
func (c *amContext) SubRender(name string) ([]byte, error) {
|
||||
view, err := views.GetTemplate(name)
|
||||
if err != nil {
|
||||
@@ -56,22 +75,32 @@ func (c *amContext) SubRender(name string) ([]byte, error) {
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
// SetOutputType sets the MIME output type for the current operation.
|
||||
func (c *amContext) SetOutputType(typ string) {
|
||||
c.outputType = typ
|
||||
}
|
||||
|
||||
// SetRC sets the HTTP result code for the current operation.
|
||||
func (c *amContext) SetRC(rc int) {
|
||||
c.httprc = rc
|
||||
}
|
||||
|
||||
// URLPath returns the path component of the request URL.
|
||||
func (c *amContext) URLPath() string {
|
||||
return c.echoContext.Request().URL.Path
|
||||
}
|
||||
|
||||
// VarMap provides access to the Jet variable map for setting variable data.
|
||||
func (c *amContext) VarMap() jet.VarMap {
|
||||
return c.rendervars
|
||||
}
|
||||
|
||||
/* NewAmContext creates a new AmContext wrapping the Echo context.
|
||||
* Parameters:
|
||||
* ctxt - The Echo context to be wrapped.
|
||||
* Returns:
|
||||
* A new Amsterdam context wrapping that context.
|
||||
*/
|
||||
func NewAmContext(ctxt echo.Context) AmContext {
|
||||
rc := amContext{
|
||||
echoContext: ctxt,
|
||||
@@ -83,6 +112,12 @@ func NewAmContext(ctxt echo.Context) AmContext {
|
||||
return &rc
|
||||
}
|
||||
|
||||
/* AmContextFromEchoContext returns the AmContext associated with an Echo context.
|
||||
* Parameters:
|
||||
* ctxt - The Echo context to have the AmContext extracted.
|
||||
* Returns:
|
||||
* The associated AmContext, or nil if there is none.
|
||||
*/
|
||||
func AmContextFromEchoContext(ctxt echo.Context) AmContext {
|
||||
myctxt := ctxt.Get("amsterdam_context")
|
||||
if myctxt != nil {
|
||||
|
||||
Reference in New Issue
Block a user