Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

33 linhas
1.0KB

  1. $.mustache = function (template, view, partials) {
  2. return Mustache.render(template, view, partials);
  3. };
  4. var methods = {
  5. init: function(view, partials) {
  6. return $(this).map(function (i, elm) {
  7. var template = $.trim($(elm).html());
  8. var output = $.mustache(template, view, partials);
  9. return $(output).get();
  10. });
  11. },
  12. //var compiledTemplate = $('#template').mustache('compile');
  13. compile: function() {
  14. var template = $.trim(this.html());
  15. return Mustache.compile(template);
  16. },
  17. //$('#template').mustache('compilePartial', 'partial-name');
  18. compilePartial: function(name) {
  19. var template = $.trim(this.html());
  20. Mustache.compilePartial(name, template);
  21. return this;
  22. }
  23. };
  24. $.fn.mustache = function (method) {
  25. if ( methods[method] ) {
  26. return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  27. } else if ( typeof method === 'object' || ! method ) {
  28. return methods.init.apply( this, arguments );
  29. }
  30. };
  31. })(jQuery);