actionMappingFormat
enum actionMappingFormat =
q{
static if (hasUDA!(%1$s.%2$s, HttpAction))
{
static action_%2$s = getUDAs!(%1$s.%2$s, HttpAction)[0];
if (action_%2$s.action && action_%2$s.action.strip().length)
{
auto routingData = _mappedRoutes.get("%2$s", null);
if (!routingData && !_mappedControllers[fullyQualifiedName!TController])
{
routingData = parseRoute(action_%2$s.action);
if (routingData && routingData.length > 1)
{
_mappedRoutes["%2$s"] = routingData;
action_%2$s.action = routingData[0].identifier;
}
}
if (routingData && routingData.length)
{
if (routingData[0].identifier == "<>")
{
action_%2$s.action = null;
}
}
}
enum parameterTypes_%2$s = Parameters!(controller.%2$s).stringof[1..$-1].split(", ");
static if (parameterTypes_%2$s.length)
{
template isJsonObject(T)
{
static if (is(T == struct) || is(T == class))
{
enum isJsonObject = true;
}
else
{
enum isJsonObject = false;
}
}
mixin("enum isJson_%2$s = isJsonObject!" ~ parameterTypes_%2$s[0] ~ ";");
static if (isJson_%2$s)
{
static if(parameterTypes_%2$s.length == 1)
{
static if (hasUDA!(%1$s.%2$s, HttpSanitize))
{
mapAction(
action_%2$s.method,
(
action_%2$s.action && action_%2$s.action.strip().length ?
action_%2$s.action : "%2$s"
).firstToLower(),
() {
mixin("return controller.%2$s(client.getSanitizedModelFromJson!" ~ (parameterTypes_%2$s[0]) ~ ");");
}
);
}
else
{
mapAction(
action_%2$s.method,
(
action_%2$s.action && action_%2$s.action.strip().length ?
action_%2$s.action : "%2$s"
).firstToLower(),
() {
mixin("return controller.%2$s(client.getModelFromJson!" ~ (parameterTypes_%2$s[0]) ~ ");");
}
);
}
}
else
{
static assert(0, "Can only map a single json object.");
}
}
else
{
enum parameterNames_%2$s = [ParameterIdentifierTuple!(controller.%2$s)];
mapAction(
action_%2$s.method,
(
action_%2$s.action && action_%2$s.action.strip().length ?
action_%2$s.action : "%2$s"
).firstToLower(),
() {
static foreach (i; 0 .. parameterNames_%2$s.length)
{
static if (hasUDA!(%1$s.%2$s, HttpQuery))
{
static if (hasUDA!(%1$s.%2$s, HttpSanitize))
{
mixin("auto " ~ parameterNames_%2$s[i] ~ " = to!(" ~ (parameterTypes_%2$s[i]) ~ ")(escapeHtml(client.query.get(\"" ~ parameterNames_%2$s[i] ~ "\")));");
}
else
{
mixin("auto " ~ parameterNames_%2$s[i] ~ " = to!(" ~ (parameterTypes_%2$s[i]) ~ ")(client.query.get(\"" ~ parameterNames_%2$s[i] ~ "\"));");
}
}
else static if (hasUDA!(%1$s.%2$s, HttpForm))
{
static if (hasUDA!(%1$s.%2$s, HttpSanitize))
{
mixin("auto " ~ parameterNames_%2$s[i] ~ " = to!(" ~ (parameterTypes_%2$s[i]) ~ ")(escapeHtml(client.form.get(\"" ~ parameterNames_%2$s[i] ~ "\")));");
}
else
{
mixin("auto " ~ parameterNames_%2$s[i] ~ " = to!(" ~ (parameterTypes_%2$s[i]) ~ ")(client.form.get(\"" ~ parameterNames_%2$s[i] ~ "\"));");
}
}
else
{
mixin(parameterTypes_%2$s[i] ~ " " ~ parameterNames_%2$s[i] ~ ";");
static if (hasUDA!(%1$s.%2$s, HttpSanitize) && parameterTypes_%2$s[i] == "string")
{
if (action_%2$s.action && action_%2$s.action.length)
{
mixin(parameterNames_%2$s[i] ~ " = escapeHtml(get!(" ~ (parameterTypes_%2$s[i]) ~ ")(\"" ~ parameterNames_%2$s[i] ~ "\"));");
}
else
{
mixin(parameterNames_%2$s[i] ~ " = escapeHtml(getByIndex!(" ~ (parameterTypes_%2$s[i]) ~ ")(\"" ~ to!string(i) ~ "\"));");
}
}
else
{
if (action_%2$s.action && action_%2$s.action.length)
{
mixin(parameterNames_%2$s[i] ~ " = get!(" ~ (parameterTypes_%2$s[i]) ~ ")(\"" ~ parameterNames_%2$s[i] ~ "\");");
}
else
{
mixin(parameterNames_%2$s[i] ~ " = getByIndex!(" ~ (parameterTypes_%2$s[i]) ~ ")(\"" ~ to!string(i) ~ "\");");
}
}
}
}
mixin("return controller.%2$s(" ~ (parameterNames_%2$s.join(",")) ~ ");");
}
);
}
}
else
{
mapAction(
action_%2$s.method,
(
action_%2$s.action && action_%2$s.action.strip().length ?
action_%2$s.action : "%2$s"
).firstToLower(),
&controller.%2$s
);
}
}
};
diamond controllers controller
classesmanifest constantsmixin templatesvariables
The format used for actions.