Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. {
  2. "name": "templates.js",
  3. "version": "0.2.7",
  4. "author": {
  5. "name": "psychobunny",
  6. "email": "psycho.bunny@hotmail.com"
  7. },
  8. "description": "An ultralight and super fast templating framework",
  9. "scripts": {
  10. "test": "./node_modules/.bin/mocha tests/main.js"
  11. },
  12. "repository": {
  13. "type": "git",
  14. "url": "git://github.com/psychobunny/templates.js"
  15. },
  16. "main": "./index.js",
  17. "keywords": [
  18. "templates",
  19. "templating",
  20. "framework",
  21. "javascript"
  22. ],
  23. "devDependencies": {
  24. "assert": "~1.1.1",
  25. "mocha": "^2.2.5",
  26. "express": "~3.4.8",
  27. "path": "~0.4.9",
  28. "async": "^0.9.0",
  29. "winston": "^0.7.3",
  30. "grunt": "^0.4.5",
  31. "grunt-mocha-test": "^0.12.7",
  32. "grunt-benchmark": "^0.3.0",
  33. "grunt-contrib-watch": "^0.6.1",
  34. "grunt-contrib-uglify": "^0.9.1"
  35. },
  36. "license": "MIT",
  37. "engines": {
  38. "node": ">=0.6"
  39. },
  40. "readme": "# <img alt=\"templates.js\" src=\"http://i.imgur.com/vVyRepC.png\" />\r\n[![Build Status](https://travis-ci.org/psychobunny/templates.js.png?branch=master)](https://travis-ci.org/psychobunny/templates.js)\r\n[![Code Climate](https://codeclimate.com/github/psychobunny/templates.js.png)](https://codeclimate.com/github/psychobunny/templates.js)\r\n[![Dependency Status](https://david-dm.org/psychobunny/templates.js.png)](https://david-dm.org/psychobunny/templates.js)\r\n\r\ntemplates.js is an ultralight (1.72kb minified and gzipped) and super fast templating framework for JavaScript and node.js.\r\n\r\nIt has [express](http://expressjs.com/) support out-of-the-box.\r\n\r\n## API\r\n\r\nParse templates by passing in a template string and an object representing the data to be parsed.\r\n\r\n```\r\nvar parsed = templates.parse(template, data);\r\n```\r\n\r\n### templates.js client-side\r\n\r\n```\r\n<html>\r\n<head>\r\n\t<script type=\"text/javascript\" src=\"path/to/templates.js\"></script>\r\n</head>\r\n<body>\r\n\t<div id=\"template\">\r\n\t\t<p>{quote.text}</p>\r\n\t\t<strong>{quote.author}</strong>\r\n\t</div>\r\n\r\n\t<script type=\"text/javascript\">\r\n\t\tvar el = document.getElementById('template');\r\n\r\n\t\tel.innerHTML = templates.parse(el.innerHTML, {\r\n\t\t\tquote: {\r\n\t\t\t\ttext: \"Life is really simple, but we insist on making it complicated.\",\r\n\t\t\t\tauthor: \"Confucius\"\r\n\t\t\t}\r\n\t\t});\r\n\t</script>\r\n</body>\r\n</html>\r\n```\r\n\r\n### templates.js and express\r\n\r\n```\r\nvar express = require('express'),\r\n\tapp = express(),\r\n\ttemplates = require('templates.js'),\r\n\tdata = {};\r\n\r\napp.configure(function() {\r\n\tapp.engine('tpl', templates.__express);\r\n\tapp.set('view engine', 'tpl');\r\n\tapp.set('views', 'path/to/templates');\r\n});\r\n\r\napp.render('myview', data, function(err, html) {\r\n\tconsole.log(html);\r\n});\r\n\r\napp.get('/myview', function(res, req, next) {\r\n\tres.render('myview', data);\r\n});\r\n```\r\n\r\n## Template Syntax\r\nSample data, see test cases for more:\r\n\r\n```\r\n{\r\n\t\"animals\": [\r\n\t\t{\r\n\t\t\t\"name\": \"Cat\",\r\n\t\t\t\"species\": \"Felis silvestris catus\",\r\n\t\t\t\"isHuman\": false,\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"name\": \"Dog\",\r\n\t\t\t\"species\": \"Canis lupus familiaris\",\r\n\t\t\t\"isHuman\": false,\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"name\": \"Human\",\r\n\t\t\t\"species\": \"Homo sapiens\",\r\n\t\t\t\"isHuman\": true\r\n\t\t}\r\n\t],\r\n\t\"package\": {\r\n\t\t\"name\": \"templates.js\",\r\n\t\t\"author\": \"psychobunny\",\r\n\t\t\"url\": \"http://www.github.com/psychobunny/templates.js\"\r\n\t},\r\n\t\"website\": \"http://burnaftercompiling.com\",\r\n\t\"sayHello\": true\r\n}\r\n```\r\n\r\n### Simple key/value\r\n```\r\nMy blog URL is {website}. The URL for this library is {package.url}\r\n```\r\n\r\n### Conditionals\r\n```\r\n<!-- IF sayHello -->\r\n Hello world!\r\n<!-- ENDIF sayHello -->\r\n\r\n<!-- IF !somethingFalse -->\r\n somethingFalse doensn't exist\r\n<!-- ENDFIF !somethingFalse -->\r\n```\r\n\r\n### Arrays\r\nRepeat blocks of HTML with an array. The two helpers `@first` and `@last` are also available as conditionals within an array.\r\n\r\n```\r\n<!-- BEGIN animals -->\r\n {animals.name} is from the species {animals.species}.\r\n <!-- IF !animals.isHuman -->\r\n - This could be a pet.\r\n <!-- ENDIF !animals.isHuman -->\r\n<!-- END animals -->\r\n\r\nprints out:\r\n\r\nCat is from the species Felis silvestris catus.\r\n- This could be a pet.\r\nDog is from the Canis lupus familiaris.\r\n- This could be a pet.\r\nHuman is from the species Homo sapiens.\r\n```\r\n\r\n### Helpers\r\n\r\nHelpers are JavaScript methods for advanced logic in templates. This example shows a really simple example of a function called `print_is_human` which will render text depending on the current block's data.\r\n\r\n```\r\ntemplates.registerHelper('print_is_human', function(data, iterator, numblocks) {\r\n\treturn (data.isHuman) ? \"Is human\" : \"Isn't human\";\r\n});\r\n\r\n<!-- BEGIN animals -->\r\n{function.print_is_human}\r\n<!-- END animals -->\r\n\r\nprints out:\r\n\r\nIsn't human\r\nIsn't human\r\nIs human\r\n```\r\n## Installation\r\n\r\n npm install templates.js\r\n\r\n## Testing\r\n\r\n npm install\r\n npm test\r\n\r\n## Projects using templates.js\r\n\r\n[NodeBB](http://www.nodebb.org)\r\n\r\nAdd yours here by submitting a PR :)\r\n",
  41. "readmeFilename": "README.md",
  42. "bugs": {
  43. "url": "https://github.com/psychobunny/templates.js/issues"
  44. },
  45. "_id": "templates.js@0.2.7",
  46. "dist": {
  47. "shasum": "80dc075e5517b0b4b43ca45ba1036e50ef1388d1"
  48. },
  49. "_from": "templates.js@0.2.7",
  50. "_resolved": "https://registry.npmjs.org/templates.js/-/templates.js-0.2.7.tgz"
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement