full.js 832 B

12345678910111213141516171819202122232425262728293031323334
  1. /*<TMODJS> <build:'<:build:>'> '<:debug:>'*/
  2. '<:engine:>'
  3. !function (global, template) {
  4. var get = template.get;
  5. var helpers = template.helpers;
  6. var resolve = function(from, to) {
  7. var DOUBLE_DOT_RE = /(\/)[^/]+\1\.\.\1/;
  8. var dirname = from.replace(/^([^.])/, './$1').replace(/[^/]+$/, "");
  9. var id = dirname + to;
  10. id = id.replace(/\/\.\//g, "/");
  11. while (id.match(DOUBLE_DOT_RE)) {
  12. id = id.replace(DOUBLE_DOT_RE, "/");
  13. }
  14. return id;
  15. };
  16. helpers.$include = function (path, data, from) {
  17. var id = resolve(from, path);
  18. return template.render(id, data);
  19. };
  20. template.get = function (id) {
  21. return get(id.replace(/^\.\//, ''));
  22. };
  23. '<:syntax:>'
  24. '<:helpers:>'
  25. '<:templates:>'
  26. }(this, this.template);