arsd.web

magic web wrapper

Members

Aliases

WrapperFunction
alias WrapperFunction = WrapperReturn delegate(Cgi cgi, WebDotDBaseType, in string[][string] args, in string format, in string secondaryFormat = null)

The definition of the beastly wrapper function

Classes

ApiObject
class ApiObject

Implement subclasses of this inside your main provider class to do a more object oriented site.

ApiProvider
class ApiProvider

Everything should derive from this instead of the old struct namespace used before Your class must provide a default constructor.

InsufficientParametersException
class InsufficientParametersException

throw this if your function needs something that is missing. Done automatically by the wrapper function

InvalidParameterException
class InvalidParameterException

throw this if a paramater is invalid. Automatic forms may present this to the user in a new form. (FIXME: implement that)

NoSuchPageException
class NoSuchPageException

throw if the request path is not found. Done automatically by the default catch all handler.

ParamCheckHelper
class ParamCheckHelper
PermissionDeniedException
class PermissionDeniedException

throw this if the user's access is denied

Session
class Session

Provides some persistent storage, kinda like PHP But, you have to manually commit() the data back to a file. You might want to put this in a scope(exit) block or something like that.

TemplatedDocument
class TemplatedDocument

a specialization of Document that: a) is always in strict mode and b) provides some template variable text replacement, in addition to DOM manips. The variable text is valid in text nodes and attribute values. It takes the format of {$variable}, where variable is a key into the vars member.

WebDotDBaseType
class WebDotDBaseType

this is there so there's a common runtime type for all callables

Functions

badParameter
void badParameter(string expected = "")

convenience for throwing InvalidParameterExceptions

beautify
string beautify(string name)

turns camelCase into human presentable capitalized words with spaces

checkPassword
bool checkPassword(string saltedPasswordHash, string userSuppliedPassword)

and use this to check it.

createAutomaticForm
Form createAutomaticForm(Document document, in FunctionInfo* func, string[string] fieldTypes = null)
Form createAutomaticForm(Document document, string action, in Parameter[] parameters, string submitText = "Submit", string method = "POST", string[string] fieldTypes = null)

Given a function from reflection, build a form to ask for it's params

formatAs
string formatAs(T ret, string format, R api = null, JSONValue* returnValue = null, string formatJsonToStringAs = null)

This is the function called to turn return values into strings. Implement a template called _customFormat in your apiprovider class to make special formats. Otherwise, this provides the defaults of html, table, json, etc. call it like so: JSONValue returnValue; formatAs(value, this, returnValue, "type");

fromUrlParam
type fromUrlParam(in string[] ofInterest, in string name, in string[][string] all)

turns a string array from the URL into a proper D type

generateWrapper
WrapperFunction generateWrapper(ReflectionInfo* reflection, R api)

generates the massive wrapper function for each of your class' methods. it is responsible for turning strings to params and return values back to strings.

getSessionId
string getSessionId(Cgi cgi)

meant to give a generic useful hook for sessions. kinda sucks at this point. use the Session class instead. If you just construct it, the sessionId property works fine. Don't set any data and it won't save any file.

getSiteLink
string getSiteLink(Cgi cgi)

This gets your site's base link. note it's really only good if you are using FancyMain.

isFreeOfTypicalPlainTextSpamLinks
bool isFreeOfTypicalPlainTextSpamLinks(string txt)

