Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PURE plugin fix & warn on load error #113

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/plugins/sammy.pure.js
Expand Up @@ -11,7 +11,9 @@
Sammy.Pure = function(app, method_alias) { Sammy.Pure = function(app, method_alias) {


var pure = function(template, data, directives) { 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 // set the default method name/extension
Expand Down
13 changes: 10 additions & 3 deletions lib/sammy.js
Expand Up @@ -20,7 +20,7 @@
return String(s).replace(/&(?!\w+;)/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); return String(s).replace(/&(?!\w+;)/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}, },
_routeWrapper = function(verb) { _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 = {}, _template_cache = {},
_has_history = !!(window.history && history.pushState), _has_history = !!(window.history && history.pushState),
Expand Down Expand Up @@ -534,7 +534,7 @@
// It is also possible to pass a string as the callback, which is looked up as the name // It is also possible to pass a string as the callback, which is looked up as the name
// of a method on the application. // 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; var app = this, param_names = [], add_route, path_match;


// if the method signature is just (path, callback) // if the method signature is just (path, callback)
Expand All @@ -543,6 +543,7 @@
path = verb; path = verb;
callback = path; callback = path;
verb = 'any'; verb = 'any';
exit = exit;
} }


verb = verb.toLowerCase(); // ensure verb is lower case verb = verb.toLowerCase(); // ensure verb is lower case
Expand All @@ -568,7 +569,7 @@
} }


add_route = function(with_verb) { 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 // add route to routes array
app.routes[with_verb] = app.routes[with_verb] || []; app.routes[with_verb] = app.routes[with_verb] || [];
// place routes in order of definition // place routes in order of definition
Expand Down Expand Up @@ -1047,6 +1048,11 @@
if (returned === false) { return false; } if (returned === false) { return false; }
} }
} }

if(app.last_route && app.last_route.exit) {
app.last_route.exit.apply(context);
}

app.last_route = route; app.last_route = route;
context.trigger('event-context-before', {context: context}); context.trigger('event-context-before', {context: context});
returned = route.callback.apply(context, callback_args); returned = route.callback.apply(context, callback_args);
Expand Down Expand Up @@ -1524,6 +1530,7 @@
data: {}, data: {},
dataType: is_json ? 'json' : 'text', dataType: is_json ? 'json' : 'text',
type: 'get', type: 'get',
error: function() { console.warn(arguments); },
success: function(data) { success: function(data) {
if (should_cache) { if (should_cache) {
context.event_context.app.templateCache(location, data); context.event_context.app.templateCache(location, data);
Expand Down