{"_id":"_design/basic","_rev":"492-fb5f0fcc1023d7e8404b4c9b6625b946","vendor":{"couchapp":{"evently":{"profile":{"profileReady":{"after":"function(e, p) {\r\n $$(this).profile = p;\r\n};","data":"function(e, p) {\r\n return p\r\n}","mustache":"
\r\n {{#gravatar_url}}{{/gravatar_url}}\r\n
\r\n {{nickname}}\r\n
\r\n
\r\n

Hello {{nickname}}!

\r\n
"},"noProfile":{"data":"function(e, userCtx) {\r\n return userCtx;\r\n}","mustache":"
\r\n

Hello {{name}}, Please setup your user profile.

\r\n \r\n \r\n \r\n \r\n \r\n
","selectors":{"form":{"submit":"function() {\r\n var md5 = $$(this).app.require(\"vendor/couchapp/lib/md5\");\r\n \r\n // TODO this can be cleaned up with docForm?\r\n // it still needs the workflow to edit an existing profile\r\n var name = $(\"input[name=userCtxName]\",this).val();\r\n var newProfile = {\r\n rand : Math.random().toString(), \r\n nickname : $(\"input[name=nickname]\",this).val(),\r\n email : $(\"input[name=email]\",this).val(),\r\n url : $(\"input[name=url]\",this).val()\r\n }, widget = $(this);\r\n\r\n // setup gravatar_url\r\n if (md5) {\r\n newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon'; \r\n }\r\n\r\n // store the user profile on the user account document\r\n $.couch.userDb(function(db) {\r\n var userDocId = \"org.couchdb.user:\"+name;\r\n db.openDoc(userDocId, {\r\n success : function(userDoc) {\r\n userDoc[\"couch.app.profile\"] = newProfile;\r\n db.saveDoc(userDoc, {\r\n success : function() {\r\n newProfile.name = userDoc.name;\r\n $$(widget).profile = newProfile;\r\n widget.trigger(\"profileReady\", [newProfile]);\r\n }\r\n });\r\n }\r\n });\r\n });\r\n return false;\r\n}"}}},"loggedIn":"function(e, r) {\r\n var userCtx = r.userCtx;\r\n var widget = $(this);\r\n // load the profile from the user doc\r\n var db = $.couch.db(r.info.authentication_db);\r\n var userDocId = \"org.couchdb.user:\"+userCtx.name;\r\n db.openDoc(userDocId, {\r\n success : function(userDoc) {\r\n var profile = userDoc[\"couch.app.profile\"];\r\n if (profile) {\r\n // we copy the name to the profile so it can be used later\r\n // without publishing the entire userdoc (roles, pass, etc)\r\n profile.name = userDoc.name;\r\n $$(widget).profile = profile;\r\n widget.trigger(\"profileReady\", [profile]);\r\n } else {\r\n widget.trigger(\"noProfile\", [userCtx]);\r\n }\r\n }\r\n });\r\n}","loggedOut":{"after":"function() {\r\n $$(this).profile = null;\r\n};","mustache":"

Please log in to see your profile.

"}},"README":"## Starting the Document this code challenge\r\n\r\nI need help on this code. I only have so many hours in the day. Please be liberal about patching and hacking (and sharing code!) so we can all benefit. \r\n\r\nDocs patches are deeply appreciated. For now you can just stick Markdown files in the Docs directory.\r\n\r\n# Evently\r\n\r\nThese are some vendor Evently widgets that are running on the CouchApp system.\r\n\r\n## Account\r\n This is how you signup, login and logout without worry about the code.\r\n Todo, we could have this work against remote APIs like that Facebook stuff or whatever.\r\n\r\n\r\n## Profile\r\n Use this to load the local users profile for the logged in user. Useful if you're going to be posting new messages. Most applications end up customizing `profile.profileReady` to render the primary data-entry form. This gets you benefits like refreshing on login / logout, etc, automatically.\r\n\r\n\r\n## Docs\r\n This needs to be moved to it's own app.\r\n I have this vision of a docs app designed for offline editing, that involves each Markdown paragraph being it's own document, with automatic use of Bespin for code samples. Any help on this would be thanked much.","account":{"loggedIn":{"after":"function(e, r) {\r\n $$(this).userCtx = r.userCtx;\r\n $$(this).info = r.info;\r\n};","data":"function(e, r) {\r\n return {\r\n name : r.userCtx.name,\r\n uri_name : encodeURIComponent(r.userCtx.name),\r\n auth_db : encodeURIComponent(r.info.authentication_db)\r\n };\r\n}","mustache":"Welcome \r\n{{name}}! \r\nLogout?\r\n","selectors":{"a[href=#logout]":{"click":["doLogout"]}}},"loginForm":{"after":"function() {\r\n $(\"input[name=name]\", this).focus();\r\n}","mustache":"
\r\n \r\n \r\n \r\n or Signup\r\n
","selectors":{"form":{"submit":"function(e) {\r\n var name = $('input[name=name]', this).val(),\r\n pass = $('input[name=password]', this).val(); \r\n $(this).trigger('doLogin', [name, pass]);\r\n return false;\r\n}"},"a[href=#signup]":{"click":["signupForm"]}}},"_init":"function() {\r\n var elem = $(this);\r\n $$(this).userCtx = null;\r\n $.couch.session({\r\n success : function(r) {\r\n var userCtx = r.userCtx;\r\n if (userCtx.name) {\r\n elem.trigger(\"loggedIn\", [r]);\r\n } else if (userCtx.roles.indexOf(\"_admin\") != -1) {\r\n elem.trigger(\"adminParty\");\r\n } else {\r\n elem.trigger(\"loggedOut\");\r\n };\r\n }\r\n });\r\n}","doLogout":"function() {\r\n var elem = $(this);\r\n $.couch.logout({\r\n success : function() {\r\n elem.trigger(\"_init\");\r\n }\r\n });\r\n}","loggedOut":{"mustache":"Signup or Login","selectors":{"a[href=#login]":{"click":["loginForm"]},"a[href=#signup]":{"click":["signupForm"]}}},"adminParty":{"mustache":"

Admin party, everyone is admin! Fix this in Futon before proceeding.

"},"doSignup":"function(e, name, pass) {\r\n var elem = $(this);\r\n $.couch.signup({\r\n name : name\r\n }, pass, {\r\n success : function() {\r\n elem.trigger(\"doLogin\", [name, pass]);\r\n }\r\n });\r\n}","signupForm":{"after":"function() {\r\n $(\"input[name=name]\", this).focus();\r\n}","mustache":"
\r\n \r\n \r\n \r\n or Login\r\n
","selectors":{"a[href=#login]":{"click":["loginForm"]},"form":{"submit":"function(e) {\r\n var name = $('input[name=name]', this).val(),\r\n pass = $('input[name=password]', this).val(); \r\n $(this).trigger('doSignup', [name, pass]);\r\n return false;\r\n}"}}},"doLogin":"function(e, name, pass) {\r\n var elem = $(this);\r\n $.couch.login({\r\n name : name,\r\n password : pass,\r\n success : function(r) {\r\n elem.trigger(\"_init\")\r\n }\r\n }); \r\n}"}},"lib":{"redirect":"exports.permanent = function(redirect) {\r\n return {\r\n code : 301,\r\n headers : {\r\n \"Location\" : redirect\r\n }\r\n };\r\n};","code":"exports.ddoc = function(ddoc) {\r\n // only return the parts of the app that we use\r\n var i, j, path, key, obj, ref, out = {},\r\n resources = ddoc.couchapp && ddoc.couchapp.load && ddoc.couchapp.load.app || [];\r\n for (i=0; i < resources.length; i++) {\r\n path = resources[i].split('/');\r\n obj = ddoc;\r\n ref = out;\r\n for (j=0; j < path.length; j++) {\r\n key = path[j];\r\n ref[key] = ref[key] || {};\r\n if (j < path.length - 1) {\r\n obj = obj[key];\r\n ref = ref[key];\r\n }\r\n };\r\n ref[key] = obj[key];\r\n };\r\n return out;\r\n};","utils":"exports.prettyDate = function(time){\r\n \r\n\tvar date = new Date(time.replace(/-/g,\"/\").replace(\"T\", \" \").replace(\"Z\", \" +0000\").replace(/(\\d*\\:\\d*:\\d*)\\.\\d*/g,\"$1\")),\r\n\t\tdiff = (((new Date()).getTime() - date.getTime()) / 1000),\r\n\t\tday_diff = Math.floor(diff / 86400);\r\n\r\n if (isNaN(day_diff)) return time;\r\n\r\n\treturn day_diff < 1 && (\r\n\t\t\tdiff < 60 && \"just now\" ||\r\n\t\t\tdiff < 120 && \"1 minute ago\" ||\r\n\t\t\tdiff < 3600 && Math.floor( diff / 60 ) + \" minutes ago\" ||\r\n\t\t\tdiff < 7200 && \"1 hour ago\" ||\r\n\t\t\tdiff < 86400 && Math.floor( diff / 3600 ) + \" hours ago\") ||\r\n\t\tday_diff == 1 && \"yesterday\" ||\r\n\t\tday_diff < 21 && day_diff + \" days ago\" ||\r\n\t\tday_diff < 45 && Math.ceil( day_diff / 7 ) + \" weeks ago\" ||\r\n time;\r\n // day_diff < 730 && Math.ceil( day_diff / 31 ) + \" months ago\" ||\r\n // Math.ceil( day_diff / 365 ) + \" years ago\";\r\n};","cache":"exports.get = function(db, docid, setFun, getFun) {\r\n db.openDoc(docid, {\r\n success : function(doc) {\r\n getFun(doc.cache);\r\n },\r\n error : function() {\r\n setFun(function(cache) {\r\n db.saveDoc({\r\n _id : docid,\r\n cache : cache\r\n });\r\n getFun(cache);\r\n });\r\n }\r\n });\r\n};\r\n\r\nexports.clear = function(db, docid) {\r\n db.openDoc(docid, {\r\n success : function(doc) {\r\n db.removeDoc(doc);\r\n },\r\n error : function() {}\r\n });\r\n};","list":"// Helpers for writing server-side _list functions in CouchDB\r\nexports.withRows = function(fun) {\r\n var f = function() {\r\n var row = getRow();\r\n return row && fun(row);\r\n };\r\n f.iterator = true;\r\n return f;\r\n}\r\n\r\nexports.send = function(chunk) {\r\n send(chunk + \"\\n\")\r\n}","linkup":"// this code makes http://example.com into a link, \r\n// and also handles @name and #hashtag\r\n\r\n// todo add [[wiki_links]]\r\n\r\nvar mustache = require(\"vendor/couchapp/lib/mustache\");\r\nexports.encode = function(body, person_prefix, tag_prefix) {\r\n body = mustache.escape(body);\r\n person_prefix = person_prefix || \"http://twitter.com/\";\r\n tag_prefix = tag_prefix || \"http://delicious.com/tag/\";\r\n return body.replace(/((ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?)/gi,function(a) {\r\n return ''+a+'';\r\n }).replace(/\\@([\\w\\-]+)/g,function(user,name) {\r\n return ''+user+'';\r\n }).replace(/\\#([\\w\\-\\.]+)/g,function(word,tag) {\r\n return ''+word+'';\r\n });\r\n};","markdown":"//\r\n// showdown.js -- A javascript port of Markdown.\r\n//\r\n// Copyright (c) 2007 John Fraser.\r\n//\r\n// Original Markdown Copyright (c) 2004-2005 John Gruber\r\n// \r\n//\r\n// Redistributable under a BSD-style open source license.\r\n// See license.txt for more information.\r\n//\r\n// The full source distribution is at:\r\n//\r\n//\t\t\t\tA A L\r\n//\t\t\t\tT C A\r\n//\t\t\t\tT K B\r\n//\r\n// \r\n//\r\n\r\n//\r\n// Wherever possible, Showdown is a straight, line-by-line port\r\n// of the Perl version of Markdown.\r\n//\r\n// This is not a normal parser design; it's basically just a\r\n// series of string substitutions. It's hard to read and\r\n// maintain this way, but keeping Showdown close to the original\r\n// design makes it easier to port new features.\r\n//\r\n// More importantly, Showdown behaves like markdown.pl in most\r\n// edge cases. So web applications can do client-side preview\r\n// in Javascript, and then build identical HTML on the server.\r\n//\r\n// This port needs the new RegExp functionality of ECMA 262,\r\n// 3rd Edition (i.e. Javascript 1.5). Most modern web browsers\r\n// should do fine. Even with the new regular expression features,\r\n// We do a lot of work to emulate Perl's regex functionality.\r\n// The tricky changes in this file mostly have the \"attacklab:\"\r\n// label. Major or self-explanatory changes don't.\r\n//\r\n// Smart diff tools like Araxis Merge will be able to match up\r\n// this file with markdown.pl in a useful way. A little tweaking\r\n// helps: in a copy of markdown.pl, replace \"#\" with \"//\" and\r\n// replace \"$text\" with \"text\". Be sure to ignore whitespace\r\n// and line endings.\r\n//\r\n\r\n\r\n//\r\n// Showdown usage:\r\n//\r\n// var text = \"Markdown *rocks*.\";\r\n//\r\n// var markdown = require(\"markdown\");\r\n// var html = markdown.encode(text);\r\n//\r\n// print(html);\r\n//\r\n// Note: move the sample code to the bottom of this\r\n// file before uncommenting it.\r\n//\r\n\r\n\r\n//\r\n// Globals:\r\n//\r\n\r\n// Global hashes, used by various utility routines\r\nvar g_urls;\r\nvar g_titles;\r\nvar g_html_blocks;\r\n\r\n// Used to track when we're inside an ordered or unordered list\r\n// (see _ProcessListItems() for details):\r\nvar g_list_level = 0;\r\n\r\n\r\nexports.makeHtml = function(text) {\r\n//\r\n// Main function. The order in which other subs are called here is\r\n// essential. Link and image substitutions need to happen before\r\n// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the \r\n// and tags get encoded.\r\n//\r\n\r\n\t// Clear the global hashes. If we don't clear these, you get conflicts\r\n\t// from other articles when generating a page which contains more than\r\n\t// one article (e.g. an index page that shows the N most recent\r\n\t// articles):\r\n\tg_urls = new Array();\r\n\tg_titles = new Array();\r\n\tg_html_blocks = new Array();\r\n\r\n\t// attacklab: Replace ~ with ~T\r\n\t// This lets us use tilde as an escape char to avoid md5 hashes\r\n\t// The choice of character is arbitray; anything that isn't\r\n // magic in Markdown will work.\r\n\ttext = text.replace(/~/g,\"~T\");\r\n\r\n\t// attacklab: Replace $ with ~D\r\n\t// RegExp interprets $ as a special character\r\n\t// when it's in a replacement string\r\n\ttext = text.replace(/\\$/g,\"~D\");\r\n\r\n\t// Standardize line endings\r\n\ttext = text.replace(/\\r\\n/g,\"\\n\"); // DOS to Unix\r\n\ttext = text.replace(/\\r/g,\"\\n\"); // Mac to Unix\r\n\r\n\t// Make sure text begins and ends with a couple of newlines:\r\n\ttext = \"\\n\\n\" + text + \"\\n\\n\";\r\n\r\n\t// Convert all tabs to spaces.\r\n\ttext = _Detab(text);\r\n\r\n\t// Strip any lines consisting only of spaces and tabs.\r\n\t// This makes subsequent regexen easier to write, because we can\r\n\t// match consecutive blank lines with /\\n+/ instead of something\r\n\t// contorted like /[ \\t]*\\n+/ .\r\n\ttext = text.replace(/^[ \\t]+$/mg,\"\");\r\n\r\n\t// Turn block-level HTML blocks into hash entries\r\n\ttext = _HashHTMLBlocks(text);\r\n\r\n\t// Strip link definitions, store in hashes.\r\n\ttext = _StripLinkDefinitions(text);\r\n\r\n\ttext = _RunBlockGamut(text);\r\n\r\n\ttext = _UnescapeSpecialChars(text);\r\n\r\n\t// attacklab: Restore dollar signs\r\n\ttext = text.replace(/~D/g,\"$$\");\r\n\r\n\t// attacklab: Restore tildes\r\n\ttext = text.replace(/~T/g,\"~\");\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _StripLinkDefinitions = function(text) {\r\n//\r\n// Strips link definitions from text, stores the URLs and titles in\r\n// hash references.\r\n//\r\n\r\n\t// Link defs are in the form: ^[id]: url \"optional title\"\r\n\r\n\t/*\r\n\t\tvar text = text.replace(/\r\n\t\t\t\t^[ ]{0,3}\\[(.+)\\]: // id = $1 attacklab: g_tab_width - 1\r\n\t\t\t\t [ \\t]*\r\n\t\t\t\t \\n?\t\t\t\t// maybe *one* newline\r\n\t\t\t\t [ \\t]*\r\n\t\t\t\t?\t\t\t// url = $2\r\n\t\t\t\t [ \\t]*\r\n\t\t\t\t \\n?\t\t\t\t// maybe one newline\r\n\t\t\t\t [ \\t]*\r\n\t\t\t\t(?:\r\n\t\t\t\t (\\n*)\t\t\t\t// any lines skipped = $3 attacklab: lookbehind removed\r\n\t\t\t\t [\"(]\r\n\t\t\t\t (.+?)\t\t\t\t// title = $4\r\n\t\t\t\t [\")]\r\n\t\t\t\t [ \\t]*\r\n\t\t\t\t)?\t\t\t\t\t// title is optional\r\n\t\t\t\t(?:\\n+|$)\r\n\t\t\t /gm,\r\n\t\t\t function(){...});\r\n\t*/\r\n\tvar text = text.replace(/^[ ]{0,3}\\[(.+)\\]:[ \\t]*\\n?[ \\t]*?[ \\t]*\\n?[ \\t]*(?:(\\n*)[\"(](.+?)[\")][ \\t]*)?(?:\\n+|\\Z)/gm,\r\n\t\tfunction (wholeMatch,m1,m2,m3,m4) {\r\n\t\t\tm1 = m1.toLowerCase();\r\n\t\t\tg_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive\r\n\t\t\tif (m3) {\r\n\t\t\t\t// Oops, found blank lines, so it's not a title.\r\n\t\t\t\t// Put back the parenthetical statement we stole.\r\n\t\t\t\treturn m3+m4;\r\n\t\t\t} else if (m4) {\r\n\t\t\t\tg_titles[m1] = m4.replace(/\"/g,\""\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Completely remove the definition from the text\r\n\t\t\treturn \"\";\r\n\t\t}\r\n\t);\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _HashHTMLBlocks = function(text) {\r\n\t// attacklab: Double up blank lines to reduce lookaround\r\n\ttext = text.replace(/\\n/g,\"\\n\\n\");\r\n\r\n\t// Hashify HTML blocks:\r\n\t// We only want to do this for block-level HTML tags, such as headers,\r\n\t// lists, and tables. That's because we still want to wrap

s around\r\n\t// \"paragraphs\" that are wrapped in non-block-level tags, such as anchors,\r\n\t// phrase emphasis, and spans. The list of tags we're looking for is\r\n\t// hard-coded:\r\n\tvar block_tags_a = \"p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del\"\r\n\tvar block_tags_b = \"p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math\"\r\n\r\n\t// First, look for nested blocks, e.g.:\r\n\t//

\r\n\t//
\r\n\t// tags for inner block must be indented.\r\n\t//
\r\n\t//
\r\n\t//\r\n\t// The outermost tags must start at the left margin for this to match, and\r\n\t// the inner nested divs must be indented.\r\n\t// We need to do this before the next, more liberal match, because the next\r\n\t// match will start at the first `
` and stop at the first `
`.\r\n\r\n\t// attacklab: This regex can be expensive when it fails.\r\n\t/*\r\n\t\tvar text = text.replace(/\r\n\t\t(\t\t\t\t\t\t// save in $1\r\n\t\t\t^\t\t\t\t\t// start of line (with /m)\r\n\t\t\t<($block_tags_a)\t// start tag = $2\r\n\t\t\t\\b\t\t\t\t\t// word break\r\n\t\t\t\t\t\t\t\t// attacklab: hack around khtml/pcre bug...\r\n\t\t\t[^\\r]*?\\n\t\t\t// any number of lines, minimally matching\r\n\t\t\t\t\t\t\t// the matching end tag\r\n\t\t\t[ \\t]*\t\t\t\t// trailing spaces/tabs\r\n\t\t\t(?=\\n+)\t\t\t\t// followed by a newline\r\n\t\t)\t\t\t\t\t\t// attacklab: there are sentinel newlines at end of document\r\n\t\t/gm,function(){...}};\r\n\t*/\r\n\ttext = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\\b[^\\r]*?\\n<\\/\\2>[ \\t]*(?=\\n+))/gm,hashElement);\r\n\r\n\t//\r\n\t// Now match more liberally, simply from `\\n` to `\\n`\r\n\t//\r\n\r\n\t/*\r\n\t\tvar text = text.replace(/\r\n\t\t(\t\t\t\t\t\t// save in $1\r\n\t\t\t^\t\t\t\t\t// start of line (with /m)\r\n\t\t\t<($block_tags_b)\t// start tag = $2\r\n\t\t\t\\b\t\t\t\t\t// word break\r\n\t\t\t\t\t\t\t\t// attacklab: hack around khtml/pcre bug...\r\n\t\t\t[^\\r]*?\t\t\t\t// any number of lines, minimally matching\r\n\t\t\t.*\t\t\t\t// the matching end tag\r\n\t\t\t[ \\t]*\t\t\t\t// trailing spaces/tabs\r\n\t\t\t(?=\\n+)\t\t\t\t// followed by a newline\r\n\t\t)\t\t\t\t\t\t// attacklab: there are sentinel newlines at end of document\r\n\t\t/gm,function(){...}};\r\n\t*/\r\n\ttext = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\\b[^\\r]*?.*<\\/\\2>[ \\t]*(?=\\n+)\\n)/gm,hashElement);\r\n\r\n\t// Special case just for
. It was easier to make a special case than\r\n\t// to make the other regex more complicated. \r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t// save in $1\r\n\t\t\t\\n\\n\t\t\t\t// Starting after a blank line\r\n\t\t\t[ ]{0,3}\r\n\t\t\t(<(hr)\t\t\t\t// start tag = $2\r\n\t\t\t\\b\t\t\t\t\t// word break\r\n\t\t\t([^<>])*?\t\t\t// \r\n\t\t\t\\/?>)\t\t\t\t// the matching end tag\r\n\t\t\t[ \\t]*\r\n\t\t\t(?=\\n{2,})\t\t\t// followed by a blank line\r\n\t\t)\r\n\t\t/g,hashElement);\r\n\t*/\r\n\ttext = text.replace(/(\\n[ ]{0,3}(<(hr)\\b([^<>])*?\\/?>)[ \\t]*(?=\\n{2,}))/g,hashElement);\r\n\r\n\t// Special case for standalone HTML comments:\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t// save in $1\r\n\t\t\t\\n\\n\t\t\t\t// Starting after a blank line\r\n\t\t\t[ ]{0,3}\t\t\t// attacklab: g_tab_width - 1\r\n\t\t\t\r\n\t\t\t[ \\t]*\r\n\t\t\t(?=\\n{2,})\t\t\t// followed by a blank line\r\n\t\t)\r\n\t\t/g,hashElement);\r\n\t*/\r\n\ttext = text.replace(/(\\n\\n[ ]{0,3}[ \\t]*(?=\\n{2,}))/g,hashElement);\r\n\r\n\t// PHP and ASP-style processor instructions ( and <%...%>)\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(?:\r\n\t\t\t\\n\\n\t\t\t\t// Starting after a blank line\r\n\t\t)\r\n\t\t(\t\t\t\t\t\t// save in $1\r\n\t\t\t[ ]{0,3}\t\t\t// attacklab: g_tab_width - 1\r\n\t\t\t(?:\r\n\t\t\t\t<([?%])\t\t\t// $2\r\n\t\t\t\t[^\\r]*?\r\n\t\t\t\t\\2>\r\n\t\t\t)\r\n\t\t\t[ \\t]*\r\n\t\t\t(?=\\n{2,})\t\t\t// followed by a blank line\r\n\t\t)\r\n\t\t/g,hashElement);\r\n\t*/\r\n\ttext = text.replace(/(?:\\n\\n)([ ]{0,3}(?:<([?%])[^\\r]*?\\2>)[ \\t]*(?=\\n{2,}))/g,hashElement);\r\n\r\n\t// attacklab: Undo double lines (see comment at top of this function)\r\n\ttext = text.replace(/\\n\\n/g,\"\\n\");\r\n\treturn text;\r\n}\r\n\r\nvar hashElement = function(wholeMatch,m1) {\r\n\tvar blockText = m1;\r\n\r\n\t// Undo double lines\r\n\tblockText = blockText.replace(/\\n\\n/g,\"\\n\");\r\n\tblockText = blockText.replace(/^\\n/,\"\");\r\n\t\r\n\t// strip trailing blank lines\r\n\tblockText = blockText.replace(/\\n+$/g,\"\");\r\n\t\r\n\t// Replace the element text with a marker (\"~KxK\" where x is its key)\r\n\tblockText = \"\\n\\n~K\" + (g_html_blocks.push(blockText)-1) + \"K\\n\\n\";\r\n\t\r\n\treturn blockText;\r\n};\r\n\r\nvar _RunBlockGamut = function(text) {\r\n//\r\n// These are all the transformations that form block-level\r\n// tags like paragraphs, headers, and list items.\r\n//\r\n\ttext = _DoHeaders(text);\r\n\r\n\t// Do Horizontal Rules:\r\n\tvar key = hashBlock(\"
\");\r\n\ttext = text.replace(/^[ ]{0,2}([ ]?\\*[ ]?){3,}[ \\t]*$/gm,key);\r\n\ttext = text.replace(/^[ ]{0,2}([ ]?\\-[ ]?){3,}[ \\t]*$/gm,key);\r\n\ttext = text.replace(/^[ ]{0,2}([ ]?\\_[ ]?){3,}[ \\t]*$/gm,key);\r\n\r\n\ttext = _DoLists(text);\r\n\ttext = _DoCodeBlocks(text);\r\n\ttext = _DoBlockQuotes(text);\r\n\r\n\t// We already ran _HashHTMLBlocks() before, in Markdown(), but that\r\n\t// was to escape raw HTML in the original Markdown source. This time,\r\n\t// we're escaping the markup we've just created, so that we don't wrap\r\n\t//

tags around block-level tags.\r\n\ttext = _HashHTMLBlocks(text);\r\n\ttext = _FormParagraphs(text);\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _RunSpanGamut = function(text) {\r\n//\r\n// These are all the transformations that occur *within* block-level\r\n// tags like paragraphs, headers, and list items.\r\n//\r\n\r\n\ttext = _DoCodeSpans(text);\r\n\ttext = _EscapeSpecialCharsWithinTagAttributes(text);\r\n\ttext = _EncodeBackslashEscapes(text);\r\n\r\n\t// Process anchor and image tags. Images must come first,\r\n\t// because ![foo][f] looks like an anchor.\r\n\ttext = _DoImages(text);\r\n\ttext = _DoAnchors(text);\r\n\r\n\t// Make links out of things like ``\r\n\t// Must come after _DoAnchors(), because you can use < and >\r\n\t// delimiters in inline links like [this]().\r\n\ttext = _DoAutoLinks(text);\r\n\ttext = _EncodeAmpsAndAngles(text);\r\n\ttext = _DoItalicsAndBold(text);\r\n\r\n\t// Do hard breaks:\r\n\ttext = text.replace(/ +\\n/g,\"
\\n\");\r\n\r\n\treturn text;\r\n}\r\n\r\nvar _EscapeSpecialCharsWithinTagAttributes = function(text) {\r\n//\r\n// Within tags -- meaning between < and > -- encode [\\ ` * _] so they\r\n// don't conflict with their use in Markdown for code, italics and strong.\r\n//\r\n\r\n\t// Build a regex to find HTML tags and comments. See Friedl's \r\n\t// \"Mastering Regular Expressions\", 2nd Ed., pp. 200-201.\r\n\tvar regex = /(<[a-z\\/!$](\"[^\"]*\"|'[^']*'|[^'\">])*>|)/gi;\r\n\r\n\ttext = text.replace(regex, function(wholeMatch) {\r\n\t\tvar tag = wholeMatch.replace(/(.)<\\/?code>(?=.)/g,\"$1`\");\r\n\t\ttag = escapeCharacters(tag,\"\\\\`*_\");\r\n\t\treturn tag;\r\n\t});\r\n\r\n\treturn text;\r\n}\r\n\r\nvar _DoAnchors = function(text) {\r\n//\r\n// Turn Markdown link shortcuts into XHTML
tags.\r\n//\r\n\t//\r\n\t// First, handle reference-style links: [link text] [id]\r\n\t//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t\t// wrap whole match in $1\r\n\t\t\t\\[\r\n\t\t\t(\r\n\t\t\t\t(?:\r\n\t\t\t\t\t\\[[^\\]]*\\]\t\t// allow brackets nested one level\r\n\t\t\t\t\t|\r\n\t\t\t\t\t[^\\[]\t\t\t// or anything else\r\n\t\t\t\t)*\r\n\t\t\t)\r\n\t\t\t\\]\r\n\r\n\t\t\t[ ]?\t\t\t\t\t// one optional space\r\n\t\t\t(?:\\n[ ]*)?\t\t\t\t// one optional newline followed by spaces\r\n\r\n\t\t\t\\[\r\n\t\t\t(.*?)\t\t\t\t\t// id = $3\r\n\t\t\t\\]\r\n\t\t)()()()()\t\t\t\t\t// pad remaining backreferences\r\n\t\t/g,_DoAnchors_callback);\r\n\t*/\r\n\ttext = text.replace(/(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()/g,writeAnchorTag);\r\n\r\n\t//\r\n\t// Next, inline-style links: [link text](url \"optional title\")\r\n\t//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t\t(\t\t\t\t\t\t// wrap whole match in $1\r\n\t\t\t\t\\[\r\n\t\t\t\t(\r\n\t\t\t\t\t(?:\r\n\t\t\t\t\t\t\\[[^\\]]*\\]\t// allow brackets nested one level\r\n\t\t\t\t\t|\r\n\t\t\t\t\t[^\\[\\]]\t\t\t// or anything else\r\n\t\t\t\t)\r\n\t\t\t)\r\n\t\t\t\\]\r\n\t\t\t\\(\t\t\t\t\t\t// literal paren\r\n\t\t\t[ \\t]*\r\n\t\t\t()\t\t\t\t\t\t// no id, so leave $3 empty\r\n\t\t\t?\t\t\t\t// href = $4\r\n\t\t\t[ \\t]*\r\n\t\t\t(\t\t\t\t\t\t// $5\r\n\t\t\t\t(['\"])\t\t\t\t// quote char = $6\r\n\t\t\t\t(.*?)\t\t\t\t// Title = $7\r\n\t\t\t\t\\6\t\t\t\t\t// matching quote\r\n\t\t\t\t[ \\t]*\t\t\t\t// ignore any spaces/tabs between closing quote and )\r\n\t\t\t)?\t\t\t\t\t\t// title is optional\r\n\t\t\t\\)\r\n\t\t)\r\n\t\t/g,writeAnchorTag);\r\n\t*/\r\n\ttext = text.replace(/(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]\\([ \\t]*()?[ \\t]*((['\"])(.*?)\\6[ \\t]*)?\\))/g,writeAnchorTag);\r\n\r\n\t//\r\n\t// Last, handle reference-style shortcuts: [link text]\r\n\t// These must come last in case you've also got [link test][1]\r\n\t// or [link test](/foo)\r\n\t//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t \t\t\t\t\t// wrap whole match in $1\r\n\t\t\t\\[\r\n\t\t\t([^\\[\\]]+)\t\t\t\t// link text = $2; can't contain '[' or ']'\r\n\t\t\t\\]\r\n\t\t)()()()()()\t\t\t\t\t// pad rest of backreferences\r\n\t\t/g, writeAnchorTag);\r\n\t*/\r\n\ttext = text.replace(/(\\[([^\\[\\]]+)\\])()()()()()/g, writeAnchorTag);\r\n\r\n\treturn text;\r\n}\r\n\r\nvar writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {\r\n\tif (m7 == undefined) m7 = \"\";\r\n\tvar whole_match = m1;\r\n\tvar link_text = m2;\r\n\tvar link_id\t = m3.toLowerCase();\r\n\tvar url\t\t= m4;\r\n\tvar title\t= m7;\r\n\t\r\n\tif (url == \"\") {\r\n\t\tif (link_id == \"\") {\r\n\t\t\t// lower-case and turn embedded newlines into spaces\r\n\t\t\tlink_id = link_text.toLowerCase().replace(/ ?\\n/g,\" \");\r\n\t\t}\r\n\t\turl = \"#\"+link_id;\r\n\t\t\r\n\t\tif (g_urls[link_id] != undefined) {\r\n\t\t\turl = g_urls[link_id];\r\n\t\t\tif (g_titles[link_id] != undefined) {\r\n\t\t\t\ttitle = g_titles[link_id];\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\tif (whole_match.search(/\\(\\s*\\)$/m)>-1) {\r\n\t\t\t\t// Special case for explicit empty url\r\n\t\t\t\turl = \"\";\r\n\t\t\t} else {\r\n\t\t\t\treturn whole_match;\r\n\t\t\t}\r\n\t\t}\r\n\t}\t\r\n\t\r\n\turl = escapeCharacters(url,\"*_\");\r\n\tvar result = \"\" + link_text + \"\";\r\n\t\r\n\treturn result;\r\n}\r\n\r\n\r\nvar _DoImages = function(text) {\r\n//\r\n// Turn Markdown image shortcuts into tags.\r\n//\r\n\r\n\t//\r\n\t// First, handle reference-style labeled images: ![alt text][id]\r\n\t//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t// wrap whole match in $1\r\n\t\t\t!\\[\r\n\t\t\t(.*?)\t\t\t\t// alt text = $2\r\n\t\t\t\\]\r\n\r\n\t\t\t[ ]?\t\t\t\t// one optional space\r\n\t\t\t(?:\\n[ ]*)?\t\t\t// one optional newline followed by spaces\r\n\r\n\t\t\t\\[\r\n\t\t\t(.*?)\t\t\t\t// id = $3\r\n\t\t\t\\]\r\n\t\t)()()()()\t\t\t\t// pad rest of backreferences\r\n\t\t/g,writeImageTag);\r\n\t*/\r\n\ttext = text.replace(/(!\\[(.*?)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()/g,writeImageTag);\r\n\r\n\t//\r\n\t// Next, handle inline images: ![alt text](url \"optional title\")\r\n\t// Don't forget: encode * and _\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t// wrap whole match in $1\r\n\t\t\t!\\[\r\n\t\t\t(.*?)\t\t\t\t// alt text = $2\r\n\t\t\t\\]\r\n\t\t\t\\s?\t\t\t\t\t// One optional whitespace character\r\n\t\t\t\\(\t\t\t\t\t// literal paren\r\n\t\t\t[ \\t]*\r\n\t\t\t()\t\t\t\t\t// no id, so leave $3 empty\r\n\t\t\t?\t\t\t// src url = $4\r\n\t\t\t[ \\t]*\r\n\t\t\t(\t\t\t\t\t// $5\r\n\t\t\t\t(['\"])\t\t\t// quote char = $6\r\n\t\t\t\t(.*?)\t\t\t// title = $7\r\n\t\t\t\t\\6\t\t\t\t// matching quote\r\n\t\t\t\t[ \\t]*\r\n\t\t\t)?\t\t\t\t\t// title is optional\r\n\t\t\\)\r\n\t\t)\r\n\t\t/g,writeImageTag);\r\n\t*/\r\n\ttext = text.replace(/(!\\[(.*?)\\]\\s?\\([ \\t]*()?[ \\t]*((['\"])(.*?)\\6[ \\t]*)?\\))/g,writeImageTag);\r\n\r\n\treturn text;\r\n}\r\n\r\nvar writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {\r\n\tvar whole_match = m1;\r\n\tvar alt_text = m2;\r\n\tvar link_id\t = m3.toLowerCase();\r\n\tvar url\t\t= m4;\r\n\tvar title\t= m7;\r\n\r\n\tif (!title) title = \"\";\r\n\t\r\n\tif (url == \"\") {\r\n\t\tif (link_id == \"\") {\r\n\t\t\t// lower-case and turn embedded newlines into spaces\r\n\t\t\tlink_id = alt_text.toLowerCase().replace(/ ?\\n/g,\" \");\r\n\t\t}\r\n\t\turl = \"#\"+link_id;\r\n\t\t\r\n\t\tif (g_urls[link_id] != undefined) {\r\n\t\t\turl = g_urls[link_id];\r\n\t\t\tif (g_titles[link_id] != undefined) {\r\n\t\t\t\ttitle = g_titles[link_id];\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\treturn whole_match;\r\n\t\t}\r\n\t}\t\r\n\t\r\n\talt_text = alt_text.replace(/\"/g,\""\");\r\n\turl = escapeCharacters(url,\"*_\");\r\n\tvar result = \"\\\"\"\";\r\n\t\r\n\treturn result;\r\n}\r\n\r\n\r\nvar _DoHeaders = function(text) {\r\n\r\n\t// Setext-style headers:\r\n\t//\tHeader 1\r\n\t//\t========\r\n\t// \r\n\t//\tHeader 2\r\n\t//\t--------\r\n\t//\r\n\ttext = text.replace(/^(.+)[ \\t]*\\n=+[ \\t]*\\n+/gm,\r\n\t\tfunction(wholeMatch,m1){return hashBlock(\"

\" + _RunSpanGamut(m1) + \"

\");});\r\n\r\n\ttext = text.replace(/^(.+)[ \\t]*\\n-+[ \\t]*\\n+/gm,\r\n\t\tfunction(matchFound,m1){return hashBlock(\"

\" + _RunSpanGamut(m1) + \"

\");});\r\n\r\n\t// atx-style headers:\r\n\t// # Header 1\r\n\t// ## Header 2\r\n\t// ## Header 2 with closing hashes ##\r\n\t// ...\r\n\t// ###### Header 6\r\n\t//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t\t^(\\#{1,6})\t\t\t\t// $1 = string of #'s\r\n\t\t\t[ \\t]*\r\n\t\t\t(.+?)\t\t\t\t\t// $2 = Header text\r\n\t\t\t[ \\t]*\r\n\t\t\t\\#*\t\t\t\t\t\t// optional closing #'s (not counted)\r\n\t\t\t\\n+\r\n\t\t/gm, function() {...});\r\n\t*/\r\n\r\n\ttext = text.replace(/^(\\#{1,6})[ \\t]*(.+?)[ \\t]*\\#*\\n+/gm,\r\n\t\tfunction(wholeMatch,m1,m2) {\r\n\t\t\tvar h_level = m1.length;\r\n\t\t\treturn hashBlock(\"\" + _RunSpanGamut(m2) + \"\");\r\n\t\t});\r\n\r\n\treturn text;\r\n}\r\n\r\n// This declaration keeps Dojo compressor from outputting garbage:\r\nvar _ProcessListItems;\r\n\r\nvar _DoLists = function(text) {\r\n//\r\n// Form HTML ordered (numbered) and unordered (bulleted) lists.\r\n//\r\n\r\n\t// attacklab: add sentinel to hack around khtml/safari bug:\r\n\t// http://bugs.webkit.org/show_bug.cgi?id=11231\r\n\ttext += \"~0\";\r\n\r\n\t// Re-usable pattern to match any entirel ul or ol list:\r\n\r\n\t/*\r\n\t\tvar whole_list = /\r\n\t\t(\t\t\t\t\t\t\t\t\t// $1 = whole list\r\n\t\t\t(\t\t\t\t\t\t\t\t// $2\r\n\t\t\t\t[ ]{0,3}\t\t\t\t\t// attacklab: g_tab_width - 1\r\n\t\t\t\t([*+-]|\\d+[.])\t\t\t\t// $3 = first list item marker\r\n\t\t\t\t[ \\t]+\r\n\t\t\t)\r\n\t\t\t[^\\r]+?\r\n\t\t\t(\t\t\t\t\t\t\t\t// $4\r\n\t\t\t\t~0\t\t\t\t\t\t\t// sentinel for workaround; should be $\r\n\t\t\t|\r\n\t\t\t\t\\n{2,}\r\n\t\t\t\t(?=\\S)\r\n\t\t\t\t(?!\t\t\t\t\t\t\t// Negative lookahead for another list item marker\r\n\t\t\t\t\t[ \\t]*\r\n\t\t\t\t\t(?:[*+-]|\\d+[.])[ \\t]+\r\n\t\t\t\t)\r\n\t\t\t)\r\n\t\t)/g\r\n\t*/\r\n\tvar whole_list = /^(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/gm;\r\n\r\n\tif (g_list_level) {\r\n\t\ttext = text.replace(whole_list,function(wholeMatch,m1,m2) {\r\n\t\t\tvar list = m1;\r\n\t\t\tvar list_type = (m2.search(/[*+-]/g)>-1) ? \"ul\" : \"ol\";\r\n\r\n\t\t\t// Turn double returns into triple returns, so that we can make a\r\n\t\t\t// paragraph for the last item in a list, if necessary:\r\n\t\t\tlist = list.replace(/\\n{2,}/g,\"\\n\\n\\n\");;\r\n\t\t\tvar result = _ProcessListItems(list);\r\n\t\r\n\t\t\t// Trim any trailing whitespace, to put the closing ``\r\n\t\t\t// up on the preceding line, to get it past the current stupid\r\n\t\t\t// HTML block parser. This is a hack to work around the terrible\r\n\t\t\t// hack that is the HTML block parser.\r\n\t\t\tresult = result.replace(/\\s+$/,\"\");\r\n\t\t\tresult = \"<\"+list_type+\">\" + result + \"\\n\";\r\n\t\t\treturn result;\r\n\t\t});\r\n\t} else {\r\n\t\twhole_list = /(\\n\\n|^\\n?)(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/g;\r\n\t\ttext = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {\r\n\t\t\tvar runup = m1;\r\n\t\t\tvar list = m2;\r\n\r\n\t\t\tvar list_type = (m3.search(/[*+-]/g)>-1) ? \"ul\" : \"ol\";\r\n\t\t\t// Turn double returns into triple returns, so that we can make a\r\n\t\t\t// paragraph for the last item in a list, if necessary:\r\n\t\t\tvar list = list.replace(/\\n{2,}/g,\"\\n\\n\\n\");;\r\n\t\t\tvar result = _ProcessListItems(list);\r\n\t\t\tresult = runup + \"<\"+list_type+\">\\n\" + result + \"\\n\";\t\r\n\t\t\treturn result;\r\n\t\t});\r\n\t}\r\n\r\n\t// attacklab: strip sentinel\r\n\ttext = text.replace(/~0/,\"\");\r\n\r\n\treturn text;\r\n}\r\n\r\n_ProcessListItems = function(list_str) {\r\n//\r\n// Process the contents of a single ordered or unordered list, splitting it\r\n// into individual list items.\r\n//\r\n\t// The $g_list_level global keeps track of when we're inside a list.\r\n\t// Each time we enter a list, we increment it; when we leave a list,\r\n\t// we decrement. If it's zero, we're not in a list anymore.\r\n\t//\r\n\t// We do this because when we're not inside a list, we want to treat\r\n\t// something like this:\r\n\t//\r\n\t// I recommend upgrading to version\r\n\t// 8. Oops, now this line is treated\r\n\t// as a sub-list.\r\n\t//\r\n\t// As a single paragraph, despite the fact that the second line starts\r\n\t// with a digit-period-space sequence.\r\n\t//\r\n\t// Whereas when we're inside a list (or sub-list), that line will be\r\n\t// treated as the start of a sub-list. What a kludge, huh? This is\r\n\t// an aspect of Markdown's syntax that's hard to parse perfectly\r\n\t// without resorting to mind-reading. Perhaps the solution is to\r\n\t// change the syntax rules such that sub-lists must start with a\r\n\t// starting cardinal number; e.g. \"1.\" or \"a.\".\r\n\r\n\tg_list_level++;\r\n\r\n\t// trim trailing blank lines:\r\n\tlist_str = list_str.replace(/\\n{2,}$/,\"\\n\");\r\n\r\n\t// attacklab: add sentinel to emulate \\z\r\n\tlist_str += \"~0\";\r\n\r\n\t/*\r\n\t\tlist_str = list_str.replace(/\r\n\t\t\t(\\n)?\t\t\t\t\t\t\t// leading line = $1\r\n\t\t\t(^[ \\t]*)\t\t\t\t\t\t// leading whitespace = $2\r\n\t\t\t([*+-]|\\d+[.]) [ \\t]+\t\t\t// list marker = $3\r\n\t\t\t([^\\r]+?\t\t\t\t\t\t// list item text = $4\r\n\t\t\t(\\n{1,2}))\r\n\t\t\t(?= \\n* (~0 | \\2 ([*+-]|\\d+[.]) [ \\t]+))\r\n\t\t/gm, function(){...});\r\n\t*/\r\n\tlist_str = list_str.replace(/(\\n)?(^[ \\t]*)([*+-]|\\d+[.])[ \\t]+([^\\r]+?(\\n{1,2}))(?=\\n*(~0|\\2([*+-]|\\d+[.])[ \\t]+))/gm,\r\n\t\tfunction(wholeMatch,m1,m2,m3,m4){\r\n\t\t\tvar item = m4;\r\n\t\t\tvar leading_line = m1;\r\n\t\t\tvar leading_space = m2;\r\n\r\n\t\t\tif (leading_line || (item.search(/\\n{2,}/)>-1)) {\r\n\t\t\t\titem = _RunBlockGamut(_Outdent(item));\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// Recursion for sub-lists:\r\n\t\t\t\titem = _DoLists(_Outdent(item));\r\n\t\t\t\titem = item.replace(/\\n$/,\"\"); // chomp(item)\r\n\t\t\t\titem = _RunSpanGamut(item);\r\n\t\t\t}\r\n\r\n\t\t\treturn \"
  • \" + item + \"
  • \\n\";\r\n\t\t}\r\n\t);\r\n\r\n\t// attacklab: strip sentinel\r\n\tlist_str = list_str.replace(/~0/g,\"\");\r\n\r\n\tg_list_level--;\r\n\treturn list_str;\r\n}\r\n\r\n\r\nvar _DoCodeBlocks = function(text) {\r\n//\r\n// Process Markdown `
    ` blocks.\r\n//  \r\n\r\n\t/*\r\n\t\ttext = text.replace(text,\r\n\t\t\t/(?:\\n\\n|^)\r\n\t\t\t(\t\t\t\t\t\t\t\t// $1 = the code block -- one or more lines, starting with a space/tab\r\n\t\t\t\t(?:\r\n\t\t\t\t\t(?:[ ]{4}|\\t)\t\t\t// Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width\r\n\t\t\t\t\t.*\\n+\r\n\t\t\t\t)+\r\n\t\t\t)\r\n\t\t\t(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))\t// attacklab: g_tab_width\r\n\t\t/g,function(){...});\r\n\t*/\r\n\r\n\t// attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\r\n\ttext += \"~0\";\r\n\t\r\n\ttext = text.replace(/(?:\\n\\n|^)((?:(?:[ ]{4}|\\t).*\\n+)+)(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))/g,\r\n\t\tfunction(wholeMatch,m1,m2) {\r\n\t\t\tvar codeblock = m1;\r\n\t\t\tvar nextChar = m2;\r\n\t\t\r\n\t\t\tcodeblock = _EncodeCode( _Outdent(codeblock));\r\n\t\t\tcodeblock = _Detab(codeblock);\r\n\t\t\tcodeblock = codeblock.replace(/^\\n+/g,\"\"); // trim leading newlines\r\n\t\t\tcodeblock = codeblock.replace(/\\n+$/g,\"\"); // trim trailing whitespace\r\n\r\n\t\t\tcodeblock = \"
    \" + codeblock + \"\\n
    \";\r\n\r\n\t\t\treturn hashBlock(codeblock) + nextChar;\r\n\t\t}\r\n\t);\r\n\r\n\t// attacklab: strip sentinel\r\n\ttext = text.replace(/~0/,\"\");\r\n\r\n\treturn text;\r\n}\r\n\r\nvar hashBlock = function(text) {\r\n\ttext = text.replace(/(^\\n+|\\n+$)/g,\"\");\r\n\treturn \"\\n\\n~K\" + (g_html_blocks.push(text)-1) + \"K\\n\\n\";\r\n}\r\n\r\n\r\nvar _DoCodeSpans = function(text) {\r\n//\r\n// * Backtick quotes are used for spans.\r\n// \r\n// * You can use multiple backticks as the delimiters if you want to\r\n//\t include literal backticks in the code span. So, this input:\r\n//\t \r\n//\t\t Just type ``foo `bar` baz`` at the prompt.\r\n//\t \r\n//\t Will translate to:\r\n//\t \r\n//\t\t

    Just type foo `bar` baz at the prompt.

    \r\n//\t \r\n//\tThere's no arbitrary limit to the number of backticks you\r\n//\tcan use as delimters. If you need three consecutive backticks\r\n//\tin your code, use four for delimiters, etc.\r\n//\r\n// * You can use spaces to get literal backticks at the edges:\r\n//\t \r\n//\t\t ... type `` `bar` `` ...\r\n//\t \r\n//\t Turns to:\r\n//\t \r\n//\t\t ... type `bar` ...\r\n//\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t\t(^|[^\\\\])\t\t\t\t\t// Character before opening ` can't be a backslash\r\n\t\t\t(`+)\t\t\t\t\t\t// $2 = Opening run of `\r\n\t\t\t(\t\t\t\t\t\t\t// $3 = The code block\r\n\t\t\t\t[^\\r]*?\r\n\t\t\t\t[^`]\t\t\t\t\t// attacklab: work around lack of lookbehind\r\n\t\t\t)\r\n\t\t\t\\2\t\t\t\t\t\t\t// Matching closer\r\n\t\t\t(?!`)\r\n\t\t/gm, function(){...});\r\n\t*/\r\n\r\n\ttext = text.replace(/(^|[^\\\\])(`+)([^\\r]*?[^`])\\2(?!`)/gm,\r\n\t\tfunction(wholeMatch,m1,m2,m3,m4) {\r\n\t\t\tvar c = m3;\r\n\t\t\tc = c.replace(/^([ \\t]*)/g,\"\");\t// leading whitespace\r\n\t\t\tc = c.replace(/[ \\t]*$/g,\"\");\t// trailing whitespace\r\n\t\t\tc = _EncodeCode(c);\r\n\t\t\treturn m1+\"\"+c+\"\";\r\n\t\t});\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _EncodeCode = function(text) {\r\n//\r\n// Encode/escape certain characters inside Markdown code runs.\r\n// The point is that in code, these characters are literals,\r\n// and lose their special Markdown meanings.\r\n//\r\n\t// Encode all ampersands; HTML entities are not\r\n\t// entities within a Markdown code span.\r\n\ttext = text.replace(/&/g,\"&\");\r\n\r\n\t// Do the angle bracket song and dance:\r\n\ttext = text.replace(//g,\">\");\r\n\r\n\t// Now, escape characters that are magic in Markdown:\r\n\ttext = escapeCharacters(text,\"\\*_{}[]\\\\\",false);\r\n\r\n// jj the line above breaks this:\r\n//---\r\n\r\n//* Item\r\n\r\n// 1. Subitem\r\n\r\n// special char: *\r\n//---\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _DoItalicsAndBold = function(text) {\r\n\r\n\t// must go first:\r\n\ttext = text.replace(/(\\*\\*|__)(?=\\S)([^\\r]*?\\S[*_]*)\\1/g,\r\n\t\t\"$2\");\r\n\r\n\ttext = text.replace(/(\\*|_)(?=\\S)([^\\r]*?\\S)\\1/g,\r\n\t\t\"$2\");\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _DoBlockQuotes = function(text) {\r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t(\t\t\t\t\t\t\t\t// Wrap whole match in $1\r\n\t\t\t(\r\n\t\t\t\t^[ \\t]*>[ \\t]?\t\t\t// '>' at the start of a line\r\n\t\t\t\t.+\\n\t\t\t\t\t// rest of the first line\r\n\t\t\t\t(.+\\n)*\t\t\t\t\t// subsequent consecutive lines\r\n\t\t\t\t\\n*\t\t\t\t\t\t// blanks\r\n\t\t\t)+\r\n\t\t)\r\n\t\t/gm, function(){...});\r\n\t*/\r\n\r\n\ttext = text.replace(/((^[ \\t]*>[ \\t]?.+\\n(.+\\n)*\\n*)+)/gm,\r\n\t\tfunction(wholeMatch,m1) {\r\n\t\t\tvar bq = m1;\r\n\r\n\t\t\t// attacklab: hack around Konqueror 3.5.4 bug:\r\n\t\t\t// \"----------bug\".replace(/^-/g,\"\") == \"bug\"\r\n\r\n\t\t\tbq = bq.replace(/^[ \\t]*>[ \\t]?/gm,\"~0\");\t// trim one level of quoting\r\n\r\n\t\t\t// attacklab: clean up hack\r\n\t\t\tbq = bq.replace(/~0/g,\"\");\r\n\r\n\t\t\tbq = bq.replace(/^[ \\t]+$/gm,\"\");\t\t// trim whitespace-only lines\r\n\t\t\tbq = _RunBlockGamut(bq);\t\t\t\t// recurse\r\n\t\t\t\r\n\t\t\tbq = bq.replace(/(^|\\n)/g,\"$1 \");\r\n\t\t\t// These leading spaces screw with
     content, so we need to fix that:\r\n\t\t\tbq = bq.replace(\r\n\t\t\t\t\t/(\\s*
    [^\\r]+?<\\/pre>)/gm,\r\n\t\t\t\tfunction(wholeMatch,m1) {\r\n\t\t\t\t\tvar pre = m1;\r\n\t\t\t\t\t// attacklab: hack around Konqueror 3.5.4 bug:\r\n\t\t\t\t\tpre = pre.replace(/^  /mg,\"~0\");\r\n\t\t\t\t\tpre = pre.replace(/~0/g,\"\");\r\n\t\t\t\t\treturn pre;\r\n\t\t\t\t});\r\n\t\t\t\r\n\t\t\treturn hashBlock(\"
    \\n\" + bq + \"\\n
    \");\r\n\t\t});\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _FormParagraphs = function(text) {\r\n//\r\n// Params:\r\n// $text - string to process with html

    tags\r\n//\r\n\r\n\t// Strip leading and trailing lines:\r\n\ttext = text.replace(/^\\n+/g,\"\");\r\n\ttext = text.replace(/\\n+$/g,\"\");\r\n\r\n\tvar grafs = text.split(/\\n{2,}/g);\r\n\tvar grafsOut = new Array();\r\n\r\n\t//\r\n\t// Wrap

    tags.\r\n\t//\r\n\tvar end = grafs.length;\r\n\tfor (var i=0; i= 0) {\r\n\t\t\tgrafsOut.push(str);\r\n\t\t}\r\n\t\telse if (str.search(/\\S/) >= 0) {\r\n\t\t\tstr = _RunSpanGamut(str);\r\n\t\t\tstr = str.replace(/^([ \\t]*)/g,\"

    \");\r\n\t\t\tstr += \"

    \"\r\n\t\t\tgrafsOut.push(str);\r\n\t\t}\r\n\r\n\t}\r\n\r\n\t//\r\n\t// Unhashify HTML blocks\r\n\t//\r\n\tend = grafsOut.length;\r\n\tfor (var i=0; i= 0) {\r\n\t\t\tvar blockText = g_html_blocks[RegExp.$1];\r\n\t\t\tblockText = blockText.replace(/\\$/g,\"$$$$\"); // Escape any dollar signs\r\n\t\t\tgrafsOut[i] = grafsOut[i].replace(/~K\\d+K/,blockText);\r\n\t\t}\r\n\t}\r\n\r\n\treturn grafsOut.join(\"\\n\\n\");\r\n}\r\n\r\n\r\nvar _EncodeAmpsAndAngles = function(text) {\r\n// Smart processing for ampersands and angle brackets that need to be encoded.\r\n\t\r\n\t// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:\r\n\t// http://bumppo.net/projects/amputator/\r\n\ttext = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)/g,\"&\");\r\n\t\r\n\t// Encode naked <'s\r\n\ttext = text.replace(/<(?![a-z\\/?\\$!])/gi,\"<\");\r\n\t\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _EncodeBackslashEscapes = function(text) {\r\n//\r\n// Parameter: String.\r\n// Returns:\tThe string, with after processing the following backslash\r\n//\t\t\t escape sequences.\r\n//\r\n\r\n\t// attacklab: The polite way to do this is with the new\r\n\t// escapeCharacters() function:\r\n\t//\r\n\t// \ttext = escapeCharacters(text,\"\\\\\",true);\r\n\t// \ttext = escapeCharacters(text,\"`*_{}[]()>#+-.!\",true);\r\n\t//\r\n\t// ...but we're sidestepping its use of the (slow) RegExp constructor\r\n\t// as an optimization for Firefox. This function gets called a LOT.\r\n\r\n\ttext = text.replace(/\\\\(\\\\)/g,escapeCharacters_callback);\r\n\ttext = text.replace(/\\\\([`*_{}\\[\\]()>#+-.!])/g,escapeCharacters_callback);\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _DoAutoLinks = function(text) {\r\n\r\n\ttext = text.replace(/<((https?|ftp|dict):[^'\">\\s]+)>/gi,\"$1\");\r\n\r\n\t// Email addresses: \r\n\r\n\t/*\r\n\t\ttext = text.replace(/\r\n\t\t\t<\r\n\t\t\t(?:mailto:)?\r\n\t\t\t(\r\n\t\t\t\t[-.\\w]+\r\n\t\t\t\t\\@\r\n\t\t\t\t[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+\r\n\t\t\t)\r\n\t\t\t>\r\n\t\t/gi, _DoAutoLinks_callback());\r\n\t*/\r\n\ttext = text.replace(/<(?:mailto:)?([-.\\w]+\\@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+)>/gi,\r\n\t\tfunction(wholeMatch,m1) {\r\n\t\t\treturn _EncodeEmailAddress( _UnescapeSpecialChars(m1) );\r\n\t\t}\r\n\t);\r\n\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _EncodeEmailAddress = function(addr) {\r\n//\r\n// Input: an email address, e.g. \"foo@example.com\"\r\n//\r\n// Output: the email address as a mailto link, with each character\r\n//\tof the address encoded as either a decimal or hex entity, in\r\n//\tthe hopes of foiling most address harvesting spam bots. E.g.:\r\n//\r\n//\tfoo\r\n//\t @example.com\r\n//\r\n// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk\r\n// mailing list: \r\n//\r\n\r\n\t// attacklab: why can't javascript speak hex?\r\n\tfunction char2hex(ch) {\r\n\t\tvar hexDigits = '0123456789ABCDEF';\r\n\t\tvar dec = ch.charCodeAt(0);\r\n\t\treturn(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15));\r\n\t}\r\n\r\n\tvar encode = [\r\n\t\tfunction(ch){return \"&#\"+ch.charCodeAt(0)+\";\";},\r\n\t\tfunction(ch){return \"&#x\"+char2hex(ch)+\";\";},\r\n\t\tfunction(ch){return ch;}\r\n\t];\r\n\r\n\taddr = \"mailto:\" + addr;\r\n\r\n\taddr = addr.replace(/./g, function(ch) {\r\n\t\tif (ch == \"@\") {\r\n\t\t \t// this *must* be encoded. I insist.\r\n\t\t\tch = encode[Math.floor(Math.random()*2)](ch);\r\n\t\t} else if (ch !=\":\") {\r\n\t\t\t// leave ':' alone (to spot mailto: later)\r\n\t\t\tvar r = Math.random();\r\n\t\t\t// roughly 10% raw, 45% hex, 45% dec\r\n\t\t\tch = (\r\n\t\t\t\t\tr > .9 ?\tencode[2](ch) :\r\n\t\t\t\t\tr > .45 ?\tencode[1](ch) :\r\n\t\t\t\t\t\t\t\tencode[0](ch)\r\n\t\t\t\t);\r\n\t\t}\r\n\t\treturn ch;\r\n\t});\r\n\r\n\taddr = \"\" + addr + \"\";\r\n\taddr = addr.replace(/\">.+:/g,\"\\\">\"); // strip the mailto: from the visible part\r\n\r\n\treturn addr;\r\n}\r\n\r\n\r\nvar _UnescapeSpecialChars = function(text) {\r\n//\r\n// Swap back in all the special characters we've hidden.\r\n//\r\n\ttext = text.replace(/~E(\\d+)E/g,\r\n\t\tfunction(wholeMatch,m1) {\r\n\t\t\tvar charCodeToReplace = parseInt(m1);\r\n\t\t\treturn String.fromCharCode(charCodeToReplace);\r\n\t\t}\r\n\t);\r\n\treturn text;\r\n}\r\n\r\n\r\nvar _Outdent = function(text) {\r\n//\r\n// Remove one level of line-leading tabs or spaces\r\n//\r\n\r\n\t// attacklab: hack around Konqueror 3.5.4 bug:\r\n\t// \"----------bug\".replace(/^-/g,\"\") == \"bug\"\r\n\r\n\ttext = text.replace(/^(\\t|[ ]{1,4})/gm,\"~0\"); // attacklab: g_tab_width\r\n\r\n\t// attacklab: clean up hack\r\n\ttext = text.replace(/~0/g,\"\")\r\n\r\n\treturn text;\r\n}\r\n\r\nvar _Detab = function(text) {\r\n// attacklab: Detab's completely rewritten for speed.\r\n// In perl we could fix it by anchoring the regexp with \\G.\r\n// In javascript we're less fortunate.\r\n\r\n\t// expand first n-1 tabs\r\n\ttext = text.replace(/\\t(?=\\t)/g,\" \"); // attacklab: g_tab_width\r\n\r\n\t// replace the nth with two sentinels\r\n\ttext = text.replace(/\\t/g,\"~A~B\");\r\n\r\n\t// use the sentinel to anchor our regex so it doesn't explode\r\n\ttext = text.replace(/~B(.+?)~A/g,\r\n\t\tfunction(wholeMatch,m1,m2) {\r\n\t\t\tvar leadingText = m1;\r\n\t\t\tvar numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width\r\n\r\n\t\t\t// there *must* be a better way to do this:\r\n\t\t\tfor (var i=0; i;\r\n f.title = data.title;\r\n f.id = data.feed_id;\r\n f.link.@href = data.feed_link;\r\n f.link.@rel = \"self\";\r\n f.generator = \"CouchApp on CouchDB\";\r\n f.updated = rfc3339(data.updated);\r\n return f.toXMLString().replace(/\\<\\/feed\\>/,'');\r\n};\r\n\r\nexports.entry = function(data) {\r\n var entry = ;\r\n entry.id = data.entry_id;\r\n entry.title = data.title;\r\n entry.content = data.content;\r\n entry.content.@type = (data.content_type || 'html');\r\n entry.updated = rfc3339(data.updated);\r\n entry.author = {data.author};\r\n entry.link.@href = data.alternate;\r\n entry.link.@rel = \"alternate\";\r\n return entry;\r\n}","path":"// from couch.js\r\nfunction encodeOptions(options) {\r\n var buf = [];\r\n if (typeof(options) == \"object\" && options !== null) {\r\n for (var name in options) {\r\n if (!options.hasOwnProperty(name)) {continue;}\r\n var value = options[name];\r\n if (name == \"key\" || name == \"startkey\" || name == \"endkey\") {\r\n value = JSON.stringify(value);\r\n }\r\n buf.push(encodeURIComponent(name) + \"=\" + encodeURIComponent(value));\r\n }\r\n }\r\n if (!buf.length) {\r\n return \"\";\r\n }\r\n return \"?\" + buf.join(\"&\");\r\n}\r\n\r\nfunction concatArgs(array, args) {\r\n for (var i=0; i < args.length; i++) {\r\n array.push(args[i]);\r\n };\r\n return array;\r\n};\r\n\r\nfunction makePath(array) {\r\n var options, path;\r\n \r\n if (typeof array[array.length - 1] != \"string\") {\r\n // it's a params hash\r\n options = array.pop();\r\n }\r\n path = array.map(function(item) {return encodeURIComponent(item)}).join('/');\r\n if (options) {\r\n return path + encodeOptions(options);\r\n } else {\r\n return path; \r\n }\r\n};\r\n\r\nexports.init = function(req) {\r\n return {\r\n asset : function() {\r\n var p = req.path, parts = ['', p[0], p[1] , p[2]];\r\n return makePath(concatArgs(parts, arguments));\r\n },\r\n show : function() {\r\n var p = req.path, parts = ['', p[0], p[1] , p[2], '_show'];\r\n return makePath(concatArgs(parts, arguments));\r\n },\r\n list : function() {\r\n var p = req.path, parts = ['', p[0], p[1] , p[2], '_list'];\r\n return makePath(concatArgs(parts, arguments));\r\n },\r\n update : function() {\r\n var p = req.path, parts = ['', p[0], p[1] , p[2], '_update'];\r\n return makePath(concatArgs(parts, arguments));\r\n },\r\n limit : function(limit) {\r\n var query = req.query;\r\n var l = query.limit;\r\n query.limit = limit;\r\n var view = req.path[req.path.length - 1];\r\n var list = req.path[req.path.length - 2];\r\n var link = this.list(list, view, query);\r\n query.limit = l;\r\n return link;\r\n },\r\n older : function(key) {\r\n if (!typeof key == \"undefined\") return null;\r\n var query = req.query;\r\n query.startkey = key;\r\n query.skip=1;\r\n var view = req.path[req.path.length - 1];\r\n var list = req.path[req.path.length - 2];\r\n return this.list(list, view, query);\r\n },\r\n absolute : function(path) {\r\n return 'http://' + req.headers.Host + path;\r\n }\r\n }\r\n};","validate":"// a library for validations\r\n// over time we expect to extract more helpers and move them here.\r\nexports.init = function(newDoc, oldDoc, userCtx, secObj) {\r\n var v = {};\r\n \r\n v.forbidden = function(message) { \r\n throw({forbidden : message});\r\n };\r\n\r\n v.unauthorized = function(message) {\r\n throw({unauthorized : message});\r\n };\r\n\r\n v.assert = function(should, message) {\r\n if (!should) v.forbidden(message);\r\n }\r\n \r\n v.isAdmin = function() {\r\n return userCtx.roles.indexOf('_admin') != -1\r\n };\r\n \r\n v.isRole = function(role) {\r\n return userCtx.roles.indexOf(role) != -1\r\n };\r\n\r\n v.require = function() {\r\n for (var i=0; i < arguments.length; i++) {\r\n var field = arguments[i];\r\n message = \"The '\"+field+\"' field is required.\";\r\n if (typeof newDoc[field] == \"undefined\") v.forbidden(message);\r\n };\r\n };\r\n\r\n v.unchanged = function(field) {\r\n if (oldDoc && oldDoc[field] != newDoc[field]) \r\n v.forbidden(\"You may not change the '\"+field+\"' field.\");\r\n };\r\n\r\n v.matches = function(field, regex, message) {\r\n if (!newDoc[field].match(regex)) {\r\n message = message || \"Format of '\"+field+\"' field is invalid.\";\r\n v.forbidden(message); \r\n }\r\n };\r\n\r\n // this ensures that the date will be UTC, parseable, and collate correctly\r\n v.dateFormat = function(field) {\r\n message = \"Sorry, '\"+field+\"' is not a valid date format. Try: 2010-02-24T17:00:03.432Z\";\r\n v.matches(field, /\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d*)?Z/, message);\r\n }\r\n \r\n return v;\r\n};","md5":"/*\r\n * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message\r\n * Digest Algorithm, as defined in RFC 1321.\r\n * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.\r\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\r\n * Distributed under the BSD License\r\n * See http://pajhome.org.uk/crypt/md5 for more info.\r\n */\r\n\r\n/*\r\n * Configurable variables. You may need to tweak these to be compatible with\r\n * the server-side, but the defaults work in most cases.\r\n */\r\nvar hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\r\nvar b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\r\nvar chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */\r\n\r\n/*\r\n * These are the functions you'll usually want to call\r\n * They take string arguments and return either hex or base-64 encoded strings\r\n */\r\nfunction hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}\r\nfunction b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}\r\nfunction str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}\r\nfunction hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }\r\nfunction b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }\r\nfunction str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }\r\n\r\n/*\r\n * Perform a simple self-test to see if the VM is working\r\n */\r\nfunction md5_vm_test()\r\n{\r\n return hex_md5(\"abc\") == \"900150983cd24fb0d6963f7d28e17f72\";\r\n}\r\n\r\n/*\r\n * Calculate the MD5 of an array of little-endian words, and a bit length\r\n keep\r\n */\r\nfunction core_md5(x, len)\r\n{\r\n /* append padding */\r\n x[len >> 5] |= 0x80 << ((len) % 32);\r\n x[(((len + 64) >>> 9) << 4) + 14] = len;\r\n\r\n var a = 1732584193;\r\n var b = -271733879;\r\n var c = -1732584194;\r\n var d = 271733878;\r\n\r\n for(var i = 0; i < x.length; i += 16)\r\n {\r\n var olda = a;\r\n var oldb = b;\r\n var oldc = c;\r\n var oldd = d;\r\n\r\n a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);\r\n d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);\r\n c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);\r\n b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);\r\n a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);\r\n d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);\r\n c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);\r\n b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);\r\n a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);\r\n d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);\r\n c = md5_ff(c, d, a, b, x[i+10], 17, -42063);\r\n b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);\r\n a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);\r\n d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);\r\n c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);\r\n b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);\r\n\r\n a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);\r\n d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);\r\n c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);\r\n b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);\r\n a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);\r\n d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);\r\n c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);\r\n b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);\r\n a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);\r\n d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);\r\n c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);\r\n b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);\r\n a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);\r\n d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);\r\n c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);\r\n b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);\r\n\r\n a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);\r\n d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);\r\n c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);\r\n b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);\r\n a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);\r\n d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);\r\n c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);\r\n b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);\r\n a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);\r\n d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);\r\n c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);\r\n b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);\r\n a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);\r\n d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);\r\n c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);\r\n b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);\r\n\r\n a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);\r\n d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);\r\n c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);\r\n b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);\r\n a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);\r\n d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);\r\n c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);\r\n b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);\r\n a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);\r\n d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);\r\n c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);\r\n b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);\r\n a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);\r\n d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);\r\n c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);\r\n b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);\r\n\r\n a = safe_add(a, olda);\r\n b = safe_add(b, oldb);\r\n c = safe_add(c, oldc);\r\n d = safe_add(d, oldd);\r\n }\r\n return Array(a, b, c, d);\r\n\r\n}\r\n\r\n/*\r\n * These functions implement the four basic operations the algorithm uses.\r\n */\r\nfunction md5_cmn(q, a, b, x, s, t)\r\n{\r\n return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);\r\n}\r\nfunction md5_ff(a, b, c, d, x, s, t)\r\n{\r\n return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);\r\n}\r\nfunction md5_gg(a, b, c, d, x, s, t)\r\n{\r\n return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);\r\n}\r\nfunction md5_hh(a, b, c, d, x, s, t)\r\n{\r\n return md5_cmn(b ^ c ^ d, a, b, x, s, t);\r\n}\r\nfunction md5_ii(a, b, c, d, x, s, t)\r\n{\r\n return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);\r\n}\r\n\r\n/*\r\n * Calculate the HMAC-MD5, of a key and some data\r\n */\r\nfunction core_hmac_md5(key, data)\r\n{\r\n var bkey = str2binl(key);\r\n if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);\r\n\r\n var ipad = Array(16), opad = Array(16);\r\n for(var i = 0; i < 16; i++)\r\n {\r\n ipad[i] = bkey[i] ^ 0x36363636;\r\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\r\n }\r\n\r\n var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);\r\n return core_md5(opad.concat(hash), 512 + 128);\r\n}\r\n\r\n/*\r\n * Add integers, wrapping at 2^32. This uses 16-bit operations internally\r\n * to work around bugs in some JS interpreters.\r\n */\r\nfunction safe_add(x, y)\r\n{\r\n var lsw = (x & 0xFFFF) + (y & 0xFFFF);\r\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\r\n return (msw << 16) | (lsw & 0xFFFF);\r\n}\r\n\r\n/*\r\n * Bitwise rotate a 32-bit number to the left.\r\n */\r\nfunction bit_rol(num, cnt)\r\n{\r\n return (num << cnt) | (num >>> (32 - cnt));\r\n}\r\n\r\n/*\r\n * Convert a string to an array of little-endian words\r\n * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.\r\n keep\r\n */\r\nfunction str2binl(str)\r\n{\r\n var bin = Array();\r\n var mask = (1 << chrsz) - 1;\r\n for(var i = 0; i < str.length * chrsz; i += chrsz)\r\n bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);\r\n return bin;\r\n}\r\n\r\n/*\r\n * Convert an array of little-endian words to a string\r\n */\r\nfunction binl2str(bin)\r\n{\r\n var str = \"\";\r\n var mask = (1 << chrsz) - 1;\r\n for(var i = 0; i < bin.length * 32; i += chrsz)\r\n str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);\r\n return str;\r\n}\r\n\r\n/*\r\n * Convert an array of little-endian words to a hex string.\r\n keep\r\n */\r\nfunction binl2hex(binarray)\r\n{\r\n var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\r\n var str = \"\";\r\n for(var i = 0; i < binarray.length * 4; i++)\r\n {\r\n str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +\r\n hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);\r\n }\r\n return str;\r\n}\r\n\r\n/*\r\n * Convert an array of little-endian words to a base-64 string\r\n */\r\nfunction binl2b64(binarray)\r\n{\r\n var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\r\n var str = \"\";\r\n for(var i = 0; i < binarray.length * 4; i += 3)\r\n {\r\n var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)\r\n | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )\r\n | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);\r\n for(var j = 0; j < 4; j++)\r\n {\r\n if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;\r\n else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);\r\n }\r\n }\r\n return str;\r\n}\r\n\r\nexports.hex = hex_md5;","mustache":"/*\r\n * CommonJS-compatible mustache.js module\r\n *\r\n * See http://github.com/janl/mustache.js for more info.\r\n */\r\n\r\n/*\r\n mustache.js — Logic-less templates in JavaScript\r\n\r\n See http://mustache.github.com/ for more info.\r\n*/\r\n\r\nvar Mustache = function() {\r\n var Renderer = function() {};\r\n\r\n Renderer.prototype = {\r\n otag: \"{{\",\r\n ctag: \"}}\",\r\n pragmas: {},\r\n buffer: [],\r\n pragmas_implemented: {\r\n \"IMPLICIT-ITERATOR\": true\r\n },\r\n context: {},\r\n\r\n render: function(template, context, partials, in_recursion) {\r\n // reset buffer & set context\r\n if(!in_recursion) {\r\n this.context = context;\r\n this.buffer = []; // TODO: make this non-lazy\r\n }\r\n\r\n // fail fast\r\n if(!this.includes(\"\", template)) {\r\n if(in_recursion) {\r\n return template;\r\n } else {\r\n this.send(template);\r\n return;\r\n }\r\n }\r\n\r\n template = this.render_pragmas(template);\r\n var html = this.render_section(template, context, partials);\r\n if(in_recursion) {\r\n return this.render_tags(html, context, partials, in_recursion);\r\n }\r\n\r\n this.render_tags(html, context, partials, in_recursion);\r\n },\r\n\r\n /*\r\n Sends parsed lines\r\n */\r\n send: function(line) {\r\n if(line != \"\") {\r\n this.buffer.push(line);\r\n }\r\n },\r\n\r\n /*\r\n Looks for %PRAGMAS\r\n */\r\n render_pragmas: function(template) {\r\n // no pragmas\r\n if(!this.includes(\"%\", template)) {\r\n return template;\r\n }\r\n\r\n var that = this;\r\n var regex = new RegExp(this.otag + \"%([\\\\w-]+) ?([\\\\w]+=[\\\\w]+)?\" +\r\n this.ctag);\r\n return template.replace(regex, function(match, pragma, options) {\r\n if(!that.pragmas_implemented[pragma]) {\r\n throw({message: \r\n \"This implementation of mustache doesn't understand the '\" +\r\n pragma + \"' pragma\"});\r\n }\r\n that.pragmas[pragma] = {};\r\n if(options) {\r\n var opts = options.split(\"=\");\r\n that.pragmas[pragma][opts[0]] = opts[1];\r\n }\r\n return \"\";\r\n // ignore unknown pragmas silently\r\n });\r\n },\r\n\r\n /*\r\n Tries to find a partial in the curent scope and render it\r\n */\r\n render_partial: function(name, context, partials) {\r\n name = this.trim(name);\r\n if(!partials || partials[name] === undefined) {\r\n throw({message: \"unknown_partial '\" + name + \"'\"});\r\n }\r\n if(typeof(context[name]) != \"object\") {\r\n return this.render(partials[name], context, partials, true);\r\n }\r\n return this.render(partials[name], context[name], partials, true);\r\n },\r\n\r\n /*\r\n Renders inverted (^) and normal (#) sections\r\n */\r\n render_section: function(template, context, partials) {\r\n if(!this.includes(\"#\", template) && !this.includes(\"^\", template)) {\r\n return template;\r\n }\r\n\r\n var that = this;\r\n // CSW - Added \"+?\" so it finds the tighest bound, not the widest\r\n var regex = new RegExp(this.otag + \"(\\\\^|\\\\#)\\\\s*(.+)\\\\s*\" + this.ctag +\r\n \"\\n*([\\\\s\\\\S]+?)\" + this.otag + \"\\\\/\\\\s*\\\\2\\\\s*\" + this.ctag +\r\n \"\\\\s*\", \"mg\");\r\n\r\n // for each {{#foo}}{{/foo}} section do...\r\n return template.replace(regex, function(match, type, name, content) {\r\n var value = that.find(name, context);\r\n if(type == \"^\") { // inverted section\r\n if(!value || that.is_array(value) && value.length === 0) {\r\n // false or empty list, render it\r\n return that.render(content, context, partials, true);\r\n } else {\r\n return \"\";\r\n }\r\n } else if(type == \"#\") { // normal section\r\n if(that.is_array(value)) { // Enumerable, Let's loop!\r\n return that.map(value, function(row) {\r\n return that.render(content, that.create_context(row),\r\n partials, true);\r\n }).join(\"\");\r\n } else if(that.is_object(value)) { // Object, Use it as subcontext!\r\n return that.render(content, that.create_context(value),\r\n partials, true);\r\n } else if(typeof value === \"function\") {\r\n // higher order section\r\n return value.call(context, content, function(text) {\r\n return that.render(text, context, partials, true);\r\n });\r\n } else if(value) { // boolean section\r\n return that.render(content, context, partials, true);\r\n } else {\r\n return \"\";\r\n }\r\n }\r\n });\r\n },\r\n\r\n /*\r\n Replace {{foo}} and friends with values from our view\r\n */\r\n render_tags: function(template, context, partials, in_recursion) {\r\n // tit for tat\r\n var that = this;\r\n\r\n var new_regex = function() {\r\n return new RegExp(that.otag + \"(=|!|>|\\\\{|%)?([^\\\\/#\\\\^]+?)\\\\1?\" +\r\n that.ctag + \"+\", \"g\");\r\n };\r\n\r\n var regex = new_regex();\r\n var tag_replace_callback = function(match, operator, name) {\r\n switch(operator) {\r\n case \"!\": // ignore comments\r\n return \"\";\r\n case \"=\": // set new delimiters, rebuild the replace regexp\r\n that.set_delimiters(name);\r\n regex = new_regex();\r\n return \"\";\r\n case \">\": // render partial\r\n return that.render_partial(name, context, partials);\r\n case \"{\": // the triple mustache is unescaped\r\n return that.find(name, context);\r\n default: // escape the value\r\n return that.escape(that.find(name, context));\r\n }\r\n };\r\n var lines = template.split(\"\\n\");\r\n for(var i = 0; i < lines.length; i++) {\r\n lines[i] = lines[i].replace(regex, tag_replace_callback, this);\r\n if(!in_recursion) {\r\n this.send(lines[i]);\r\n }\r\n }\r\n\r\n if(in_recursion) {\r\n return lines.join(\"\\n\");\r\n }\r\n },\r\n\r\n set_delimiters: function(delimiters) {\r\n var dels = delimiters.split(\" \");\r\n this.otag = this.escape_regex(dels[0]);\r\n this.ctag = this.escape_regex(dels[1]);\r\n },\r\n\r\n escape_regex: function(text) {\r\n // thank you Simon Willison\r\n if(!arguments.callee.sRE) {\r\n var specials = [\r\n '/', '.', '*', '+', '?', '|',\r\n '(', ')', '[', ']', '{', '}', '\\\\'\r\n ];\r\n arguments.callee.sRE = new RegExp(\r\n '(\\\\' + specials.join('|\\\\') + ')', 'g'\r\n );\r\n }\r\n return text.replace(arguments.callee.sRE, '\\\\$1');\r\n },\r\n\r\n /*\r\n find `name` in current `context`. That is find me a value\r\n from the view object\r\n */\r\n find: function(name, context) {\r\n name = this.trim(name);\r\n\r\n // Checks whether a value is thruthy or false or 0\r\n function is_kinda_truthy(bool) {\r\n return bool === false || bool === 0 || bool;\r\n }\r\n\r\n var value;\r\n if(is_kinda_truthy(context[name])) {\r\n value = context[name];\r\n } else if(is_kinda_truthy(this.context[name])) {\r\n value = this.context[name];\r\n }\r\n\r\n if(typeof value === \"function\") {\r\n return value.apply(context);\r\n }\r\n if(value !== undefined) {\r\n return value;\r\n }\r\n // silently ignore unkown variables\r\n return \"\";\r\n },\r\n\r\n // Utility methods\r\n\r\n /* includes tag */\r\n includes: function(needle, haystack) {\r\n return haystack.indexOf(this.otag + needle) != -1;\r\n },\r\n\r\n /*\r\n Does away with nasty characters\r\n */\r\n escape: function(s) {\r\n s = String(s === null ? \"\" : s);\r\n return s.replace(/&(?!\\w+;)|[\"<>\\\\]/g, function(s) {\r\n switch(s) {\r\n case \"&\": return \"&\";\r\n case \"\\\\\": return \"\\\\\\\\\";\r\n case '\"': return '\\\"';\r\n case \"<\": return \"<\";\r\n case \">\": return \">\";\r\n default: return s;\r\n }\r\n });\r\n },\r\n\r\n // by @langalex, support for arrays of strings\r\n create_context: function(_context) {\r\n if(this.is_object(_context)) {\r\n return _context;\r\n } else {\r\n var iterator = \".\";\r\n if(this.pragmas[\"IMPLICIT-ITERATOR\"]) {\r\n iterator = this.pragmas[\"IMPLICIT-ITERATOR\"].iterator;\r\n }\r\n var ctx = {};\r\n ctx[iterator] = _context;\r\n return ctx;\r\n }\r\n },\r\n\r\n is_object: function(a) {\r\n return a && typeof a == \"object\";\r\n },\r\n\r\n is_array: function(a) {\r\n return Object.prototype.toString.call(a) === '[object Array]';\r\n },\r\n\r\n /*\r\n Gets rid of leading and trailing whitespace\r\n */\r\n trim: function(s) {\r\n return s.replace(/^\\s*|\\s*$/g, \"\");\r\n },\r\n\r\n /*\r\n Why, why, why? Because IE. Cry, cry cry.\r\n */\r\n map: function(array, fn) {\r\n if (typeof array.map == \"function\") {\r\n return array.map(fn);\r\n } else {\r\n var r = [];\r\n var l = array.length;\r\n for(var i = 0; i < l; i++) {\r\n r.push(fn(array[i]));\r\n }\r\n return r;\r\n }\r\n }\r\n };\r\n\r\n return({\r\n name: \"mustache.js\",\r\n version: \"0.3.1-dev\",\r\n\r\n /*\r\n Turns a template and view into HTML\r\n */\r\n to_html: function(template, view, partials, send_fun) {\r\n var renderer = new Renderer();\r\n if(send_fun) {\r\n renderer.send = send_fun;\r\n }\r\n renderer.render(template, view, partials);\r\n if(!send_fun) {\r\n return renderer.buffer.join(\"\\n\");\r\n }\r\n },\r\n escape : function(text) {\r\n return new Renderer().escape(text);\r\n }\r\n });\r\n}();\r\n\r\nexports.name = Mustache.name;\r\nexports.version = Mustache.version;\r\n\r\nexports.to_html = Mustache.to_html;\r\nexports.escape = Mustache.escape;","docform":"// Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n// use this file except in compliance with the License. You may obtain a copy\r\n// of the License at\r\n//\r\n// http://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n// License for the specific language governing permissions and limitations under\r\n// the License.\r\n\r\n// turn the form into deep json\r\n// field names like 'author-email' get turned into json like\r\n// {\"author\":{\"email\":\"quentin@example.com\"}}\r\n// acts on doc by reference, so you can safely pass non-form fields through\r\n\r\nfunction docForm(formSelector, opts) {\r\n var localFormDoc = {};\r\n opts = opts || {};\r\n opts.fields = opts.fields || [];\r\n\r\n // turn the form into deep json\r\n // field names like 'author-email' get turned into json like\r\n // {\"author\":{\"email\":\"quentin@example.com\"}}\r\n function formToDeepJSON(form, fields, doc) {\r\n form = $(form);\r\n fields.forEach(function(field) {\r\n var element = form.find(\"[name=\"+field+\"]\"),\r\n parts = field.split('-'),\r\n frontObj = doc, frontName = parts.shift();\r\n\r\n if (element.attr('type') === 'checkbox') {\r\n var val = element.attr('checked');\r\n } else {\r\n var val = element.val();\r\n if (!val) {\r\n if (frontObj[field]) {\r\n delete frontObj[field];\r\n }\r\n return;\r\n }\r\n }\r\n \r\n while (parts.length > 0) {\r\n frontObj[frontName] = frontObj[frontName] || {};\r\n frontObj = frontObj[frontName];\r\n frontName = parts.shift();\r\n }\r\n frontObj[frontName] = val;\r\n });\r\n }\r\n \r\n // Apply the behavior\r\n $(formSelector).submit(function(e) {\r\n e.preventDefault();\r\n if (opts.validate && opts.validate() == false) { return false;}\r\n // formToDeepJSON acts on localFormDoc by reference\r\n formToDeepJSON(this, opts.fields, localFormDoc);\r\n if (opts.beforeSave) {opts.beforeSave(localFormDoc);}\r\n db.saveDoc(localFormDoc, {\r\n success : function(resp) {\r\n if (opts.success) {opts.success(resp, localFormDoc);}\r\n }\r\n });\r\n \r\n return false;\r\n });\r\n\r\n // populate form from an existing doc\r\n function docToForm(doc) {\r\n var form = $(formSelector);\r\n // fills in forms\r\n opts.fields.forEach(function(field) {\r\n var parts = field.split('-');\r\n var run = true, frontObj = doc, frontName = parts.shift();\r\n while (frontObj && parts.length > 0) { \r\n frontObj = frontObj[frontName];\r\n frontName = parts.shift();\r\n }\r\n if (frontObj && frontObj[frontName]) {\r\n var element = form.find(\"[name=\"+field+\"]\");\r\n if (element.attr('type') === 'checkbox') {\r\n element.attr('checked', frontObj[frontName]);\r\n } else {\r\n element.val(frontObj[frontName]);\r\n }\r\n }\r\n });\r\n }\r\n \r\n if (opts.id) {\r\n db.openDoc(opts.id, {\r\n attachPrevRev : opts.attachPrevRev,\r\n error: function() {\r\n if (opts.error) {opts.error.apply(opts, arguments);}\r\n },\r\n success: function(doc) {\r\n if (opts.load || opts.onLoad) {(opts.load || opts.onLoad)(doc);}\r\n localFormDoc = doc;\r\n docToForm(doc);\r\n }});\r\n } else if (opts.template) {\r\n if (opts.load || opts.onLoad) {(opts.load || opts.onLoad)(opts.template);}\r\n localFormDoc = opts.template;\r\n docToForm(localFormDoc);\r\n }\r\n var instance = {\r\n deleteDoc : function(opts) {\r\n opts = opts || {};\r\n if (confirm(\"Really delete this document?\")) { \r\n db.removeDoc(localFormDoc, opts);\r\n }\r\n },\r\n localDoc : function() {\r\n formToDeepJSON(formSelector, opts.fields, localFormDoc);\r\n return localFormDoc;\r\n }\r\n };\r\n return instance;\r\n}"},"metadata":{"name":"couchapp","fetch_uri":"git://github.com/couchapp/vendor.git","description":"official couchapp vendor"}}},"language":"javascript","views":{"by_geneIDcount":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\temit([doc.Gene_EntrezID, methodCount], miR);\r\n\t\t\t}\r\n\t\t}\r\n};"},"by_geneIDmethod":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tvar methodList = new Array();\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodList[methodCount] = method.toLowerCase();\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\tmethodList.sort();\r\n\t\t\t\tvar methodCombinations = getCombinations(methodList);\r\n\t\t\t\tfor (var i = 0; i < methodCombinations.length; i++) {\r\n\t\t\t\t\temit([doc.Gene_EntrezID, methodCombinations[i]], miR);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n};\r\n\r\nfunction getCombinations(chars) {\r\n var result = [];\r\n var f = function(prefix, chars) {\r\n for (var i = 0; i < chars.length; i++) {\r\n result.push(prefix + chars[i]);\r\n f(prefix + chars[i] + '+', chars.slice(i + 1));\r\n }\r\n }\r\n f('', chars);\r\n return result;\r\n}"},"by_miRNAIDcount":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\temit([doc.miRNA, methodCount], miR);\r\n\t\t\t}\r\n\t\t}\r\n};"},"by_miRNAIDmethod":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tvar methodList = new Array();\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodList[methodCount] = method.toLowerCase();\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\tmethodList.sort();\r\n\t\t\t\tvar methodCombinations = getCombinations(methodList);\r\n\t\t\t\tfor (var i = 0; i < methodCombinations.length; i++) {\r\n\t\t\t\t\temit([doc.miRNA, methodCombinations[i]], miR);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n};\r\n\r\nfunction getCombinations(chars) {\r\n var result = [];\r\n var f = function(prefix, chars) {\r\n for (var i = 0; i < chars.length; i++) {\r\n result.push(prefix + chars[i]);\r\n f(prefix + chars[i] + '+', chars.slice(i + 1));\r\n }\r\n }\r\n f('', chars);\r\n return result;\r\n}"},"by_matureMIRcount":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\temit([miR, methodCount], doc.miRNA);\r\n\t\t\t}\r\n\t\t}\r\n};"},"by_matmir":{"map":"function(doc) {\n\tfor (var miR in doc.mat_miRNA) {\n\t\t\temit(miR, 1);\n\t}\n};","reduce":"_sum"},"by_matureMIRmethod":{"map":"function(doc) {\r\n\tif (doc.mat_miRNA) {\r\n\t\t\tfor (var miR in doc.mat_miRNA) {\r\n\t\t\t\tvar methodCount = 0;\r\n\t\t\t\tvar methodList = new Array();\r\n\t\t\t\tfor (var method in doc.mat_miRNA[miR]) {\r\n\t\t\t\t\tmethodList[methodCount] = method.toLowerCase();\r\n\t\t\t\t\tmethodCount++;\r\n\t\t\t\t}\r\n\t\t\t\tmethodList.sort();\r\n\t\t\t\tvar methodCombinations = getCombinations(methodList);\r\n\t\t\t\tfor (var i = 0; i < methodCombinations.length; i++) {\r\n\t\t\t\t\temit([miR, methodCombinations[i]], doc.miRNA);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n};\r\n\r\nfunction getCombinations(chars) {\r\n var result = [];\r\n var f = function(prefix, chars) {\r\n for (var i = 0; i < chars.length; i++) {\r\n result.push(prefix + chars[i]);\r\n f(prefix + chars[i] + '+', chars.slice(i + 1));\r\n }\r\n }\r\n f('', chars);\r\n return result;\r\n}"}},"lists":{"interactionHTML":"function(head, req) {\r\n var row;\r\n start({ \"headers\": { \"Content-Type\": \"text/html\" }});\r\n while (row = getRow()) {\r\n\t\tif (row.doc) {\r\n\t\t\tvar x = '';\r\n\t\t\tvar doc = row.doc;\r\n\t\t\tvar doc_id = doc._id.replace(/:/,\" Vs \"); \r\n\t\t\t\r\n\t\t\tx = '
    ';\r\n\t\t\tx = x + '

    ' + doc.miRNA + ' Vs ' + doc.Gene_Symbol + '

    ';\r\n\t\t\t\r\n\t\t\tx = x + 'mature miRNA: ' + '' + row.value + '';\r\n\t\t\tx = x + '
      ';\r\n\t\t\tfor (var method in doc.mat_miRNA[row.value]) {\r\n\t\t\t\tif(method == \"mirTarBase\") {\r\n\t\t\t\t\tx = x + '
    • mirTarBase';\r\n\t\t\t\t\tx = x + '';\r\n\t\t\t\t} else if(method == \"miRanda\") {\r\n\t\t\t\t\t\tx = x + '
    • miRanda';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Score: ' + doc.mat_miRNA[row.value][method][transcript][\"Tot.Score\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Energy: ' + doc.mat_miRNA[row.value][method][transcript][\"Tot.Energy\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Transcript Location: ' + doc.mat_miRNA[row.value][method][transcript][\"TranscriptLoc\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Position: ' + doc.mat_miRNA[row.value][method][transcript][\"Position\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} else if((method == \"picTar5\") || (method == \"picTar4\")) {\r\n\t\t\t\t\t\tx = x + '
    • ' + method + '';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Score: ' + doc.mat_miRNA[row.value][method][transcript][\"score\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Position: ' + doc.mat_miRNA[row.value][method][transcript][\"siteChr\"] + ':'+ doc.mat_miRNA[row.value][method][transcript][\"siteStart\"] + ':' + doc.mat_miRNA[row.value][method][transcript][\"siteEnd\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • picTar Name: ' + doc.mat_miRNA[row.value][method][transcript][\"miRname\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • View Conservation in UCSC Genome Browser
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} else if(method == \"targetScan\") {\r\n\t\t\t\t\t\tx = x + '
    • ' + method + '';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Context Score: ' + doc.mat_miRNA[row.value][method][transcript][\"contextScore\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Aggregate Pct: ' + doc.mat_miRNA[row.value][method][transcript][\"aggregatePCT\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Total Conserved sites: ' + doc.mat_miRNA[row.value][method][transcript][\"totalConSites\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • miRNA family: ' + doc.mat_miRNA[row.value][method][transcript][\"miRfamily\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Representative miRNA: ' + doc.mat_miRNA[row.value][method][transcript][\"repMIRNA\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} \r\n\t\t\t}\t\r\n\t\t\tx = x + '
    ';\r\n\t\t\tsend(x);\r\n\t\t}\r\n\t\telse {\r\n\t\t\tsend(row.value + \"\\n\");\r\n\t\t}\r\n }\r\n};","sort":"function(head, req) {\r\n\tvar row\r\n\tvar rows=[]\r\n\twhile(row = getRow()) {\r\n\t\trows.push(row) \r\n\t}\r\n\trows.sort(function(a,b) {\r\n\t\treturn b.value-a.value\r\n\t})\r\n\tsend(JSON.stringify({\"rows\" : rows}))\r\n}","matureMIRinteraction":"function(head, req) {\r\n var row;\r\n start({ \"headers\": { \"Content-Type\": \"text/html\" }});\r\n var geneHash = {};\r\n\tvar tx = 'Search targetHub with miRBase ID or Gene ID for target data illustration across prediction methods';\r\n\tsend(tx);\t\t\r\n\twhile (row = getRow()) {\r\n\t\tif (row.doc) {\r\n\t\t\tvar doc = row.doc;\r\n\t\t\tvar x = '';\r\n\t\t\tif(geneHash[doc.Gene_EntrezID] == 1) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\telse { \r\n\t\t\t\tgeneHash[doc.Gene_EntrezID] = 1\r\n\t\t\t}\r\n\t\t\tvar key = new String(row.key);\r\n\t\t\tvar matmiRNA=key.split(\",\");\r\n\t\t\tx = '
    ';\r\n\t\t\tx = x + '

    ' + doc.Gene_Symbol + '

    ';\r\n\t\t\tx = x + '
      ';\r\n\t\t\tfor (var method in doc.mat_miRNA[matmiRNA[0]]) {\r\n\t\t\t\tif(method == \"mirTarBase\") {\r\n\t\t\t\t\tx = x + '
    • mirTarBase';\r\n\t\t\t\t\tx = x + '';\r\n\t\t\t\t} else if(method == \"miRanda\") {\r\n\t\t\t\t\t\tx = x + '
    • miRanda';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Score: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Tot.Score\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Energy: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Tot.Energy\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Transcript Location: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"TranscriptLoc\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Position: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Position\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} else if((method == \"picTar5\") || (method == \"picTar4\")) {\r\n\t\t\t\t\t\tx = x + '
    • ' + method + '';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Score: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"score\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Position: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteChr\"] + ':'+ doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteStart\"] + ':' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteEnd\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • picTar Name: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"miRname\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • View Conservation in UCSC Genome Browser
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} else if(method == \"targetScan\") {\r\n\t\t\t\t\t\tx = x + '
    • ' + method + '';\r\n\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + '
      • ' + transcript + '
      • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
          ';\r\n\t\t\t\t\t\t\tx = x + '
        • Context Score: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"contextScore\"] + '
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Aggregate Pct: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"aggregatePCT\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Total Conserved sites: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"totalConSites\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • miRNA family: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"miRfamily\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        • Representative miRNA: ' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"repMIRNA\"] +'
        • ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t\tx = x + '
        ';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tx = x + '
      ';\r\n\t\t\t\t} \r\n\t\t\t}\t\r\n\t\t\tx = x + '
    ';\r\n\t\t\tsend(x);\r\n\t\t}\r\n\t\telse {\r\n\t\t\tsend(row.value + \"\\n\");\r\n\t\t}\r\n }\r\n};","miRbase":"function(head, req) {\r\n var row;\r\n start({ \"headers\": { \"Content-Type\": \"text/html\" }});\r\n while (row = getRow()) {\r\n\t\tsend(row.value);\r\n\t\t}\r\n};","matureMIRinteractionTSV":"function(head, req) {\r\n var row; var headers;\r\n start({\r\n\t\t'headers': {\r\n\t\t\t'Content-Type': 'application/targethub-results; charset=utf-8; header=present',\r\n\t\t\t'Content-Disposition' : 'attachment; filename=\"results_targetHub.tsv\"'\r\n\t\t}\r\n\t});\r\n var geneHash = {};\r\n\twhile (row = getRow()) {\r\n\t\tif(!headers) {\r\n\t\t\theaders = \"matureMIRNA\" + '\\t' + \"geneSymbol\" + '\\t' + \"geneID\" + '\\t' + \"method\" + '\\t' + \"transcript\" + '\\t' + \"param1\" + '\\t' + \"param2\" + '\\t' + \"param3\" + '\\t' + \"param4\" + '\\n';\r\n\t\t\tsend(headers);\r\n\t\t}\r\n\t\tif (row.doc) {\r\n\t\t\tvar doc = row.doc;\r\n\t\t\tvar x = '';\r\n\t\t\tif(geneHash[doc.Gene_EntrezID] == 1) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\telse { \r\n\t\t\t\tgeneHash[doc.Gene_EntrezID] = 1\r\n\t\t\t}\r\n\t\t\tvar key = new String(row.key);\r\n\t\t\tvar matmiRNA=key.split(\",\");\r\n\t\t\tfor (var method in doc.mat_miRNA[matmiRNA[0]]) {\r\n\t\t\t\tif(method == \"mirTarBase\") {\r\n\t\t\t\t\tx = x + matmiRNA[0] + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\tx = x + 'mirTarBase' + '\\t';\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method].experiments;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method].supportType;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method].interactionID;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method].pubmedID;\r\n\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t} else if(method == \"miRanda\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + matmiRNA[0] + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + 'miRanda';\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Tot.Score\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Tot.Energy\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"TranscriptLoc\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"Position\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t} else if((method == \"picTar5\") || (method == \"picTar4\")) {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + matmiRNA[0] + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"score\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteChr\"] + ':'+ doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteStart\"] + ':' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"siteEnd\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"miRname\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t} else if(method == \"targetScan\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + matmiRNA[0] + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"contextScore\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"aggregatePCT\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"totalConSites\"];\r\n\t\t\t\t\t\t\t//x = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"miRfamily\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"repMIRNA\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t} else if(method == \"rna22_3utr\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[matmiRNA[0]][method]) {\r\n\t\t\t\t\t\t\tx = x + matmiRNA[0] + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"bind.energy\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"duplex.bp\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"region\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[matmiRNA[0]][method][transcript][\"ensembl.gene\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\t\r\n\t\t\tsend(x);\r\n\t\t}\r\n\t\telse {\r\n\t\t\tsend(row.value + \"\\n\");\r\n\t\t}\r\n }\r\n};","open":"function (head, req) {\r\n\r\n var row;\r\n var ii = 0;\r\n\r\n start({'headers': {\r\n 'Content-Type': 'application/json',\r\n\t\"Access-Control-Allow-Origin\": \"*\"\r\n }});\r\n\r\n send (\"[\");\r\n while ((row = getRow()) !== null) {\r\n\tsend ((ii > 0 ? \",\":\"\") + JSON.stringify(row.doc));\r\n\tii++;\r\n }\r\n send (\"]\");\r\n}","interactionTSV":"function(head, req) {\r\n var row; var headers;\r\n start({\r\n\t\t'headers': {\r\n\t\t\t'Content-Type': 'application/targethub-results; charset=utf-8; header=present',\r\n\t\t\t'Content-Disposition' : 'attachment; filename=\"results_targetHub.tsv\"'\r\n\t\t}\r\n\t});\r\n\t//start({ 'headers': {}});\r\n while (row = getRow()) {\r\n\t\tif(!headers) {\r\n\t\t\theaders = \"miRNA\" + '\\t' + \"matureMIRNA\" + '\\t' + \"geneSymbol\" + '\\t' + \"geneID\" + '\\t' + \"method\" + '\\t' + \"transcript\" + '\\t' + \"param1\" + '\\t' + \"param2\" + '\\t' + \"param3\" + '\\t' + \"param4\" + '\\n';\r\n\t\t\tsend(headers);\r\n\t\t}\r\n\t\tif (row.doc) {\r\n\t\t\tvar x = '';\r\n\t\t\tvar doc = row.doc;\r\n\t\t\tfor (var method in doc.mat_miRNA[row.value]) {\r\n\t\t\t\tif(method == \"mirTarBase\") {\r\n\t\t\t\t\tx = x + doc.miRNA + '\\t' + row.value + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\tx = x + 'mirTarBase' + '\\t';\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method].experiments;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method].supportType;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method].interactionID;\r\n\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method].pubmedID;\r\n\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t} else if(method == \"miRanda\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + doc.miRNA + '\\t' + row.value + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x +'miRanda';\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"Tot.Score\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"Tot.Energy\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"TranscriptLoc\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"Position\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\r\n\t\t\t\t} else if((method == \"picTar5\") || (method == \"picTar4\")) {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + doc.miRNA + '\\t' + row.value + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"score\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"siteChr\"] + ':'+ doc.mat_miRNA[row.value][method][transcript][\"siteStart\"] + ':' + doc.mat_miRNA[row.value][method][transcript][\"siteEnd\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"miRname\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t} else if(method == \"targetScan\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + doc.miRNA + '\\t' + row.value + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"contextScore\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"aggregatePCT\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"totalConSites\"];\r\n\t\t\t\t\t\t\t//x = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"miRfamily\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"repMIRNA\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t} else if(method == \"rna22_3utr\") {\r\n\t\t\t\t\t\tfor(var transcript in doc.mat_miRNA[row.value][method]) {\r\n\t\t\t\t\t\t\tx = x + doc.miRNA + '\\t' + row.value + '\\t' + doc.Gene_Symbol + '\\t' + doc.Gene_EntrezID + '\\t';\r\n\t\t\t\t\t\t\tx = x + method;\r\n\t\t\t\t\t\t\tx = x + '\\t' + transcript;\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"bind.energy\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"duplex.bp\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"region\"];\r\n\t\t\t\t\t\t\tx = x + '\\t' + doc.mat_miRNA[row.value][method][transcript][\"ensembl.gene\"];\r\n\t\t\t\t\t\t\tx = x + '\\n';\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\t\r\n\t\t\tsend(x);\r\n\t\t}\r\n\t\telse {\r\n\t\t\tsend(row.value + \"\\n\");\r\n\t\t}\r\n }\r\n};"},"evently":{"profile":{"profileReady":{"mustache":"

    Most applications will customize this template (ddoc.evently.profile.profileReady.mustache) for user input.

    \r\n\r\n
    \r\n {{#gravatar_url}}{{/gravatar_url}}\r\n
    \r\n {{name}}\r\n
    \r\n
    \r\n\r\n
    \r\n \r\n
    \r\n\r\n
    ","selectors":{"form":{"submit":"function() {\r\n var form = $(this);\r\n var fdoc = form.serializeObject();\r\n fdoc.created_at = new Date();\r\n fdoc.profile = $$(\"#profile\").profile;\r\n $$(this).app.db.saveDoc(fdoc, {\r\n success : function() {\r\n form[0].reset();\r\n }\r\n });\r\n return false;\r\n};"}}}},"items":{"_changes":{"query":{"limit":50,"descending":"true","view":"recent-items"},"data":"function(data) {\r\n // $.log(data)\r\n var p;\r\n return {\r\n items : data.rows.map(function(r) {\r\n p = (r.value && r.value.profile) || {};\r\n p.message = r.value && r.value.message;\r\n return p;\r\n })\r\n }\r\n};","mustache":"

    Customize this format here: ddoc.evently.items._changes.mustache

    \r\n

    Recent Messages

    \r\n
      \r\n {{#items}}\r\n
    • \r\n
      \r\n {{#gravatar_url}}\"{{name}}\"/{{/gravatar_url}}\r\n
      \r\n {{nickname}}\r\n
      \r\n
      \r\n

      {{message}}

      \r\n
      \r\n
    • \r\n {{/items}}\r\n
    \r\n

    Protip: If you setup continuous replication between this database and a remote one, this list will reflect remote changes in near real-time.

    \r\n

    This would be a good place to add pagination.

    "}}},"updates":{},"couchapp":{"signatures":{"index.html":"d97dccd049594dc0f800004b9d836fb8","data/hg19.ucsc.refine.header.seq.zip":"dd0e396c9c0f35c4713d3ea4c0ce9282","api.html":"a9726cbd4eb1c06eaeaef8ad68b8f0f1","vendor/couchapp/jquery.pathbinder.js":"5df725edddaa4c44578d1612a0e7a824","tarHub.js":"02315a828b251e6b3f4d79d1505636f7","images/mirbase-logo-blue-web.png":"2ed2be2e99a2eee7c948e95e01bf32f2","suggestions.js":"3e6171c37fade7064abf60a015b2930b","vendor/couchapp/jquery.mustache.js":"3a0f0634fecad2a5c3197858635f8760","images/MDACC_RGB_TC_tag_V.png":"5dcd88884a1a8c3fbe63da090ce8bc53","images/targetscan_logo.gif":"be4cea592988e44bc3f6aa8d494d673f","data/human.mature.v18.txt.zip":"a4ad3fa30a02e69588eefd173a525222","vendor/couchapp/loader.js":"60c37eebecfe06a052ad8c8c4cfa1c09","style/layout.css":"e1516e02f81af8c09b11024970a385ed","canvasXpress.min.js":"082f6b4aeef3b520635be5c8cc4170f4","images/miranda_logo.jpg":"e41ece00932cfbfdaed047159ede1794","vendor/couchapp/jquery.couch.app.js":"ab4e9d6fdbe920b559b5f513fce40426","vendor/couchapp/jquery.evently.js":"1d2d8972f1b07413b3891854a20fb4bc","docs.html":"1677edc620e04e8a2e9c4056d89cfbb3","images/mirtarbase_logo.gif":"beb27ef079637af8f8511fa6d356b62d","vendor/couchapp/jquery.couch.app.util.js":"a8cb7dcb45f53b501268654ade94a6ad","images/genesmash.png":"b2a9805d27e3b5b3390963ededcf9e49"},"name":"tarHub: A RESTful resource for miRNA targets","objects":{},"description":"A relaxed way to get information about miRNA targeting genes","manifest":["shows/","language","updates/","evently/","evently/profile/","evently/profile/profileReady/","evently/profile/profileReady/selectors/","evently/profile/profileReady/selectors/form/","evently/profile/profileReady/selectors/form/submit.js","evently/profile/profileReady/mustache.html","evently/items/","evently/items/_changes/","evently/items/_changes/data.js","evently/items/_changes/mustache.html","evently/items/_changes/query.json","vendor/","vendor/couchapp/","vendor/couchapp/evently/","vendor/couchapp/evently/profile/","vendor/couchapp/evently/profile/profileReady/","vendor/couchapp/evently/profile/profileReady/data.js","vendor/couchapp/evently/profile/profileReady/after.js","vendor/couchapp/evently/profile/profileReady/mustache.html","vendor/couchapp/evently/profile/loggedIn.js","vendor/couchapp/evently/profile/loggedOut/","vendor/couchapp/evently/profile/loggedOut/after.js","vendor/couchapp/evently/profile/loggedOut/mustache.html","vendor/couchapp/evently/profile/noProfile/","vendor/couchapp/evently/profile/noProfile/selectors/","vendor/couchapp/evently/profile/noProfile/selectors/form/","vendor/couchapp/evently/profile/noProfile/selectors/form/submit.js","vendor/couchapp/evently/profile/noProfile/data.js","vendor/couchapp/evently/profile/noProfile/mustache.html","vendor/couchapp/evently/account/","vendor/couchapp/evently/account/adminParty/","vendor/couchapp/evently/account/adminParty/mustache.html","vendor/couchapp/evently/account/doSignup.js","vendor/couchapp/evently/account/doLogin.js","vendor/couchapp/evently/account/doLogout.js","vendor/couchapp/evently/account/loggedIn/","vendor/couchapp/evently/account/loggedIn/data.js","vendor/couchapp/evently/account/loggedIn/selectors.json","vendor/couchapp/evently/account/loggedIn/after.js","vendor/couchapp/evently/account/loggedIn/mustache.html","vendor/couchapp/evently/account/loggedOut/","vendor/couchapp/evently/account/loggedOut/selectors.json","vendor/couchapp/evently/account/loggedOut/mustache.html","vendor/couchapp/evently/account/signupForm/","vendor/couchapp/evently/account/signupForm/selectors/","vendor/couchapp/evently/account/signupForm/selectors/form/","vendor/couchapp/evently/account/signupForm/selectors/form/submit.js","vendor/couchapp/evently/account/signupForm/selectors/a[href=#login].json","vendor/couchapp/evently/account/signupForm/after.js","vendor/couchapp/evently/account/signupForm/mustache.html","vendor/couchapp/evently/account/loginForm/","vendor/couchapp/evently/account/loginForm/selectors/","vendor/couchapp/evently/account/loginForm/selectors/form/","vendor/couchapp/evently/account/loginForm/selectors/form/submit.js","vendor/couchapp/evently/account/loginForm/selectors/a[href=#signup].json","vendor/couchapp/evently/account/loginForm/after.js","vendor/couchapp/evently/account/loginForm/mustache.html","vendor/couchapp/evently/account/_init.js","vendor/couchapp/evently/README.md","vendor/couchapp/lib/","vendor/couchapp/lib/md5.js","vendor/couchapp/lib/docform.js","vendor/couchapp/lib/mustache.js","vendor/couchapp/lib/validate.js","vendor/couchapp/lib/code.js","vendor/couchapp/lib/list.js","vendor/couchapp/lib/path.js","vendor/couchapp/lib/atom.js","vendor/couchapp/lib/utils.js","vendor/couchapp/lib/redirect.js","vendor/couchapp/lib/linkup.js","vendor/couchapp/lib/markdown.js","vendor/couchapp/lib/cache.js","vendor/couchapp/metadata.json","couchapp.json","views/","views/by_matureMIRmethod/","views/by_matureMIRmethod/map.js","views/by_matmir/","views/by_matmir/reduce.js","views/by_matmir/map.js","views/by_geneIDmethod/","views/by_geneIDmethod/map.js","views/by_miRNAIDcount/","views/by_miRNAIDcount/map.js","views/by_matureMIRcount/","views/by_matureMIRcount/map.js","views/by_geneIDcount/","views/by_geneIDcount/map.js","views/by_miRNAIDmethod/","views/by_miRNAIDmethod/map.js","lists/","lists/interactionHTML.js","lists/matureMIRinteraction.js","lists/sort.js","lists/open.js","lists/miRbase.js","lists/interactionTSV.js","lists/matureMIRinteractionTSV.js"],"last_updated_on":"2013-03-08"},"shows":{},"_attachments":{"index.html":{"content_type":"text/html","revpos":452,"digest":"md5-TM41W5FtrqkF6nFwA1rWzw==","length":9692,"stub":true},"data/hg19.ucsc.refine.header.seq.zip":{"content_type":"application/x-zip-compressed","revpos":200,"digest":"md5-3Q45bJwPNcRxPT6kwM6Sgg==","length":10066829,"stub":true},"api.html":{"content_type":"text/html","revpos":450,"digest":"md5-jk/s5CZdGy3X/rXuEi7Z9w==","length":11256,"stub":true},"vendor/couchapp/jquery.pathbinder.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-Xfcl7d2qTERXjRYSoOeoJA==","length":5052,"stub":true},"images/mirbase-logo-blue-web.png":{"content_type":"image/x-png","revpos":5,"digest":"md5-LtK+Lpmi7ufJSOleAb8y8g==","length":30812,"stub":true},"tarHub.js":{"content_type":"application/x-javascript","revpos":492,"digest":"md5-AjFagoslHms/TXnRUFY29w==","length":21312,"stub":true},"vendor/couchapp/jquery.mustache.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-Og8GNP7K0qXDGXhYY1+HYA==","length":9812,"stub":true},"images/MDACC_RGB_TC_tag_V.png":{"content_type":"image/x-png","revpos":4,"digest":"md5-Xc2IiEoajD++Y9oJDOi8Uw==","length":38203,"stub":true},"images/targetscan_logo.gif":{"content_type":"image/gif","revpos":138,"digest":"md5-vkzqWSmI5EvD9qqNSU1nPw==","length":6717,"stub":true},"data/human.mature.v18.txt.zip":{"content_type":"application/x-zip-compressed","revpos":200,"digest":"md5-pK0/owoC5pWI7v0XOlJSIg==","length":30406,"stub":true},"vendor/couchapp/loader.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-YMN+6+z+BqBSrYyMTPocCQ==","length":474,"stub":true},"style/layout.css":{"content_type":"text/css","revpos":446,"digest":"md5-kipZ8LT++l/lvfch5AjTqQ==","length":2566,"stub":true},"canvasXpress.min.js":{"content_type":"application/x-javascript","revpos":427,"digest":"md5-CC9rSu7ztSBjW+XIzEFw9A==","length":984446,"stub":true},"images/mirtarbase_logo.gif":{"content_type":"image/gif","revpos":141,"digest":"md5-vrJ+8Hljevj4UR+m01a2LQ==","length":6513,"stub":true},"images/miranda_logo.jpg":{"content_type":"image/pjpeg","revpos":80,"digest":"md5-5B7OAJMs+/2u0EcVnt4XlA==","length":39587,"stub":true},"vendor/couchapp/jquery.couch.app.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-q06db9vpILVZtfUT/OQEJg==","length":7493,"stub":true},"vendor/couchapp/jquery.evently.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-HS2JcvGwdBOziRhUog+0vA==","length":12132,"stub":true},"docs.html":{"content_type":"text/html","revpos":452,"digest":"md5-POvMnLJQuZ75EcLi7vlqQg==","length":20021,"stub":true},"suggestions.js":{"content_type":"application/x-javascript","revpos":347,"digest":"md5-PmFxw3+t5wZKv2CgFbKTCw==","length":1709,"stub":true},"vendor/couchapp/jquery.couch.app.util.js":{"content_type":"application/x-javascript","revpos":1,"digest":"md5-qMt9y0X1O1ASaGVK3pSmrQ==","length":3141,"stub":true},"images/genesmash.png":{"content_type":"image/x-png","revpos":4,"digest":"md5-sqmAXSfjtbM5CWPt7c+eSQ==","length":5704,"stub":true}}}