{"_id":"mayo","_rev":"415854","name":"mayo","description":"Asynchronous template engine with coffeescript support","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"mhzed","email":"minhongz@gmail.com"}],"time":{"modified":"2017-03-30T13:22:40.000Z","created":"2013-02-28T08:01:21.686Z","0.1.0":"2013-02-28T08:01:21.686Z"},"users":{},"author":{"name":"zed zhou","email":"mhzedd@gmail.com","url":"http://mhzed.com"},"versions":{"0.1.0":{"name":"mayo","version":"0.1.0","author":{"name":"zed zhou","email":"mhzedd@gmail.com","url":"http://mhzed.com"},"keywords":["template","html","coffescript","asynchronous"],"description":"Asynchronous template engine with coffeescript support","homepage":"https://github.com/mhzed/mayo","bugs":{"email":"mhzedd@gmail.com"},"licenses":[{"type":"MIT"}],"engines":{"node":">=0.4.0"},"dependencies":{"under_score":">=0.1.0","coffee-script":"1.x"},"devDependencies":{"nodeunit":"*"},"optionalDependencies":{"coffee-script":"1.x"},"main":"./index","_id":"mayo@0.1.0","dist":{"shasum":"66fea1f2875b4b1aae12a3852f5d49827e7e8d15","size":19369,"noattachment":false,"tarball":"https://registry.npm.taobao.org/mayo/download/mayo-0.1.0.tgz"},"_npmVersion":"1.1.62","_npmUser":{"name":"mhzed","email":"minhongz@gmail.com"},"maintainers":[{"name":"mhzed","email":"minhongz@gmail.com"}],"directories":{},"publish_time":1362038481686,"_cnpm_publish_time":1362038481686,"_hasShrinkwrap":false}},"readme":"# mayo\n\nMayo is yet another generic template engine for javascript, key features include:\n\n1. supports javascript as the template language\n2. supports coffee-script as the template language\n3. supports inheritance\n4. supports embedding\n5. fully asynchronous, including async call inside template\n6. works in nodejs and in browser (requires jQuery in browser). Supported browsers are chrome/firefox/safari/opera,\n and any other browsers based on webkit engine. Internet Explorer has not been tested, but support is planned.\n7. built-in caching for optimum run time performance.\n8. uses a line based code marker, which makes template code easier to read(in author's opinion)\n\n## Basics\n\nA very basic usage example:\n\n var mayo = require(\"mayo\");\n mayo.run(\"abc#{number}#{param.number}\", {number: 4}, function(error, content) {\n // content is abc44\n } );\n\nIn the template, you may access the parameters directly or via the \"param\" parent object.\n\nA more complex template:\n\n ==== ./test.html contains\n

#{param.name}

\n -- param.coordinates.forEach(function(c) {\n
#{c.x}
#{c.y}
\n -- });\n\n ==== code is\n mayo.run(\"./test.html\", {\n name : \"dots\",\n coordinates : [ { x : 1, y: 2}, { x : 10, y: 20} ]\n }, function(err, content) {\n console.log(content);\n });\n\n ==== renders to\n

plain

\n
1
2
\n
10
20
\n\n## Syntax\n\n-- at the beginning of a line (preceding whitespaces are irrelevant) marks the line as code until the end of line (\\n)\nis reached. Use #{..} in content to embed javascript expression.\n\n-- on a line by itself marks the beginning/end of code block. Example:\n\n --\n var x = 1;\n // more js code\n --\n\nThe template syntax is fully configurable via mayo.config object, default is:\n{\n lineMarker : '--', // marker for single line code\n exprClosure : '#{?}' // marker for alternative embed expression, ? marks where the expression will be\n xcapeMarker : '!' // when inside of exprClosure, xml escape the value returned by expression using the\n // mayo's implicitly provided 'xcape' function\n directiveCh : '@', // when proceeded by lineMarker marker, specifies a 'directive', see performance/cache\n // section for example usage\n};\n\nTo change any of the configuration, simply do:\n\n mayo.config.lineMarker = '==';\n // the changes will take effect globally after above line is executed\n\nRegarding exprClosure: it gets converted to a RegExp, ? marks where the expression would be. Expression must be a\none-liner, and in the default case, must not contain '}' as '}' marks the end of closure. In case you want to render\n\\#{ to the output, then precede #{ with backslash \\\\. The same backslash escape rule also applies to 'lineMarker',\nexamples:\n\n \\--abc\\#{'1'}\n ==== renders to\n --abc#{'1'}\n\n \\\\--abc\n ==== renders to\n \\--abc\n\nRegarding xcapeMarker, often you want the value to be escaped for xml/html before rendering to output, in such case\nuse xcapeMarker marker:\n\n #{!''}\n ==== renders to\n <t>\n\nNote however\n\n #{ !''}\n ==== renders to\n false\n\n! must follow #{ immediately to take effect, otherwise it becomes part of javascript expression as the negation\noperator.\n\n## Embedding\n\nFor reuse-ability, you can place a commonly used template block in a separate file, and then embed it in other\ntemplates\n\n -- people.forEach(function(person) {\n ... template content ...\n -- _mayo.embed(\"./person.html\", {person: person});\n -- });\n\n_mayo is the implicit variable injected by template engine that refers to \"this\" template document. If you use \"this\",\nensure you bind it to forEach, example:\n\n -- people.forEach(function(person) {\n ... template content ...\n -- this.embed(\"./person.html\", {person: person});\n -- },this);\n\n## Inheritance\n\nAn example first:\n\n ==== ./base.html\n \n \n -- _mayo.block(\"head\");\n \n \n -- _mayo.block(\"body\"));\n \n \n\n ==== ./child.html\n -- _mayo.extend(\"./base.html\", {}, function() {\n -- _mayo.block(\"head\", function() {\n \n -- }); // end block \"head\"\n -- _mayo.block(\"body\", function() {\n
\n -- }); // end block \"body\"\n ... garbage ....\n -- }); // end extend\n\n ==== output of child.html\n \n \n \n \n \n
\n \n \n\n\"extend\" is an async function that extends this template from a base template. In the extended template, user\noverrides the blocks that are defined in base template. Note the text \"... garbage ...\" in child.html, because it's\noutside of any overridden block definitions, the text is discarded and not rendered to the output.\n\n* If you find above code extremely verbose and hard to read, consider using coffee-script, covered later.\n\nchild.html can further define more blocks inside \"body\" block\n\n ==== ./child.html\n -- _mayo.extend(\"./base.html\", {}, function(err) {\n -- _mayo.block(\"head\", function() {\n \n -- });\n -- _mayo.block(\"body\", function() {\n
\n --\n _mayo.block(\"menu\");\n _mayo.block(\"content\");\n --\n
\n -- }); // end block \"body\"\n -- });\n\n ==== ./grandchild.html\n -- _mayo.extend(\"./child.html\", {}, function(err) {\n -- _mayo.block(\"menu\", function() {\n