The definition of the beastly wrapper function
Implement subclasses of this inside your main provider class to do a more object oriented site.
Everything should derive from this instead of the old struct namespace used before Your class must provide a default constructor.
throw this if your function needs something that is missing. Done automatically by the wrapper function
throw this if a paramater is invalid. Automatic forms may present this to the user in a new form. (FIXME: implement that)
throw if the request path is not found. Done automatically by the default catch all handler.
throw this if the user's access is denied
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.
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.
this is there so there's a common runtime type for all callables
convenience for throwing InvalidParameterExceptions
turns camelCase into human presentable capitalized words with spaces
and use this to check it.
Given a function from reflection, build a form to ask for it's params
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");
turns a string array from the URL into a proper D type
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.
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.
This gets your site's base link. note it's really only good if you are using FancyMain.
Looks for things like <a or [url - the kind of stuff I often see in blatantly obvious comment spam
helper for param checking
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.
This is meant to beautify and check links and javascripts to call web.d functions. FIXME: this function sucks.
This uses reflection info to generate Javascript that can call the server with some ease. Also includes javascript base (see bottom of this file)
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...
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.
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.
implements the "table" format option. Works on structs and associative arrays (stringstring[])
does a name/field table for just a singular object
////////////////////////////// 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.
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.
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.
turns camelCase into dash-separated
This adds a custom attribute to links in the document called qsa which modifies the values on the query string
tries to take a URL name and turn it into a human natural name. so get rid of slashes, capitalize, etc.
a convenience function to do filters on your doc and write it out. kinda useless still at this point.
Equivalent to writef(fmt, args, '\n').
Like FancyMain, but you can pass a custom subclass of Cgi
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.
This is cookie parameters for the Session class. The default initializers provide some simple default values for a site-wide session cookie.
Attribute for the default formatting (html, table, json, etc)
describes an enum, iff based on int as the underlying type
This is the JSON envelope format
.
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.
Function parameter
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.
Describes the info collected about your class
Info about the current request - more specialized than the cgi object directly
describes a plain data struct
.
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
It provides the foundation to calling the server via background requests and handling the response in callbacks. (ajax style stuffs).
Old magic web wrapper - one of my first applications of CT reflection. Given a class of fairly ordinary D code, it automatically creates HTML pages and forms, a Javascript file to access the functions from the client, and JSON based api responses. I do not recommend it for new projects though, as a replacement is now built into arsd.cgi.