Permalink
Browse files

router subscriber

  • Loading branch information...
1 parent 3cc7299 commit 79eb10976b7075382680cb7cc49fcc2e27223b2e @tdreyno tdreyno committed Aug 31, 2010
@@ -1,11 +1,11 @@
steal.plugins("jquery",
"jquery/class",
"jquery/controller/history",
- "jquery/lang/openajax")
- .then("sherpa")
+ "jquery/lang/openajax",
+ "ss/router/sherpa")
.then(function($) {
- $.Class.extend("SS.Router",
+ $.Class.extend("SS.Router.Controller",
{
currentParams: {},
URLPrefix: null,
View
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../../../funcunit/qunit/qunit.css" />
+ <title>QUnit Test</title>
+ <style>
+ body {
+ margin: 0px; padding: 0px;
+ }
+ </style>
+ <!--[if IE]>
+ <script type='text/javascript'
+ src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
+ <![endif]-->
+ <script type='text/javascript'>
+ steal = {ignoreControllers: true}
+ </script>
+ <script type='text/javascript' src='../../../steal/steal.js?steal[app]=ss/router/controller/test/qunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">router Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <div id="test-content"></div>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-test-area"></div>
+ </body>
+</html>
@@ -0,0 +1,5 @@
+steal
+ .plugins("jquery/controller") //load your app
+ .plugins("ss/router/controller") //load your app
+ .plugins("funcunit/qunit") //load qunit
+ .then("controller_test")
@@ -1,6 +1,6 @@
<html>
<head>
- <link rel="stylesheet" type="text/css" href="../../funcunit/qunit/qunit.css" />
+ <link rel="stylesheet" type="text/css" href="../../../funcunit/qunit/qunit.css" />
<title>QUnit Test</title>
<style>
body {
@@ -14,7 +14,7 @@
<script type='text/javascript'>
steal = {ignoreControllers: true}
</script>
- <script type='text/javascript' src='../../steal/steal.js?steal[app]=ss/router/test/qunit'></script>
+ <script type='text/javascript' src='../../../steal/steal.js?steal[app]=ss/router/sherpa/test/qunit'></script>
</head>
<body>
File renamed without changes.
@@ -1,6 +1,5 @@
steal
.plugins("jquery/controller") //load your app
- .plugins("ss/router") //load your app
+ .plugins("ss/router/sherpa") //load your app
.plugins("funcunit/qunit") //load qunit
.then("sherpa_test")
- .then("router_test")
@@ -1,5 +1,6 @@
module("Sherpa Router");
+var Router = new Sherpa.Router();
Router.add("/path").to("basic");
Router.add("/withvariable/:something").to("with_var");
Router.add("/withmatch/:something", { matchesWith: { something: /\d+/ } }).to("with_match");
View
@@ -0,0 +1,25 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../../../funcunit/qunit/qunit.css" />
+ <title>QUnit Test</title>
+ <style>
+ body {
+ margin: 0px; padding: 0px;
+ }
+ </style>
+ <script type='text/javascript'>
+ steal = {ignoreControllers: true}
+ </script>
+ <script type='text/javascript' src='../../../steal/steal.js?steal[app]=ss/router/subscribe/test/qunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">router subscribe Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <div id="test-content"></div>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-test-area"></div>
+ </body>
+</html>
View
@@ -0,0 +1,41 @@
+steal.plugins("jquery/controller",
+ "jquery/controller/history",
+ "jquery/lang/openajax",
+ "ss/router/sherpa")
+ .then(function($) {
+
+ var SubscriberRouter = new Sherpa.Router();
+ var RouteToCallback = {};
+
+ OpenAjax.hub.subscribe("history.**", function(event_name) {
+ var key = event_name.replace(/^history(\.*)/, '/'),
+ foundRoute = SubscriberRouter.recognize(key)
+ if (!foundRoute) {
+ return;
+ }
+
+ var callbacks = RouteToCallback[foundRoute.destination];
+ if (callbacks) {
+ for (var i = 0; i < callbacks.length; i++) {
+ callbacks[i]();
+ }
+ }
+ });
+
+ $.Controller.processors.route = function( el, event, selector, cb, controller ) {
+ // Add the selector to be watched
+ SubscriberRouter.add(selector).to(selector);
+
+ // Create an array of callbacks for this selector
+ if (typeof RouteToCallback[selector] === "undefined") {
+ RouteToCallback[selector] = [];
+ }
+
+ // Add callback to this array
+ RouteToCallback[selector].push(cb);
+
+ return function() {
+ //console.debug("route unsubscribe", arguments);
+ }
+ };
+})
@@ -0,0 +1,24 @@
+module("Router Processor Controller");
+
+var didRun = false;
+
+$.Controller.extend("TestProcessorsController",
+{
+ onDocument: true
+},
+{
+ "/test/url route": function() {
+ didRun = true;
+ }
+});
+
+asyncTest("Works", function() {
+ expect(1)
+ stop();
+ location.hash = "/test/url";
+ setTimeout(function() {
+ start();
+ ok(didRun, "Route worked");
+ location.hash = "/";
+ }, 50);
+});
@@ -0,0 +1,5 @@
+steal
+ .plugins("jquery/controller") //load your app
+ .plugins("ss/router/subscribe") //load your app
+ .plugins("funcunit/qunit") //load qunit
+ .then("processor_test")

0 comments on commit 79eb109

Please sign in to comment.