Skip to content

Instantly share code, notes, and snippets.

@stephenvisser
Created May 26, 2012 17:49
Show Gist options
  • Save stephenvisser/2794767 to your computer and use it in GitHub Desktop.
Save stephenvisser/2794767 to your computer and use it in GitHub Desktop.
Controller-scoped routes using Spine.js
require('spine/lib/manager')
class Main extends Spine.Stack
routes:
'adventure': 'adv'
'home': 'home'
'information': 'info'
controllers:
info: Information
home: Home
adv: Adventure
module.exports = Main
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>App</title>
<link rel="stylesheet" href="/application.css" type="text/css" charset="utf-8">
<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
var NavBar = require("controllers/nav")
var Content = require("controllers/main")
$("body").append(new NavBar());
$("body").append(new Content());
});
</script>
</head>
<body></body>
</html>
class NavBar extends Spine.Controller
elements:
'ul':'buttons'
highlight: (item, highlight) ->
//Change the highlighted menu item to reflect URL state
constructor: ->
super
@html require('views/nav')
@routes
':path': (path) ->
@highlight $(button), path.path for button in @buttons.children()
module.exports = NavBar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment