/* dropdown("priority", makeGrid("[{ id: 0, low: 0}, { id: 1, med: 1}, {id: 2, high: 2}]"), 0) dropdown("priority", makeGrid("[{ low: 0}, { med: 1}, {high: 2}]"), 0) dropdown("priority", makeGrid("[0, 10, 100]"), 0) Options can provide the defaultValue in a "value" property. */ PUBLIC void espDropdown(HttpConn *conn, cchar *field, EdiGrid *choices, cchar *optionString) { EdiRec *rec; MprHash *options; cchar *id, *currentValue, *selected, *value; int r; if (choices == 0) { return; } options = httpGetOptions(optionString); currentValue = getValue(conn, field, options); if (field == 0) { field = httpGetOption(options, "field", "id"); } espRender(conn, "<select name='%s'%s>\r\n", field, map(conn, options)); for (r = 0; r < choices->nrecords; r++) { rec = choices->records[r]; if (rec->nfields == 1) { value = rec->fields[0].value; } else { value = ediGetFieldValue(rec, field); } if ((id = ediGetFieldValue(choices->records[r], "id")) == 0) { id = value; } selected = (smatch(value, currentValue)) ? " selected='yes'" : ""; espRender(conn, " <option value='%s'%s>%s</option>\r\n", id, selected, value); } espRender(conn, " </select>"); }
PUBLIC void espScript(HttpConn *conn, cchar *uri, cchar *optionString) { MprHash *options; cchar *indent, *newline, *path; EspScript *sp; EspRoute *eroute; bool minified; eroute = conn->rx->route->eroute; options = httpGetOptions(optionString); if (uri) { espRender(conn, "<script src='%s' type='text/javascript'></script>", httpUri(conn, uri)); } else { minified = smatch(httpGetOption(options, "minified", 0), "true"); indent = ""; for (sp = defaultScripts; sp->name; sp++) { if (sp->option && !smatch(httpGetOption(options, sp->option, "false"), "true")) { continue; } if (sp->flags & SCRIPT_IE) { espRender(conn, "%s<!-- [if lt IE 9]>\n", indent); } path = sjoin("~/", mprGetPathBase(eroute->clientDir), sp->name, minified ? ".min.js" : ".js", NULL); uri = httpUri(conn, path); newline = sp[1].name ? "\r\n" : ""; espRender(conn, "%s<script src='%s' type='text/javascript'></script>%s", indent, uri, newline); if (sp->flags & SCRIPT_IE) { espRender(conn, "%s<![endif]-->\n", indent); } indent = " "; } } }
/* tabs(makeGrid("[{ name: 'Status', uri: 'pane-1' }, { name: 'Edit', uri: 'pane-2' }]")) Options: click toggle remote */ PUBLIC void espTabs(HttpConn *conn, EdiGrid *grid, cchar *optionString) { MprHash *options; EdiRec *rec; cchar *attr, *uri, *name, *klass; int r, toggle; options = httpGetOptions(optionString); httpInsertOption(options, "class", ESTYLE("tabs")); attr = httpGetOption(options, "toggle", EDATA("click")); if ((toggle = smatch(attr, "true")) != 0) { attr = EDATA("toggle"); } espRender(conn, "<div%s>\r\n <ul>\r\n", map(conn, options)); for (r = 0; r < grid->nrecords; r++) { rec = grid->records[r]; name = ediGetFieldValue(rec, "name"); uri = ediGetFieldValue(rec, "uri"); uri = toggle ? uri : httpUri(conn, uri); if ((r == 0 && toggle) || smatch(uri, conn->rx->pathInfo)) { klass = smatch(uri, conn->rx->pathInfo) ? " class='esp-selected'" : ""; } else { klass = ""; } espRender(conn, " <li %s='%s'%s>%s</li>\r\n", attr, uri, klass, name); } espRender(conn, " </ul>\r\n </div>\r\n"); }
PUBLIC ssize espSendRec(HttpConn *conn, EdiRec *rec, int flags) { httpSetContentType(conn, "application/json"); if (rec) { return espRender(conn, "{\n \"data\": %s, \"schema\": %s}\n", ediRecAsJson(rec, flags), ediGetRecSchemaAsJson(rec)); } return espRender(conn, "{}"); }
PUBLIC void espProgress(HttpConn *conn, cchar *percent, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); httpAddOption(options, EDATA("progress"), percent); espRender(conn, "<div class='" ESTYLE("progress") "'>\r\n"); espRender(conn, " <div class='" ESTYLE("progress-inner") "'%s>%s %%</div>\r\n</div>", map(conn, options), percent); }
PUBLIC ssize espSendGrid(HttpConn *conn, EdiGrid *grid, int flags) { httpSetContentType(conn, "application/json"); if (grid) { return espRender(conn, "{\n \"data\": %s, \"schema\": %s}\n", ediGridAsJson(grid, flags), ediGetGridSchemaAsJson(grid)); } return espRender(conn, "{}"); }
PUBLIC void form(EdiRec *record, cchar *optionString) { HttpConn *conn; MprHash *options; cchar *action, *recid, *method, *uri, *token; conn = getConn(); if (record == 0) { record = getRec(); } else { conn->record = record; } options = httpGetOptions(optionString); recid = 0; /* If record provided, get the record id. Can be overridden using options.recid */ if (record) { if (record->id && !httpGetOption(options, "recid", 0)) { httpAddOption(options, "recid", record->id); } recid = httpGetOption(options, "recid", 0); emitFormErrors(conn, record, options); } if ((method = httpGetOption(options, "method", 0)) == 0) { method = (recid) ? "PUT" : "POST"; } if (!scaselessmatch(method, "GET") && !scaselessmatch(method, "POST")) { /* All methods use POST and tunnel method in data-method */ httpAddOption(options, EDATA("method"), method); method = "POST"; } if ((action = httpGetOption(options, "action", 0)) == 0) { action = (recid) ? "@update" : "@create"; } uri = httpUri(conn, action); if (smatch(httpGetOption(options, "remote", 0), "true")) { espRender(conn, "<form method='%s' " EDATA("remote") "='%s'%s >\r\n", method, uri, map(conn, options)); } else { espRender(conn, "<form method='%s' action='%s'%s >\r\n", method, uri, map(conn, options)); } if (recid) { espRender(conn, " <input name='recid' type='hidden' value='%s' />\r\n", recid); } if (!httpGetOption(options, "insecure", 0)) { if ((token = httpGetOption(options, "securityToken", 0)) == 0) { token = httpGetSecurityToken(conn, 0); } espRender(conn, " <input name='%s' type='hidden' value='%s' />\r\n", BIT_XSRF_PARAM, token); } }
/* checkbox field checkedValue -- Value for which the checkbox will be checked. Defaults to true. Example: checkbox("admin", "true") */ PUBLIC void espCheckbox(HttpConn *conn, cchar *field, cchar *checkedValue, cchar *optionString) { MprHash *options; cchar *value, *checked; options = httpGetOptions(optionString); value = getValue(conn, field, options); checked = scaselessmatch(value, checkedValue) ? " checked='yes'" : ""; espRender(conn, "<input name='%s' type='checkbox'%s%s value='%s' />\r\n", field, map(conn, options), checked, checkedValue); espRender(conn, " <input name='%s' type='hidden'%s value='' />", field, map(conn, options)); }
PUBLIC void espButton(HttpConn *conn, cchar *name, cchar *value, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<input name='%s' type='submit' value='%s'%s />", name, value, map(conn, options)); }
PUBLIC void espLabel(HttpConn *conn, cchar *text, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<span%s>%s</span>", map(conn, options), text); }
PUBLIC void espImage(HttpConn *conn, cchar *uri, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<img src='%s'%s />", httpUri(conn, uri), map(conn, options)); }
PUBLIC void espDivision(HttpConn *conn, cchar *body, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<div%s>%s</div>", map(conn, options), body); }
PUBLIC void espMail(HttpConn *conn, cchar *name, cchar *address, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<a href='mailto:%s'%s>%s</a>", address, map(conn, options), name); }
/* Control the refresh of dynamic elements in the page */ PUBLIC void espRefresh(HttpConn *conn, cchar *on, cchar *off, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); espRender(conn, "<img src='%s' " EDATA("on") "='%s' " EDATA("off") "='%s%s' class='" ESTYLE("refresh") "' />", on, on, off, map(conn, options)); }
PUBLIC void espAnchor(HttpConn *conn, cchar *text, cchar *uri, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); text = escapeValue(text, options); espRender(conn, "<a href='%s'%s>%s</a>", uri, map(conn, options), text); }
PUBLIC void espButtonLink(HttpConn *conn, cchar *text, cchar *uri, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); httpSetOption(options, EDATA("click"), httpUri(conn, uri)); espRender(conn, "<button%s>%s</button>", map(conn, options), text); }
PUBLIC void espRenderResult(HttpConn *conn, bool success) { EspReq *req; EdiRec *rec; req = conn->data; rec = getRec(); if (rec && rec->errors) { espRender(conn, "{\"error\": %d, \"feedback\": %s, \"fieldErrors\": %s}", !success, req->feedback ? mprSerialize(req->feedback, MPR_JSON_QUOTES) : "{}", mprSerialize(rec->errors, MPR_JSON_QUOTES)); } else { espRender(conn, "{\"error\": %d, \"feedback\": %s}", !success, req->feedback ? mprSerialize(req->feedback, MPR_JSON_QUOTES) : "{}"); } espFinalize(conn); }
PUBLIC void espAlert(HttpConn *conn, cchar *text, cchar *optionString) { MprHash *options; options = httpGetOptions(optionString); httpInsertOption(options, "class", ESTYLE("alert")); text = escapeValue(text, options); espRender(conn, "<div%s>%s</div>", map(conn, options), text); }
static void textInner(HttpConn *conn, cchar *field, MprHash *options) { cchar *rows, *cols, *type, *value; type = "text"; value = getValue(conn, field, options); if (value == 0 || *value == '\0') { value = espGetParam(conn, field, ""); } if (httpGetOption(options, "password", 0)) { type = "password"; } else if (httpGetOption(options, "hidden", 0)) { type = "hidden"; } if ((rows = httpGetOption(options, "rows", 0)) != 0) { cols = httpGetOption(options, "cols", "60"); espRender(conn, "<textarea name='%s' type='%s' cols='%s' rows='%s'%s>%s</textarea>", field, type, cols, rows, map(conn, options), value); } else { espRender(conn, "<input name='%s' type='%s' value='%s'%s />", field, type, value, map(conn, options)); } }
PUBLIC void espStylesheet(HttpConn *conn, cchar *uri, cchar *optionString) { EspRoute *eroute; MprHash *options; cchar *indent, *newline; char **up; bool less; eroute = conn->rx->route->eroute; if (uri) { espRender(conn, "<link rel='stylesheet' type='text/css' href='%s' />", httpUri(conn, uri)); } else { indent = ""; options = httpGetOptions(optionString); less = smatch(httpGetOption(options, "type", "css"), "less"); up = less ? defaultLess : defaultCss; for (; *up; up++) { uri = httpUri(conn, sjoin("~/", mprGetPathBase(eroute->clientDir), *up, NULL)); newline = up[1] ? "\r\n" : ""; espRender(conn, "%s<link rel='stylesheet%s' type='text/css' href='%s' />%s", indent, less ? "/less" : "", uri, newline); indent = " "; } } }
PUBLIC void espIcon(HttpConn *conn, cchar *uri, cchar *optionString) { MprHash *options; EspRoute *eroute; eroute = conn->rx->route->eroute; options = httpGetOptions(optionString); if (uri == 0) { /* Suppress favicon */ uri = "data:image/x-icon;,"; } else if (*uri == 0) { uri = sjoin("~/", mprGetPathBase(eroute->clientDir), "/images/favicon.ico", NULL); } espRender(conn, "<link href='%s' rel='shortcut icon'%s />", httpUri(conn, uri), map(conn, options)); }
/* radio("priority", "{low: 0, med: 1, high: 2}", NULL) radio("priority", "{low: 0, med: 1, high: 2}", "{value:'2'}") */ PUBLIC void espRadio(HttpConn *conn, cchar *field, cchar *choicesString, cchar *optionsString) { MprKey *kp; MprHash *choices, *options; cchar *value, *checked; choices = httpGetOptions(choicesString); options = httpGetOptions(optionsString); value = getValue(conn, field, options); for (kp = 0; (kp = mprGetNextKey(choices, kp)) != 0; ) { checked = (smatch(kp->data, value)) ? " checked" : ""; espRender(conn, "%s <input type='radio' name='%s' value='%s'%s%s />\r\n", spascal(kp->key), field, kp->data, checked, map(conn, options)); } }
PUBLIC void espRenderFlash(HttpConn *conn, cchar *kinds) { EspReq *req; MprKey *kp; cchar *msg; req = conn->data; if (kinds == 0 || req->flash == 0 || mprGetHashLength(req->flash) == 0) { return; } for (kp = 0; (kp = mprGetNextKey(req->flash, kp)) != 0; ) { msg = kp->data; if (strstr(kinds, kp->key) || strstr(kinds, "all")) { espRender(conn, "<span class='flash-%s'>%s</span>", kp->key, msg); } } }
static void emitFormErrors(HttpConn *conn, EdiRec *rec, MprHash *options) { MprHash *errors; MprKey *field; char *msg; int count; if (!rec->errors || httpGetOption(options, "hideErrors", 0)) { return; } errors = ediGetRecErrors(rec); if (errors) { count = mprGetHashLength(errors); espRender(conn, "<div class='" ESTYLE("form-error") "'><h2>The %s has %s it being saved.</h2>\r\n", spascal(rec->tableName), count <= 1 ? "an error that prevents" : "errors that prevent"); espRender(conn, " <p>There were problems with the following fields:</p>\r\n"); espRender(conn, " <ul>\r\n"); for (ITERATE_KEY_DATA(errors, field, msg)) { espRender(conn, " <li>%s %s</li>\r\n", field->key, msg); } espRender(conn, " </ul>\r\n"); espRender(conn, "</div>"); } }
PUBLIC ssize espRenderGrid(HttpConn *conn, EdiGrid *grid, int flags) { httpAddHeaderString(conn, "Content-Type", "application/json"); return espRender(conn, "{\n \"schema\": %s,\n \"data\": %s}\n", ediGetGridSchemaAsJson(grid), ediGridAsJson(grid, flags)); }
PUBLIC void espTable(HttpConn *conn, EdiGrid *grid, cchar *optionString) { MprHash *options, *colOptions, *rowOptions, *thisCol; MprList *cols; EdiRec *rec; EdiField *fp; cchar *title, *width, *o, *header, *value, *sortColumn; char index[8]; int c, r, ncols, sortOrder; assert(grid); if (grid == 0) { return; } options = httpGetOptions(optionString); if (grid->nrecords == 0) { espRender(conn, "<p>No Data</p>\r\n"); return; } if (grid->flags & EDI_GRID_READ_ONLY) { grid = ediCloneGrid(grid); } if ((sortColumn = httpGetOption(options, "sort", 0)) != 0) { sortOrder = httpOption(options, "sortOrder", "ascending", 1); ediSortGrid(grid, sortColumn, sortOrder); } colOptions = httpGetOptionHash(options, "columns"); filterCols(grid, options, colOptions); if (httpOption(options, "pivot", "true", 0) != 0) { pivotTable(conn, ediPivotGrid(grid, 1), options); return; } cols = ediGetGridColumns(grid); ncols = mprGetListLength(cols); rowOptions = mprCreateHash(0, MPR_HASH_STABLE); httpSetOption(rowOptions, EDATA("click"), httpGetOption(options, EDATA("click"), 0)); httpRemoveOption(options, EDATA("click")); httpSetOption(rowOptions, EDATA("remote"), httpGetOption(options, EDATA("remote"), 0)); httpSetOption(rowOptions, EDATA("key"), httpGetOption(options, EDATA("key"), 0)); httpSetOption(rowOptions, EDATA("params"), httpGetOption(options, EDATA("params"), 0)); httpSetOption(rowOptions, EDATA("edit"), httpGetOption(options, EDATA("edit"), 0)); httpInsertOption(options, "class", ESTYLE("table")); httpInsertOption(options, "class", ESTYLE("stripe")); espRender(conn, "<table%s>\r\n", map(conn, options)); /* Table header */ if (httpOption(options, "showHeader", "true", 1)) { espRender(conn, " <thead>\r\n"); if ((title = httpGetOption(options, "title", 0)) != 0) { espRender(conn, " <tr class='" ESTYLE("table-title") "'><td colspan='%s'>%s</td></tr>\r\n", mprGetListLength(cols), title); } espRender(conn, " <tr class='" ESTYLE("table-header") "'>\r\n"); rec = grid->records[0]; for (c = 0; c < ncols; c++) { assert(c <= rec->nfields); fp = &rec->fields[c]; width = ((o = httpGetOption(options, "width", 0)) != 0) ? sfmt(" width='%s'", o) : ""; thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), c, 10)); header = httpGetOption(thisCol, "header", spascal(fp->name)); espRender(conn, " <th%s>%s</th>\r\n", width, header); } espRender(conn, " </tr>\r\n </thead>\r\n"); } espRender(conn, " <tbody>\r\n"); /* Table body data */ for (r = 0; r < grid->nrecords; r++) { rec = grid->records[r]; httpSetOption(rowOptions, "id", rec->id); espRender(conn, " <tr%s>\r\n", map(conn, rowOptions)); for (c = 0; c < ncols; c++) { fp = &rec->fields[c]; thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), c, 10)); if (httpGetOption(thisCol, "align", 0) == 0) { if (fp->type == EDI_TYPE_INT || fp->type == EDI_TYPE_FLOAT) { if (!thisCol) { thisCol = mprCreateHash(0, MPR_HASH_STABLE); } httpInsertOption(thisCol, "align", "right"); } } value = formatValue(fp, thisCol); espRender(conn, " <td%s>%s</td>\r\n", map(conn, thisCol), value); } espRender(conn, " </tr>\r\n"); } espRender(conn, " </tbody>\r\n</table>\r\n"); }
/* Render a table from a data grid Examples: table(grid, "{ refresh:'@update', period:'1000', pivot:'true' }"); table(grid, "{ click:'@edit' }"); table(grid, "columns: [ \ { name: product, header: 'Product', width: '20%' }, \ { name: date, format: '%m-%d-%y' }, \ { name: 'user.name' }, \ ]"); table(readTable("users")); table(makeGrid("[{'name': 'peter', age: 23 }, {'name': 'mary', age: 22}]") table(grid, "{ \ columns: [ \ { name: 'speed', header: 'Speed', dropdown: [100, 1000, 40000] }, \ { name: 'adminMode', header: 'Admin Mode', radio: ['Up', 'Down'] }, \ { name: 'state', header: 'State', radio: ['Enabled', 'Disabled'] }, \ { name: 'autoNegotiate', header: 'Auto Negotiate', checkbox: ['enabled'] }, \ { name: 'type', header: 'Type' }, \ ], \ edit: true, \ pivot: true, \ showHeader: false, \ class: 'esp-pivot', \ }"); */ static void pivotTable(HttpConn *conn, EdiGrid *grid, MprHash *options) { MprHash *colOptions, *rowOptions, *thisCol, *dropdown, *radio; MprList *cols; EdiRec *rec; EdiField *fp; cchar *title, *width, *o, *header, *name, *checkbox; char index[8]; int c, r, ncols; assert(grid); if (grid->nrecords == 0) { espRender(conn, "<p>No Data</p>\r\n"); return; } colOptions = httpGetOptionHash(options, "columns"); cols = ediGetGridColumns(grid); ncols = mprGetListLength(cols); rowOptions = mprCreateHash(0, MPR_HASH_STABLE); httpSetOption(rowOptions, EDATA("click"), httpGetOption(options, EDATA("click"), 0)); httpInsertOption(options, "class", ESTYLE("pivot")); httpInsertOption(options, "class", ESTYLE("table")); espRender(conn, "<table%s>\r\n", map(conn, options)); /* Table header */ if (httpOption(options, "showHeader", "true", 1)) { espRender(conn, " <thead>\r\n"); if ((title = httpGetOption(options, "title", 0)) != 0) { espRender(conn, " <tr class='" ESTYLE("table-title") "'><td colspan='%s'>%s</td></tr>\r\n", mprGetListLength(cols), title); } espRender(conn, " <tr class='" ESTYLE("header") "'>\r\n"); rec = grid->records[0]; for (r = 0; r < ncols; r++) { assert(r <= grid->nrecords); width = ((o = httpGetOption(options, "width", 0)) != 0) ? sfmt(" width='%s'", o) : ""; thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), r, 10)); header = httpGetOption(thisCol, "header", spascal(rec->id)); espRender(conn, " <th%s>%s</th>\r\n", width, header); } espRender(conn, " </tr>\r\n </thead>\r\n"); } espRender(conn, " <tbody>\r\n"); /* Table body data */ for (r = 0; r < grid->nrecords; r++) { rec = grid->records[r]; httpSetOption(rowOptions, "id", rec->id); espRender(conn, " <tr%s>\r\n", map(conn, rowOptions)); for (c = 0; c < ncols; c++) { fp = &rec->fields[c]; thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), r, 10)); if (httpGetOption(thisCol, "align", 0) == 0) { if (fp->type == EDI_TYPE_INT || fp->type == EDI_TYPE_FLOAT) { if (!thisCol) { thisCol = mprCreateHash(0, MPR_HASH_STABLE); } httpInsertOption(thisCol, "align", "right"); } } if (c == 0) { /* Render column name */ name = httpGetOption(thisCol, "header", spascal(rec->id)); if (httpOption(options, "edit", "true", 0) && httpOption(thisCol, "edit", "true", 1)) { espRender(conn, " <td%s>%s</td><td>", map(conn, thisCol), name); if ((dropdown = httpGetOption(thisCol, "dropdown", 0)) != 0) { espDropdown(conn, fp->name, hashToGrid(dropdown), 0); } else if ((radio = httpGetOption(thisCol, "radio", 0)) != 0) { espRadio(conn, fp->name, hashToString(radio, 0), 0); } else if ((checkbox = httpGetOption(thisCol, "checkbox", 0)) != 0) { espCheckbox(conn, fp->name, checkbox, 0); } else { input(fp->name, 0); } espRender(conn, "</td>\r\n"); } else { espRender(conn, " <td%s>%s</td><td>%s</td>\r\n", map(conn, thisCol), name, fp->value); } } else { espRender(conn, " <td%s>%s</td>\r\n", map(conn, thisCol), fp->value); } } } espRender(conn, " </tr>\r\n"); espRender(conn, " </tbody>\r\n</table>\r\n"); }
void espShowRequest(HttpConn *conn) { MprHash *env; MprKey *kp; MprBuf *buf; HttpRx *rx; HttpQueue *q; cchar *query; char qbuf[MPR_MAX_STRING], **keys, *value; int i, numKeys; rx = conn->rx; httpSetHeaderString(conn, "Cache-Control", "no-cache"); httpCreateCGIParams(conn); espRender(conn, "\r\n"); /* Query */ if ((query = espGetQueryString(conn)) != 0) { scopy(qbuf, sizeof(qbuf), query); if ((numKeys = getParams(&keys, qbuf, (int) strlen(qbuf))) > 0) { for (i = 0; i < (numKeys * 2); i += 2) { value = keys[i+1]; espRender(conn, "QUERY %s=%s\r\n", keys[i], value ? value: "null"); } } espRender(conn, "\r\n"); } /* Http Headers */ env = espGetHeaderHash(conn); for (ITERATE_KEYS(env, kp)) { espRender(conn, "HEADER %s=%s\r\n", kp->key, kp->data ? kp->data: "null"); } espRender(conn, "\r\n"); /* Server vars */ for (ITERATE_KEYS(conn->rx->svars, kp)) { espRender(conn, "SERVER %s=%s\r\n", kp->key, kp->data ? kp->data: "null"); } espRender(conn, "\r\n"); /* Form vars */ if ((env = espGetParams(conn)) != 0) { for (ITERATE_KEYS(env, kp)) { espRender(conn, "FORM %s=%s\r\n", kp->key, kp->data ? kp->data: "null"); } espRender(conn, "\r\n"); } /* Body */ q = conn->readq; if (q->first && rx->bytesRead > 0 && scmp(rx->mimeType, "application/x-www-form-urlencoded") == 0) { buf = q->first->content; mprAddNullToBuf(buf); if ((numKeys = getParams(&keys, mprGetBufStart(buf), (int) mprGetBufLength(buf))) > 0) { for (i = 0; i < (numKeys * 2); i += 2) { value = keys[i+1]; espRender(conn, "BODY %s=%s\r\n", keys[i], value ? value: "null"); } } espRender(conn, "\r\n"); } }
/* <% stylesheets(patterns); %> Where patterns may contain *, ** and !pattern for exclusion */ PUBLIC void stylesheets(cchar *patterns) { HttpStream *stream; HttpRx *rx; HttpRoute *route; EspRoute *eroute; MprList *files; cchar *filename, *ext, *uri, *path, *kind, *version, *clientDir; int next; stream = getStream(); rx = stream->rx; route = rx->route; eroute = route->eroute; patterns = httpExpandRouteVars(route, patterns); clientDir = httpGetDir(route, "documents"); if (!patterns || !*patterns) { version = espGetConfig(route, "version", "1.0.0"); if (eroute->combineSheet) { /* Previously computed combined stylesheet filename */ stylesheets(eroute->combineSheet); } else if (espGetConfig(route, "http.content.combine[@=css]", 0)) { if (espGetConfig(route, "http.content.minify[@=css]", 0)) { eroute->combineSheet = sfmt("css/all-%s.min.css", version); } else { eroute->combineSheet = sfmt("css/all-%s.css", version); } stylesheets(eroute->combineSheet); } else { /* Not combining into a single stylesheet, so give priority to all.less over all.css if present Load a pure CSS incase some styles need to be applied before the lesssheet is parsed */ ext = espGetConfig(route, "http.content.stylesheets", "css"); filename = mprJoinPathExt("css/all", ext); path = mprJoinPath(clientDir, filename); if (mprPathExists(path, R_OK)) { stylesheets(filename); } else if (!smatch(ext, "less")) { path = mprJoinPath(clientDir, "css/all.less"); if (mprPathExists(path, R_OK)) { stylesheets("css/all.less"); } } } } else { if (sends(patterns, "all.less")) { path = mprJoinPath(clientDir, "css/fix.css"); if (mprPathExists(path, R_OK)) { stylesheets("css/fix.css"); } } if ((files = mprGlobPathFiles(clientDir, patterns, MPR_PATH_RELATIVE)) == 0 || mprGetListLength(files) == 0) { files = mprCreateList(0, 0); mprAddItem(files, patterns); } for (ITERATE_ITEMS(files, path, next)) { path = sjoin("~/", strim(path, ".gz", MPR_TRIM_END), NULL); uri = httpLink(stream, path); kind = mprGetPathExt(path); if (smatch(kind, "css")) { espRender(stream, "<link rel='stylesheet' type='text/css' href='%s' />\n", uri); } else { espRender(stream, "<link rel='stylesheet/%s' type='text/css' href='%s' />\n", kind, uri); } } } }
PUBLIC ssize espRenderRec(HttpConn *conn, EdiRec *rec, int flags) { httpAddHeaderString(conn, "Content-Type", "application/json"); return espRender(conn, "{\"data\": %s, \"schema\": %s}", ediRecAsJson(rec, flags), ediGetRecSchemaAsJson(rec)); }