Documentation ¶
Overview ¶
The `babou` web application core
Provides library methods that are useful from many different layers in the `app` package.
If an appropriate solution exists in this package it should be preferred over a hand-rolled implementation. As they are designed to be fairly generic solutions that are fairly composable.
Index ¶
- Constants
- Variables
- func BuildForm(params []string, data string) string
- func DisableDirectoryListing(h http.Handler) http.HandlerFunc
- func EscapeString(in string) string
- func FileFor(params []string, data string) string
- func LabelFor(params []string, data string) string
- func LinkTo(params []string, data string) string
- func Render(controllerName, actionName string, viewData *ViewData) string
- func RenderIn(templateName, controllerName, actionName string, viewData *ViewData) string
- func RenderTo(templateName string, viewData *ViewData) string
- func RenderWith(templateName, controllerName, actionName string, filterHelpers ...interface{}) string
- func TextFieldFor(params []string, data string) string
- func UrlFor(params []string, data string) string
- type Action
- type AfterPhaseContext
- type ChainableContext
- type Controller
- type MustacheRenderer
- type Param
- type RedirectPath
- type Renderer
- type Result
- type ViewData
- type ViewableContext
Constants ¶
const DEBUG_RELOAD = false
Variables ¶
var Router *mux.Router = nil
A global router or middleware implementation that will service requests from the HTTP server and direct them to an appropriate controller
Functions ¶
func BuildForm ¶
Builds a form context and renders a sub-template inside of it.
Example: {{#FormFor (controller) (method) [enctype] (formId)} } {{ > app/views/users/register.template }} {{/FormFor}}
Where the register.template can now use any of the Form helpers.
func DisableDirectoryListing ¶
func DisableDirectoryListing(h http.Handler) http.HandlerFunc
Returns a 404 error if a user asks `babou` for the contents of a directory. Useful for serving static files.
func EscapeString ¶
func FileFor ¶
Generates an input for a file. The id defaults to the `name` property if it is omitted.
Example: {{#FileFor (name) [id]}} {{/FileFor}}
func LabelFor ¶
Generates a label for a form field
Example: {{#LabelFor [fieldId]}}[display]{{/LabelFor}} [fieldId] is the id="" attr of the form field. [display] is the display text of the label.
func LinkTo ¶
Returns an HTML link as a string suitable for insertion into an HTML template.
Params: {{#UrlFor [controllerName] [routeParameters]...}} params are passed to the router to create a properly formed URL. Data: {{#UrlFor}} [data] {{/UrlFor}} data will be escaped and used as the link's display text.
func RenderIn ¶
Renders the requested template inside a layout. This can override the default behavior to render inside the application layout.
func RenderWith ¶
func TextFieldFor ¶
Generates a text field suitable for rendering in an HTML form.
Example: {{#TextFieldFor [fieldId] [?fieldType]}}{{/TextFieldFor}} [fieldId] is the field's HTML id="" attribute. [?fieldType] is an optional parameter used as the HTML type="" attribute.
Types ¶
type Action ¶
type Action func() *Result
An action takes a map of request-parameters from the middleware or router and turns it into a servicable HTTP result.
type AfterPhaseContext ¶
type AfterPhaseContext interface { ChainableContext AfterAttach(http.ResponseWriter, *http.Request) error }
Contexts which provide a callback for the "AFTER-ATTACH" phase of route resolution.
type ChainableContext ¶
type ChainableContext interface { NewInstance() ChainableContext // returns a clean instance that is safe for a single request/response // Resolve TestContext(Controller, []ChainableContext) error // Allows a context to test if a route is properly configured before any requests are serviced. // Attach ApplyContext(Controller, http.ResponseWriter, *http.Request, []ChainableContext) // Delegate down the chain until somebody answers the request. // After CloseContext() }
Contexts which can be chained together ApplyContext will actually attach the context to a specific controller TestContext can be used to determine if a route supports a given context.
type Controller ¶
type Controller interface { Dispatch(string, string) (Controller, Action) TestContext([]ChainableContext) error }
A dispatcher returns a request-facing version of itself and action which is considered safe to infoke ONLY IF the context satisfies the dispatcher with no errors.
type MustacheRenderer ¶
type MustacheRenderer struct {
// contains filtered or unexported fields
}
func NewMustacheRenderer ¶
func NewMustacheRenderer(viewsPath string) *MustacheRenderer
func (*MustacheRenderer) RenderWith ¶
func (mu *MustacheRenderer) RenderWith( templateName, controllerName, actionName string, filterHelpers ...interface{}) string
type Param ¶
type Param struct { All map[string]string Form map[string]string Files map[string][]*multipart.FileHeader }
Includes parameters from URLEncoded POST and GET data. Also includes multipart form data if its available
func RetrieveAllParams ¶
Retrieves GET and POST vars from an http Request
type RedirectPath ¶
Requests an HTTP redirect from the middleware or router.
type Result ¶
type Result struct { Body []byte //HTTP Response Body Status int //HTTP Status Code IsFile bool //Indicates that the body should be served as a file. Filename string Redirect *RedirectPath }
Represents an HTTP response from a `Controller` The middleware or router is responsible for using this result appopriately.
type ViewData ¶
type ViewData struct { Yield func(params []string, data string) string //Flash func() string Context interface{} }
A context that will be passed to the underlying html template. Yield is a function that will be replaced by the renderer. It will call your requested template and automatically pass it the supplied `Context` argument.
type ViewableContext ¶
type ViewableContext interface { ChainableContext GetViewHelpers() []interface{} }
Contexts which have view helpers associated with them If they are passed to a RenderWith method their view helpers will be added.