Skip to content

Instantly share code, notes, and snippets.

@michaelgodshall
Created August 1, 2012 15:25
Show Gist options
  • Save michaelgodshall/3227795 to your computer and use it in GitHub Desktop.
Save michaelgodshall/3227795 to your computer and use it in GitHub Desktop.
Batman.js Example
class App extends Batman.App
@root 'students#index'
# Make App available in the global namespace so it can be used
# as a namespace and bound to in views.
window.App = App
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script src="/batman/coffee-script.js" type="text/javascript"></script>
<script src="/batman/es5-shim.js" type="text/javascript"></script>
<script src="/batman/dist/batman.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<script src="controllers/application_controller.js" type="text/javascript"></script>
<script src="controllers/students.js" type="text/javascript"></script>
</head>
<body>
<div data-yield="main"></div>
<div data-defineview="students/index">
<button data-event-click="create">
New Student
</button>
</div>
</div>
<script type="text/javascript">
App.run();
</script>
</body>
</html>
class App.Student extends Batman.Model
@resourceName: 'student'
@storageKey: 'students'
@persist Batman.LocalStorage
@encode 'first_name', 'last_name', 'email'
class App.StudentsController extends App.ApplicationController
routingKey: 'students'
index: (params) ->
console.log 'Ready!'
create: (params) ->
newStudent = new App.Student(first_name: 'First', last_name: 'Last', email: '')
newStudent.save()
console.log 'Created', newStudent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment