WebPresenter

A web presenter is responsible for rendering things to HTML to be usable in a web browser.

They are passed as template arguments to the base classes of WebObject

Responsible for displaying stuff as HTML. You can put this into your own aggregate and override it. Use forwarding and specialization to customize it.

When you inherit from it, pass your own class as the CRTP argument. This lets the base class templates and your overridden templates work with each other.

1 class MyPresenter : WebPresenter!(MyPresenter) {
2 	@Override
3 	void presentSuccessfulReturnAsHtml(T : CustomType)(Cgi cgi, T ret) {
4 		// present the CustomType
5 	}
6 	@Override
7 	void presentSuccessfulReturnAsHtml(T)(Cgi cgi, T ret) {
8 		// handle everything else via the super class, which will call
9 		// back to your class when appropriate
10 		super.presentSuccessfulReturnAsHtml(cgi, ret);
11 	}
12 }

Members

Enums

Override
enum Override

A UDA version of the built-in override, to be used for static template polymorphism If you override a plain method, use override. If a template, use @Override.

Functions

createAutomaticFormForFunction
Form createAutomaticFormForFunction(T dg)

creates a form for gathering the function's arguments

createAutomaticFormForObject
Form createAutomaticFormForObject(T obj)

creates a form for gathering object members (for the REST object thing right now)

elementFor
Element elementFor(string displayName, string name)

Returns an element for a particular type

formatReturnValueAsHtml
Element formatReturnValueAsHtml(T t)
presentExceptionAsHtml
void presentExceptionAsHtml(Cgi cgi, Throwable t, T dg)

If you override this, you will need to cast the exception type t dynamically, but can then use the template arguments here to refer back to the function.

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret)

typeof(null) (which is also used to represent functions returning void) do nothing in the default presenter - allowing the function to have full low-level control over the response.

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret)

Redirections are forwarded to Cgi.setResponseLocation

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret)

Multiple responses deconstruct the algebraic type and forward to the appropriate handler at runtime

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret)

An instance of the arsd.dom.FileResource interface has its own content type; assume it is a download of some sort.

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret)

And the default handler will call formatReturnValueAsHtml and place it inside the htmlContainer.

renderBasicError
void renderBasicError(Cgi cgi, int httpErrorCode)

Renders a response as an HTTP error

Meta