Looks for things like <a or [url - the kind of stuff I often see in blatantly obvious comment spam

isValidLookingEmailAddress
bool isValidLookingEmailAddress(string e)

helper for param checking

jsCall
string jsCall(Args args)

This is meant to beautify and check links and javascripts to call web.d functions. This function works pretty ok. You're going to want to append a string to the return value to actually call .get() or whatever; it only does the name and arglist.

linkCall
string linkCall(Args args)

This is meant to beautify and check links and javascripts to call web.d functions. FIXME: this function sucks.

makeJavascriptApi
string makeJavascriptApi(const ReflectionInfo* mod, string base, bool isNested = false)

This uses reflection info to generate Javascript that can call the server with some ease. Also includes javascript base (see bottom of this file)

makeSaltedPasswordHash
string makeSaltedPasswordHash(string userSuppliedPassword, string salt = null)

These added a dependency on arsd.sha, but hashing passwords is somewhat useful in a lot of apps so I figured it was worth it. use this to make the hash to put in the database...

run
void run(Cgi cgi, Provider instantiation, size_t pathInfoStartingPoint = 0, bool handleAllExceptions = true, Session session = null)

If you're not using FancyMain, this is the go-to function to do most the work. instantiation should be an object of your ApiProvider type. pathInfoStartingPoint is used to make a slice of it, incase you already consumed part of the path info before you called this.

setLoginCookie
void setLoginCookie(Cgi cgi, string name, string value)

sets a site-wide cookie, meant to simplify login code. Note: you often might not want a side wide cookie, but I usually do since my projects need single sessions across multiple thingies, hence, this.

structToTable
Table structToTable(Document document, T arr, string[] fieldsToSkip = null)

implements the "table" format option. Works on structs and associative arrays (stringstring[])

structToTable
Table structToTable(Document document, T s, string[] fieldsToSkip = null)

does a name/field table for just a singular object

toHtml
string toHtml(T a)

Formats any given type as HTML. In custom types, you can write Element makeHtmlElement(Document document = null); to provide custom html. (the default arg is important - it won't necessarily pass a Document in at all, and since it's silently duck typed, not having that means your function won't be called and you can be left wondering WTF is going on.) Alternatively, static Element makeHtmlArray(T[]) if you want to make a whole list of them. By default, it will just concat a bunch of individual elements though.

toJson
string toJson(T a)

Translates a given type to a JSON string. TIP: if you're building a Javascript function call by strings, toJson("your string"); will build a nicely escaped string for you of any type.

toJsonValue
JSONValue toJsonValue(T a, string formatToStringAs = null, R api = null)

like toHtml - it makes a json value of any given type. It can be used generically, or it can be passed an ApiProvider so you can do a secondary custom format. (it calls api.formatAs!(type)(typeRequestString)). Why would you want that? Maybe your javascript wants to do work with a proper object,but wants to append it to the document too. Asking for json with secondary format = html means the server will provide both to you. Implement JSONValue makeJsonValue() in your struct or class to provide 100% custom Json. Elements from DOM are turned into JSON strings of the element's html.

toUrlName
string toUrlName(string name)

turns camelCase into dash-separated

translateQsa
void translateQsa(Document document, Cgi cgi, string logicalScriptName = null)

This adds a custom attribute to links in the document called qsa which modifies the values on the query string

urlToBeauty
string urlToBeauty(string url)

tries to take a URL name and turn it into a human natural name. so get rid of slashes, capitalize, etc.

writeDocument
void writeDocument(Cgi cgi, TemplatedDocument document)

a convenience function to do filters on your doc and write it out. kinda useless still at this point.

Mixin templates

CustomCgiFancyMain
mixin template CustomCgiFancyMain(CustomCgi, T, Args...)

Like FancyMain, but you can pass a custom subclass of Cgi

FancyMain
mixin template FancyMain(T, Args...)

fancier wrapper to cgi.d's GenericMain - does most the work for you, so you can just write your class and be done with it Note it creates a session for you too, and will write to the disk - a csrf token. Compile with -version=no_automatic_session to disable this.

Structs

CookieParams
struct CookieParams

This is cookie parameters for the Session class. The default initializers provide some simple default values for a site-wide session cookie.

DefaultFormat
struct DefaultFormat

Attribute for the default formatting (html, table, json, etc)

EnumInfo
struct EnumInfo

describes an enum, iff based on int as the underlying type

Envelope
struct Envelope

This is the JSON envelope format

FunctionInfo
struct FunctionInfo

.

IfInputContentType
struct IfInputContentType

With this attribute, the function is only called if the input data's content type is what you specify here. Makes sense for POST and PUT verbs.

Parameter
struct Parameter

Function parameter

PreferredMethod
struct PreferredMethod

Sets the preferred request method, used by things like other code generators. While this is preferred, the function is still callable from any request method.

ReflectionInfo
struct ReflectionInfo

Describes the info collected about your class

RequestInfo
struct RequestInfo

Info about the current request - more specialized than the cgi object directly

StructInfo
struct StructInfo

describes a plain data struct

StructMemberInfo
struct StructMemberInfo

.

Text
struct Text

use this in a function parameter if you want the automatic form to render it as a textarea FIXME: this should really be an annotation on the parameter... somehow

Variables

javascriptBaseImpl
enum string javascriptBaseImpl

It provides the foundation to calling the server via background requests and handling the response in callbacks. (ajax style stuffs).

Suggestion Box / Bug Report