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.

class MyPresenter : WebPresenter!(MyPresenter) {
	@Override
	void presentSuccessfulReturnAsHtml(T : CustomType)(Cgi cgi, T ret, typeof(null) meta) {
		// present the CustomType
	}
	@Override
	void presentSuccessfulReturnAsHtml(T)(Cgi cgi, T ret, typeof(null) meta) {
		// handle everything else via the super class, which will call
		// back to your class when appropriate
		super.presentSuccessfulReturnAsHtml(cgi, ret);
	}
}

The meta argument in there can be overridden by your own facility.

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, Element function() udaSuggestion)

Returns an element for a particular type

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

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.

presentExceptionalReturn
void presentExceptionalReturn(Cgi cgi, Throwable t, Meta meta, string format)
presentSuccessfulReturn
void presentSuccessfulReturn(Cgi cgi, T ret, Meta meta, string format)

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.

presentSuccessfulReturn
void presentSuccessfulReturn(Cgi cgi, T ret, Meta meta, string format)

Redirections are forwarded to Cgi.setResponseLocation

presentSuccessfulReturn
void presentSuccessfulReturn(Cgi cgi, T ret, Meta meta, string format)

CreatedResources send code 201 and will set the given urls, then present the given representation.

presentSuccessfulReturn
void presentSuccessfulReturn(Cgi cgi, T ret, Meta meta, string format)

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

presentSuccessfulReturn
void presentSuccessfulReturn(Cgi cgi, T ret, Meta meta, string format)

An instance of the arsd.dom.FileResource interface has its own content type; assume it is a download of some sort if the filename member is non-null of the FileResource interface.

presentSuccessfulReturnAsHtml
void presentSuccessfulReturnAsHtml(Cgi cgi, T ret, typeof(null) meta)

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

renderBasicError
void renderBasicError(Cgi cgi, int httpErrorCode)

Renders a response as an HTTP error with associated html body

Meta