diff --git a/lib/plugins/sammy.pure.js b/lib/plugins/sammy.pure.js index 09d60553..def30e76 100644 --- a/lib/plugins/sammy.pure.js +++ b/lib/plugins/sammy.pure.js @@ -11,7 +11,9 @@ Sammy.Pure = function(app, method_alias) { var pure = function(template, data, directives) { - return $(template).autoRender(data, directives); + return (typeof(directives) === 'object') ? + $(template).render(data, directives) : + $(template).autoRender(data); }; // set the default method name/extension diff --git a/lib/sammy.js b/lib/sammy.js index 6bbc8ff7..e15de2df 100644 --- a/lib/sammy.js +++ b/lib/sammy.js @@ -20,7 +20,7 @@ return String(s).replace(/&(?!\w+;)/g, '&').replace(//g, '>').replace(/"/g, '"'); }, _routeWrapper = function(verb) { - return function(path, callback) { return this.route.apply(this, [verb, path, callback]); }; + return function(path, callback, exit) { return this.route.apply(this, [verb, path, callback, exit]); }; }, _template_cache = {}, _has_history = !!(window.history && history.pushState), @@ -534,7 +534,7 @@ // It is also possible to pass a string as the callback, which is looked up as the name // of a method on the application. // - route: function(verb, path, callback) { + route: function(verb, path, callback, exit) { var app = this, param_names = [], add_route, path_match; // if the method signature is just (path, callback) @@ -543,6 +543,7 @@ path = verb; callback = path; verb = 'any'; + exit = exit; } verb = verb.toLowerCase(); // ensure verb is lower case @@ -568,7 +569,7 @@ } add_route = function(with_verb) { - var r = {verb: with_verb, path: path, callback: callback, param_names: param_names}; + var r = {verb: with_verb, path: path, callback: callback, param_names: param_names, exit: exit}; // add route to routes array app.routes[with_verb] = app.routes[with_verb] || []; // place routes in order of definition @@ -1047,6 +1048,11 @@ if (returned === false) { return false; } } } + + if(app.last_route && app.last_route.exit) { + app.last_route.exit.apply(context); + } + app.last_route = route; context.trigger('event-context-before', {context: context}); returned = route.callback.apply(context, callback_args); @@ -1524,6 +1530,7 @@ data: {}, dataType: is_json ? 'json' : 'text', type: 'get', + error: function() { console.warn(arguments); }, success: function(data) { if (should_cache) { context.event_context.app.templateCache(location, data);