{"_id":"magnum","_rev":"27-fda0cb9c4835e2bad45895156b9ef788","name":"magnum","dist-tags":{"latest":"0.1.8"},"versions":{"0.1.6":{"name":"magnum","version":"0.1.6","keywords":["template","template engine","microsoft razor","razor","general purpose"],"author":{"name":"sinclair"},"_id":"magnum@0.1.6","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/magnum/issues"},"dist":{"shasum":"2515988832486c83bfcfa96f512029d14da947d4","tarball":"https://registry.npmjs.org/magnum/-/magnum-0.1.6.tgz","integrity":"sha512-Cr2J4jWGb1dgKIQ8GRwJE07pWWx3A29mNc78PGLEyinDECoxwv8ipF1f+f1yymK03O342LQkjVKd6pEEtScg7Q==","signatures":[{"sig":"MEUCIQDaAltFcQaIc/3vViLKtSzWgwfGzJkScigowXcQFIfhagIgC5HJa3PMlQnCSbsR5BRgBT2rii9+cGerEFwLSmzSKgE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"﻿![](https://raw.github.com/sinclairzx81/magnum/master/logo.png)\r\n\r\nA easy to use, general purpose template engine for nodejs. \r\n\r\n### install\r\n\r\n\tnpm install magnum\r\n\r\n### contents\r\n* [overview](#overview)\r\n* [api](#api)\r\n\t* [render](#render)\r\n\t* [compile](#compile)\r\n\t* [context](#context)\r\n* [syntax](#syntax)\r\n\t* [expressions](#expressions)\r\n\t* [if statements](#if)\r\n\t* [for statements](#if)\r\n\t* [comments](#comments)\r\n\t* [code blocks](#codeblock)\r\n* [layouts](#layouts)\r\n\t* [import](#import)\r\n\t* [render](#render)\r\n\r\n<a name='overview' />\r\n### overview\r\n\r\nThe following outlines a layout, view and code required to render the output. \r\n\r\nlayout.html\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t@section header\r\n\t</head>\r\n\t<body>\r\n\t\t@section body\r\n\t</body>\r\n</html>\r\n```\r\n\r\nview.html\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\napp.js\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar context = { title: 'my page'}\r\n\r\nvar html = magnum.render('./view.html', context)\r\n\r\nconsole.log(html)\r\n```\r\noutputs:\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t<title>my page</html>\r\n\t</head>\r\n\t<body>\r\n\t\t<h1>Welcome</h1>\r\n\t</body>\r\n</html>\r\n```\r\n\r\n\r\n\r\n<a name='api' />\r\n### api\r\n\r\nThe following are the methods exposed by the magnum api.\r\n\r\n<a name='render' />\r\n#### render\r\n\r\ncompiles and renders the output.\r\n\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar output = magnum.render('./view.html')\r\n\r\n```\r\n\r\n<a name='compile' />\r\n#### compile\r\n\r\ncompiles the template and returns a template object. users can use this compile once, and prevent extra reads to disk.\r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar template = magnum.compile('./view.html') // save compiled template for later.\r\n\r\nvar html     = template.render({title: 'my page'})\r\n\r\nconsole.log(html)\r\n```\r\n\r\n#### context\r\n\r\nWhen calling render() on a template, you can optionally pass a data context (an object) to be rendered. Magnum encapulates all data passed on the \"context\"\r\nobject which is passed to magnum template on the render() method. Consider the following..\r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar context = {name: 'dave', fruits: ['apples', 'oranges', 'kiwifruit', 'mangos', 'grapes']}\r\n\r\nvar html = magnum.render('./template.html', context)\r\n```\r\n\r\nthe context can be accessed in the following way...\r\n\r\ntemplate.html\r\n```html\r\n\r\n<p>Hi @(context.name)</p>\r\n\r\n<ul>\r\n\r\n\t@for(var i = 0; i < context.fruits.length; i++) {\r\n\r\n\t\t<li>@(context.fruits[i])</li>\r\n\t}\r\n\r\n</ul>\r\n```\r\n\r\ncontexts are optional.\r\n\r\n<a name='syntax' />\r\n### syntax\r\n\r\nThe following syntax is available inside magnum templates.\r\n\r\n<a name='expressions' />\r\n#### expressions\r\n\r\nwill emit the value contained.\r\n\r\n```\r\n@('hello world')\r\n\r\n@(123)\r\n\r\n@(some_variable)\r\n```\r\n\r\n<a name='if' />\r\n#### if statement\r\n\r\nif statments are supported.\r\n\r\n```\r\n@if(expression) {\r\n\tsome content\r\n}\r\n\r\n@if(a > 10) {\r\n\tsome content\r\n}\r\n\r\n@(user.loggedin) {\r\n\t<span>welcome</span>\r\n}\r\n```\r\n\r\n<a name='for' />\r\n#### for statement\r\n\r\nthe following for loops are supported.\r\n\r\n```\r\n@for(var i = i; i < 100; i++) {\r\n\t@(i)\r\n}\r\n\r\n@for(var n in list) {\r\n\t@(list[n])\r\n}\r\n```\r\n\r\n\r\n<a name='codeblock' />\r\n#### code blocks\r\n\r\ncode blocks can be useful for adding template side rendering logic.\r\n\r\n```\r\n@{\r\n\tvar message = 'hello'\r\n}\r\n\r\n@(message)\r\n```\r\n\r\n<a name='comments' />\r\n#### comments\r\n```\r\n@*\r\n\tthis comment will not be rendered!\r\n*@\r\n```\r\n\r\n<a name=\"template_layouts_and_sections\" />\r\n### layouts and sections\r\n\r\nMangum supports layouts and sections. This section describes how to use them.\r\n\r\n#### import\r\n\r\nUse the import statement to have one template inheriate from another. This will allow the child template to (optionally) override the \r\nsections of the parent. \r\n\r\n##### layout.html\r\nlayout.html will be the parent template, here we define three sections.. header, body and footer. \r\n\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t@section header\r\n\t</head>\r\n\t<body>\r\n\t\t@section body\r\n\t\t@section footer {\r\n\t\t\t<span>copyright 2013</span>\r\n\t\t}\r\n\t</body>\r\n</html>\r\n```\r\n\r\n##### view.html\r\nInside view.html, we inheriate from layout.html with the import keyword. Inside view.html, we define sections for header and body. Note that\r\nthe default content for the footer not overridden. If the child template does not override a parents section, the parents section will be used\r\ninstead.\r\n\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n#### render\r\n\r\nMagnum templates allow the user to render snippets of content in place. The following renders a template named navigation.html in place. \r\n\r\n```\r\n<html>\r\n\t<head>\r\n\t</head>\r\n\t<body>\r\n\t\t@render 'navigation.html'\r\n\t\t@section content\r\n\t</body>\r\n</html>\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"https://raw.github.com/sinclairzx81/magnum/master/license.txt","type":"The MIT License (MIT)"}],"repository":{"url":"https://github.com/sinclairzx81/magnum.git","type":"git"},"_npmVersion":"1.3.8","description":"General purpose javascript template engine inspired by Microsoft Razor templates.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.1.7":{"name":"magnum","version":"0.1.7","keywords":["template","template engine","microsoft razor","razor","general purpose"],"author":{"name":"sinclair"},"_id":"magnum@0.1.7","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/magnum/issues"},"dist":{"shasum":"7c678e3751ffb41c750e1c1fac0c9dc73e4c66af","tarball":"https://registry.npmjs.org/magnum/-/magnum-0.1.7.tgz","integrity":"sha512-1nEYkkEtX20hGUfASGGrTQVz8SouuVLS+Q6chksdh56bOLwL/Bl7gt7TaYEsutYLscxae7H8mv2TATwHLFSyvw==","signatures":[{"sig":"MEYCIQC/vFDqjYaBMMqRUSvX7duh+aex5BG6nAdW+TeSkZz/YwIhAN7mG7hHT00V2cdfzbLJQBZF5WRG73PGy5Fu1ALJ53dF","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"﻿![](https://raw.github.com/sinclairzx81/magnum/master/logo.png)\r\n\r\nA fast, easy to use, general purpose template view engine for nodejs.\r\n\r\n### install\r\n\r\n\tnpm install magnum\r\n\r\n### contents\r\n* [overview](#overview)\r\n* [example](#example)\r\n* [api](#api)\r\n\t* [render](#render)\r\n\t* [compile](#compile)\r\n\t* [context](#context)\r\n* [syntax](#syntax)\r\n\t* [expressions](#expressions)\r\n\t* [if statements](#if)\r\n\t* [for statements](#for)\r\n\t* [comments](#commentblock)\r\n\t* [code blocks](#codeblock)\r\n* [layouts](#layouts)\r\n\t* [import](#import)\r\n\t* [render](#render)\r\n* [express](#express)\r\n\r\n<a name='overview' />\r\n## overview\r\n\r\nMagnum is a general purpose logic driven templating engine for nodejs developers. Magnum templates allow developers to easily script \r\ncomplex view logic with a javascript like syntax. Magnum focuses on being general purpose to enable developers can leverage it for \r\ncode generation, html templates, xml or other niche template scenarios.\r\n\r\nInspired by Microsoft Razor\r\n\r\n<a name='example' />\r\n## example\r\n\r\nThe following is a quick example demonstrating rendering a template.\r\n\r\n#### layout.html\r\n```html\r\n\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t@section header\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@section body\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n#### view.html\r\n```html\r\n\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n#### app.js\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar context = { title: 'my page'}\r\n\r\nvar html = magnum.render('./view.html', context)\r\n\r\nconsole.log(html)\r\n```\r\n\r\n#### outputs\r\n\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t<title>my page</html>\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t<h1>Welcome</h1>\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n<a name='api' />\r\n## api\r\n\r\nThe following outlines magnums methods.\r\n\r\n<a name='compile' />\r\n### compile\r\n\r\nThe compile() method compiles the template file and returns a template object. \r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar template = magnum.compile('./view.html')  // store for later\r\n\r\n//...later\r\n\r\nvar context = {title: 'my page'}\r\n\r\nvar html     = template.render(context) // render \r\n\r\nconsole.log(html)\r\n```\r\n\r\n<a name='render' />\r\n### render\r\n\r\nTo quickly compile and render a view, call the magnum.render() method.\r\n\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar output = magnum.render('./view.html')\r\n\r\n```\r\n\r\n### context\r\n\r\nWhen calling render() on a template (or via magnum itself), you can optionally pass a data context object to be rendered. \r\nMagnum encapulates all data passed on the \"context\"\r\nobject which is passed to magnum template on the render() method. Consider the following..\r\n\r\n#### template.html\r\n```html\r\n\r\n<p>Hi @(context.name)</p>\r\n\r\n<ul>\r\n\r\n\t@for(var i = 0; i < context.fruits.length; i++) {\r\n\r\n\t\t<li>@(context.fruits[i])</li>\r\n\t}\r\n\r\n</ul>\r\n```\r\n\r\n#### app.js\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar context = {name   : 'dave', \r\n\t\t       fruits : ['apples', \r\n\t\t\t\t\t\t 'oranges', \r\n\t\t\t\t\t\t 'kiwifruit', \r\n\t\t\t\t\t\t 'mangos', \r\n\t\t\t\t\t\t 'grapes' ]}\r\n\r\nvar html = magnum.render('./template.html', context)\r\n```\r\n\r\nthe context can be accessed in the following way...\r\n\r\n\r\n\r\n<a name='syntax' />\r\n## syntax\r\n\r\nThe following syntax is available inside magnum templates.\r\n\r\n<a name='expressions' />\r\n### expressions\r\n\r\nThe expression syntax allows a user to emit the value within. The following are examples. \r\n\r\n```\r\n@* strings *@\r\n@('hello world')\r\n\r\n@* numbers *@\r\n@(123)\r\n\r\n@* conditions: displays false) *@\r\n@(10 > 20)\r\n\r\n@* ternary: displays 'cat' *@\r\n@(true ? 'cat' : 'dog')\r\n\r\n@* variables *@\r\n@(myvariable)\r\n\r\n@* functions: displays 'hello world' *@\r\n@{ var message = function() { return 'hello world' } }\r\n\r\n@(message())\r\n\r\n```\r\n\r\n<a name='if' />\r\n### if statement\r\n\r\nif statments are supported.\r\n\r\n```\r\n@if(expression) {\r\n\tsome content\r\n}\r\n\r\n@if(a > 10) {\r\n\tsome content\r\n}\r\n\r\n@(user.loggedin) {\r\n\t<span>welcome</span>\r\n}\r\n```\r\n\r\n<a name='for' />\r\n### for statement\r\n\r\nthe following for loops are supported.\r\n\r\n```\r\n@for(var i = i; i < 100; i++) {\r\n\t@(i)\r\n}\r\n\r\n@for(var n in list) {\r\n\t@(list[n])\r\n}\r\n```\r\n\r\n\r\n<a name='codeblock' />\r\n### code\r\n\r\ncode blocks can be useful for adding template side rendering logic.\r\n\r\n```\r\n@{\r\n\tvar message = 'hello'\r\n}\r\n\r\n@(message)\r\n```\r\n\r\n<a name='commentblock' />\r\n### comments\r\n```\r\n@*\r\n\tthis comment will not be rendered!\r\n*@\r\n```\r\n\r\n<a name=\"template_layouts_and_sections\" />\r\n### layouts and sections\r\n\r\nMangum supports layouts and sections. This section describes how to use them.\r\n\r\n### import\r\n\r\nUse the import statement to have one template inheriate from another. This will allow the child template to (optionally) override the \r\nsections of the parent. \r\n\r\n#### layout.html\r\nlayout.html will be the parent template, here we define three sections.. header, body and footer. \r\n\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t@section header\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@section body\r\n\r\n\t\t@section footer {\r\n\r\n\t\t\t<span>copyright 2013</span>\r\n\t\t}\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n#### view.html\r\nInside view.html, we inheriate from layout.html with the import keyword. Inside view.html, we define sections for header and body. Note that\r\nthe default content for the footer not overridden. If the child template does not override a parents section, the parents section will be used\r\ninstead.\r\n\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n### render\r\n\r\nMagnum templates allow the user to render snippets of content in place. The following renders a template named navigation.html in place. \r\n\r\n#### navigation.html\r\n```html\r\n\r\n\t<ul>\r\n\r\n\t\t<li><a href='#'>home</a></li>\r\n\r\n\t\t<li><a href='#'>about</a></li>\r\n\r\n\t\t<li><a href='#'>contact</a></li>\r\n\r\n\t</ul>\r\n```\r\n\r\n#### layout.html\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@render 'navigation.html'\r\n\r\n\t\t@section content\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n<a name='express' />\r\n##express\r\nMagnum does not provide any built in middleware for specifically for express, however it is trivial for developers to 'snap in' utility \r\nmethods on the express response to acheive desireable results. consider the following...\r\n\r\n```javascript\r\n\r\nvar express = require('express')\r\n\r\nvar magnum  = require('magnum')\r\n\r\n//----------------------------------------------\r\n// setup: create and apply render method\r\n//----------------------------------------------\r\n\r\nvar app     = express()\r\n\r\napp.use(function (req, res, next) {\r\n\r\n    res.render = function (path, context) {\r\n\r\n        var output = magnum.render(path, context)\r\n\r\n        res.setHeader('Content-Type', 'text/html')\r\n\r\n        res.setHeader('Content-Length', Buffer.byteLength(output))\r\n\r\n        res.send(output)\r\n    }\r\n\t\r\n    next()\r\n})\r\n\r\n\r\n//----------------------------------------------\r\n// render the template...\r\n//----------------------------------------------\r\n\r\napp.get('/', function(req, res) {\r\n\t\r\n\tres.render('./index.html') \r\n})\r\n```\r\n\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"https://raw.github.com/sinclairzx81/magnum/master/license.txt","type":"The MIT License (MIT)"}],"repository":{"url":"https://github.com/sinclairzx81/magnum.git","type":"git"},"_npmVersion":"1.3.8","description":"General purpose javascript template engine inspired by Microsoft Razor templates.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.1.8":{"name":"magnum","version":"0.1.8","keywords":["template","template engine","microsoft razor","razor","general purpose"],"author":{"name":"sinclair"},"_id":"magnum@0.1.8","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/magnum/issues"},"dist":{"shasum":"b2a1e185c89abf09122d9eb6458562ef7f60aaba","tarball":"https://registry.npmjs.org/magnum/-/magnum-0.1.8.tgz","integrity":"sha512-1cOsmYI+8l52NSDNLW7YFvjhXB0V7SWcgDFLoAWbm5HoEitkJopbQGgCos6yHXKge/dsowxbnncRYaO16+1eJA==","signatures":[{"sig":"MEQCIBZBNNJ+GkYmf3F1i/ZvUrdMIE0hUqtNoqSDwkkUs74KAiBiUo+KVcCPwGv+8V+mpJgkGawbSKk0Nvdv7SpbjtyYBw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"﻿![](https://raw.github.com/sinclairzx81/magnum/master/logo.png)\r\n\r\nA fast, easy to use, general purpose template view engine for nodejs.\r\n\r\n### install\r\n\r\n\tnpm install magnum\r\n\r\n### contents\r\n* [overview](#overview)\r\n* [example](#example)\r\n* [api](#api)\r\n\t* [render](#render)\r\n\t* [compile](#compile)\r\n\t* [context](#context)\r\n* [syntax](#syntax)\r\n\t* [expressions](#expressions)\r\n\t* [if statements](#if)\r\n\t* [for statements](#for)\r\n\t* [comments](#commentblock)\r\n\t* [code blocks](#codeblock)\r\n* [layouts](#layouts)\r\n\t* [import](#import)\r\n\t* [render](#render)\r\n* [express](#express)\r\n\r\n<a name='overview' />\r\n## overview\r\n\r\nMagnum is a general purpose logic driven templating engine for nodejs developers. Magnum templates allow developers to easily script \r\ncomplex view logic with a javascript like syntax. Magnum focuses on being general purpose to enable developers can leverage it for \r\ncode generation, html templates, xml or other niche template scenarios.\r\n\r\nInspired by Microsoft Razor\r\n\r\n<a name='example' />\r\n## example\r\n\r\nThe following is a quick example demonstrating rendering a template.\r\n\r\n#### layout.html\r\n```html\r\n\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t@section header\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@section body\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n#### view.html\r\n```html\r\n\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n#### app.js\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar context = { title: 'my page'}\r\n\r\nvar html = magnum.render('./view.html', context)\r\n\r\nconsole.log(html)\r\n```\r\n\r\n#### outputs\r\n\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t<title>my page</html>\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t<h1>Welcome</h1>\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n<a name='api' />\r\n## api\r\n\r\nThe following outlines magnums methods.\r\n\r\n<a name='compile' />\r\n### compile\r\n\r\nThe compile() method compiles the template file and returns a template object. \r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar template = magnum.compile('./view.html')  // store for later\r\n\r\n//...later\r\n\r\nvar context = {title: 'my page'}\r\n\r\nvar html     = template.render(context) // render \r\n\r\nconsole.log(html)\r\n```\r\n\r\n<a name='render' />\r\n### render\r\n\r\nTo quickly compile and render a view, call the magnum.render() method.\r\n\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar output = magnum.render('./view.html')\r\n\r\n```\r\n\r\n### context\r\n\r\nWhen calling render() on a template (or via magnum itself), you can optionally pass a data context object to be rendered. \r\nMagnum encapulates all data passed on the \"context\"\r\nobject which is passed to magnum template on the render() method. Consider the following..\r\n\r\n#### template.html\r\n```html\r\n\r\n<p>Hi @(context.name)</p>\r\n\r\n<ul>\r\n\r\n\t@for(var i = 0; i < context.fruits.length; i++) {\r\n\r\n\t\t<li>@(context.fruits[i])</li>\r\n\t}\r\n\r\n</ul>\r\n```\r\n\r\n#### app.js\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar context = {name   : 'dave', \r\n\t\t       fruits : ['apples', \r\n\t\t\t\t\t\t 'oranges', \r\n\t\t\t\t\t\t 'kiwifruit', \r\n\t\t\t\t\t\t 'mangos', \r\n\t\t\t\t\t\t 'grapes' ]}\r\n\r\nvar html = magnum.render('./template.html', context)\r\n```\r\n\r\nthe context can be accessed in the following way...\r\n\r\n\r\n\r\n<a name='syntax' />\r\n## syntax\r\n\r\nThe following syntax is available inside magnum templates.\r\n\r\n<a name='expressions' />\r\n### expressions\r\n\r\nThe expression syntax allows a user to emit the value within. The following are examples. \r\n\r\n```\r\n@* strings *@\r\n@('hello world')\r\n\r\n@* numbers *@\r\n@(123)\r\n\r\n@* conditions: displays false) *@\r\n@(10 > 20)\r\n\r\n@* ternary: displays 'cat' *@\r\n@(true ? 'cat' : 'dog')\r\n\r\n@* variables *@\r\n@(myvariable)\r\n\r\n@* functions: displays 'hello world' *@\r\n@{ var message = function() { return 'hello world' } }\r\n\r\n@(message())\r\n\r\n```\r\n\r\n<a name='if' />\r\n### if statement\r\n\r\nif statments are supported.\r\n\r\n```\r\n@if(expression) {\r\n\tsome content\r\n}\r\n\r\n@if(a > 10) {\r\n\tsome content\r\n}\r\n\r\n@(user.loggedin) {\r\n\t<span>welcome</span>\r\n}\r\n```\r\n\r\n<a name='for' />\r\n### for statement\r\n\r\nthe following for loops are supported.\r\n\r\n```\r\n@for(var i = i; i < 100; i++) {\r\n\t@(i)\r\n}\r\n\r\n@for(var n in list) {\r\n\t@(list[n])\r\n}\r\n```\r\n\r\n\r\n<a name='codeblock' />\r\n### code\r\n\r\ncode blocks can be useful for adding template side rendering logic.\r\n\r\n```\r\n@{\r\n\tvar message = 'hello'\r\n}\r\n\r\n@(message)\r\n```\r\n\r\n<a name='commentblock' />\r\n### comments\r\n```\r\n@*\r\n\tthis comment will not be rendered!\r\n*@\r\n```\r\n\r\n<a name=\"template_layouts_and_sections\" />\r\n### layouts and sections\r\n\r\nMangum supports layouts and sections. This section describes how to use them.\r\n\r\n### import\r\n\r\nUse the import statement to have one template inheriate from another. This will allow the child template to (optionally) override the \r\nsections of the parent. \r\n\r\n#### layout.html\r\nlayout.html will be the parent template, here we define three sections.. header, body and footer. \r\n\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t\t@section header\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@section body\r\n\r\n\t\t@section footer {\r\n\r\n\t\t\t<span>copyright 2013</span>\r\n\t\t}\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n#### view.html\r\nInside view.html, we inheriate from layout.html with the import keyword. Inside view.html, we define sections for header and body. Note that\r\nthe default content for the footer not overridden. If the child template does not override a parents section, the parents section will be used\r\ninstead.\r\n\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n### render\r\n\r\nMagnum templates allow the user to render snippets of content in place. The following renders a template named navigation.html in place. \r\n\r\n#### navigation.html\r\n```html\r\n\r\n\t<ul>\r\n\r\n\t\t<li><a href='#'>home</a></li>\r\n\r\n\t\t<li><a href='#'>about</a></li>\r\n\r\n\t\t<li><a href='#'>contact</a></li>\r\n\r\n\t</ul>\r\n```\r\n\r\n#### layout.html\r\n```html\r\n<html>\r\n\r\n\t<head>\r\n\r\n\t</head>\r\n\r\n\t<body>\r\n\r\n\t\t@render 'navigation.html'\r\n\r\n\t\t@section content\r\n\r\n\t</body>\r\n\r\n</html>\r\n```\r\n\r\n<a name='express' />\r\n##express\r\nMagnum does not provide any built in middleware for specifically for express, however it is trivial for developers to 'snap in' utility \r\nmethods on the express response to acheive desireable results. consider the following...\r\n\r\n```javascript\r\n\r\nvar express = require('express')\r\n\r\nvar magnum  = require('magnum')\r\n\r\n//----------------------------------------------\r\n// setup: create and apply render method\r\n//----------------------------------------------\r\n\r\nvar app     = express()\r\n\r\napp.use(function (req, res, next) {\r\n\r\n    res.render = function (path, context) {\r\n\r\n        var output = magnum.render(path, context)\r\n\r\n        res.setHeader('Content-Type', 'text/html')\r\n\r\n        res.setHeader('Content-Length', Buffer.byteLength(output))\r\n\r\n        res.send(output)\r\n    }\r\n\t\r\n    next()\r\n})\r\n\r\n\r\n//----------------------------------------------\r\n// render the template...\r\n//----------------------------------------------\r\n\r\napp.get('/', function(req, res) {\r\n\t\r\n\tres.render('./index.html') \r\n})\r\n```\r\n\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"https://raw.github.com/sinclairzx81/magnum/master/license.txt","type":"The MIT License (MIT)"}],"repository":{"url":"https://github.com/sinclairzx81/magnum.git","type":"git"},"_npmVersion":"1.3.8","description":"General purpose javascript template engine inspired by Microsoft Razor templates.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"}},"time":{"created":"2013-12-25T12:40:24.006Z","modified":"2026-04-15T10:56:56.645Z","0.1.6":"2013-12-25T12:40:29.036Z","0.1.7":"2013-12-26T03:19:12.451Z","0.1.8":"2013-12-28T05:56:39.527Z"},"author":{"name":"sinclair"},"repository":{"url":"https://github.com/sinclairzx81/magnum.git","type":"git"},"description":"General purpose javascript template engine inspired by Microsoft Razor templates.","keywords":["template","template engine","microsoft razor","razor","general purpose"],"bugs":{"url":"https://github.com/sinclairzx81/magnum/issues"},"maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"readme":"﻿![](https://raw.github.com/sinclairzx81/magnum/master/logo.png)\r\n\r\nA easy to use, general purpose template engine for nodejs. \r\n\r\n### install\r\n\r\n\tnpm install magnum\r\n\r\n### contents\r\n* [overview](#overview)\r\n* [api](#api)\r\n\t* [render](#render)\r\n\t* [compile](#compile)\r\n\t* [context](#context)\r\n* [syntax](#syntax)\r\n\t* [expressions](#expressions)\r\n\t* [if statements](#if)\r\n\t* [for statements](#if)\r\n\t* [comments](#comments)\r\n\t* [code blocks](#codeblock)\r\n* [layouts](#layouts)\r\n\t* [import](#import)\r\n\t* [render](#render)\r\n\r\n<a name='overview' />\r\n### overview\r\n\r\nThe following outlines a layout, view and code required to render the output. \r\n\r\nlayout.html\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t@section header\r\n\t</head>\r\n\t<body>\r\n\t\t@section body\r\n\t</body>\r\n</html>\r\n```\r\n\r\nview.html\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\napp.js\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar context = { title: 'my page'}\r\n\r\nvar html = magnum.render('./view.html', context)\r\n\r\nconsole.log(html)\r\n```\r\noutputs:\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t<title>my page</html>\r\n\t</head>\r\n\t<body>\r\n\t\t<h1>Welcome</h1>\r\n\t</body>\r\n</html>\r\n```\r\n\r\n\r\n\r\n<a name='api' />\r\n### api\r\n\r\nThe following are the methods exposed by the magnum api.\r\n\r\n<a name='render' />\r\n#### render\r\n\r\ncompiles and renders the output.\r\n\r\n```javascript\r\nvar magnum = require('magnum')\r\n\r\nvar output = magnum.render('./view.html')\r\n\r\n```\r\n\r\n<a name='compile' />\r\n#### compile\r\n\r\ncompiles the template and returns a template object. users can use this compile once, and prevent extra reads to disk.\r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar template = magnum.compile('./view.html') // save compiled template for later.\r\n\r\nvar html     = template.render({title: 'my page'})\r\n\r\nconsole.log(html)\r\n```\r\n\r\n#### context\r\n\r\nWhen calling render() on a template, you can optionally pass a data context (an object) to be rendered. Magnum encapulates all data passed on the \"context\"\r\nobject which is passed to magnum template on the render() method. Consider the following..\r\n\r\n```javascript\r\n\r\nvar magnum   = require('magnum')\r\n\r\nvar context = {name: 'dave', fruits: ['apples', 'oranges', 'kiwifruit', 'mangos', 'grapes']}\r\n\r\nvar html = magnum.render('./template.html', context)\r\n```\r\n\r\nthe context can be accessed in the following way...\r\n\r\ntemplate.html\r\n```html\r\n\r\n<p>Hi @(context.name)</p>\r\n\r\n<ul>\r\n\r\n\t@for(var i = 0; i < context.fruits.length; i++) {\r\n\r\n\t\t<li>@(context.fruits[i])</li>\r\n\t}\r\n\r\n</ul>\r\n```\r\n\r\ncontexts are optional.\r\n\r\n<a name='syntax' />\r\n### syntax\r\n\r\nThe following syntax is available inside magnum templates.\r\n\r\n<a name='expressions' />\r\n#### expressions\r\n\r\nwill emit the value contained.\r\n\r\n```\r\n@('hello world')\r\n\r\n@(123)\r\n\r\n@(some_variable)\r\n```\r\n\r\n<a name='if' />\r\n#### if statement\r\n\r\nif statments are supported.\r\n\r\n```\r\n@if(expression) {\r\n\tsome content\r\n}\r\n\r\n@if(a > 10) {\r\n\tsome content\r\n}\r\n\r\n@(user.loggedin) {\r\n\t<span>welcome</span>\r\n}\r\n```\r\n\r\n<a name='for' />\r\n#### for statement\r\n\r\nthe following for loops are supported.\r\n\r\n```\r\n@for(var i = i; i < 100; i++) {\r\n\t@(i)\r\n}\r\n\r\n@for(var n in list) {\r\n\t@(list[n])\r\n}\r\n```\r\n\r\n\r\n<a name='codeblock' />\r\n#### code blocks\r\n\r\ncode blocks can be useful for adding template side rendering logic.\r\n\r\n```\r\n@{\r\n\tvar message = 'hello'\r\n}\r\n\r\n@(message)\r\n```\r\n\r\n<a name='comments' />\r\n#### comments\r\n```\r\n@*\r\n\tthis comment will not be rendered!\r\n*@\r\n```\r\n\r\n<a name=\"template_layouts_and_sections\" />\r\n### layouts and sections\r\n\r\nMangum supports layouts and sections. This section describes how to use them.\r\n\r\n#### import\r\n\r\nUse the import statement to have one template inheriate from another. This will allow the child template to (optionally) override the \r\nsections of the parent. \r\n\r\n##### layout.html\r\nlayout.html will be the parent template, here we define three sections.. header, body and footer. \r\n\r\n```html\r\n<html>\r\n\t<head>\r\n\t\t@section header\r\n\t</head>\r\n\t<body>\r\n\t\t@section body\r\n\t\t@section footer {\r\n\t\t\t<span>copyright 2013</span>\r\n\t\t}\r\n\t</body>\r\n</html>\r\n```\r\n\r\n##### view.html\r\nInside view.html, we inheriate from layout.html with the import keyword. Inside view.html, we define sections for header and body. Note that\r\nthe default content for the footer not overridden. If the child template does not override a parents section, the parents section will be used\r\ninstead.\r\n\r\n```html\r\n@import 'layout.html'\r\n\r\n@section header {\r\n\t<title>@(context.title)</html>\r\n}\r\n\r\n@section body {\r\n\t<h1>Welcome</h1>\r\n}\r\n```\r\n\r\n#### render\r\n\r\nMagnum templates allow the user to render snippets of content in place. The following renders a template named navigation.html in place. \r\n\r\n```\r\n<html>\r\n\t<head>\r\n\t</head>\r\n\t<body>\r\n\t\t@render 'navigation.html'\r\n\t\t@section content\r\n\t</body>\r\n</html>\r\n```\r\n"}