API Docs for: 3.10.3
Show:

File: handlebars/js/yui-handlebars-compiler-after.js

  1. // This file contains YUI-specific wrapper code and overrides for the
  2. // handlebars-compiler module.
  3.  
  4. /**
  5. Handlebars parser and compiler. Use this module when you need to compile
  6. Handlebars templates.
  7.  
  8. @module handlebars
  9. @submodule handlebars-compiler
  10. */
  11.  
  12. var levels = ['debug', 'info', 'warn', 'error'];
  13.  
  14. /**
  15. Logs a debugging message. Note that messages will only be logged when the
  16. handlebars module is loaded in "debug" mode.
  17.  
  18. @method log
  19. @param {String} level Log level for this message. Supported levels are "debug",
  20. "info", "warn", and "error".
  21. @param {String} message Message to log.
  22. @for Handlebars
  23. */
  24. Handlebars.logger.log = function (level, message) {
  25. Y.log(message, levels[level] || 'error', 'Handlebars');
  26. };
  27.  
  28. /**
  29. Compiles and renders a Handlebars template string in a single step.
  30.  
  31. If you'll be using a template more than once, it's more efficient to compile it
  32. into a function once using `compile()`, and then render it whenever you need to
  33. by simply executing the compiled function. However, if you only need to compile
  34. and render a template once, `render()` is a handy shortcut for doing both in a
  35. single step.
  36.  
  37. @example
  38.  
  39. Y.Handlebars.render('The pie of the day is {{pie}}!', {
  40. pie: 'Maple Custard'
  41. });
  42. // => "The pie of the day is Maple Custard!"
  43.  
  44. @method render
  45. @param {String} string Handlebars template string to render.
  46. @param {Object} context Context object to pass to the template.
  47. @param {Object} [options] Compile/render options.
  48. @param {Object} [options.helpers] Helper functions.
  49. @param {Object} [options.partials] Partials.
  50. @param {Object} [options.data] Data.
  51. @return {String} Rendered template string.
  52. */
  53. Handlebars.render = function (string, context, options) {
  54. return Handlebars.compile(string)(context, options);
  55. };
  56.  
  57. // The rest of this file is just API docs for methods defined in Handlebars
  58. // itself.
  59.  
  60. /**
  61. Compiles a Handlebars template string into a function. To render the template,
  62. call the function and pass in a context object.
  63.  
  64. @example
  65.  
  66. var template = Y.Handlebars.compile('The pie of the day is {{pie}}!.');
  67. template({pie: 'Pecan'});
  68. // => "The pie of the day is Pecan!"
  69.  
  70. @method compile
  71. @param {String} string Handlebars template string to compile.
  72. @param {Object} [options] Compiler options.
  73. @return {Function} Compiled template function.
  74. */
  75.  
  76. /**
  77. Precompiles a Handlebars template string into a string of JavaScript code. This
  78. can be used to precompile a template at build time or on the server, and the
  79. resulting template can then be rendered at runtime or on the client without
  80. needing to go through a compile step.
  81.  
  82. To render a precompiled template, evaluate the code and then pass the resulting
  83. function to `Y.Handlebars.template()` to get back an executable template
  84. function.
  85.  
  86. @method precompile
  87. @param {String} string Handlebars template string to compile.
  88. @param {Object} [options] Compiler options.
  89. @return {String} Precompiled template code.
  90. */
  91.