Skip to content

Commit

Permalink
adding a few more technology stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Apr 29, 2012
1 parent 848bfda commit ad40039
Show file tree
Hide file tree
Showing 70 changed files with 5,444 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
@@ -1,6 +1,6 @@
#Backbone Boilerplates

Developers have been reqesting examples of how to integrate Backbone.js with a number of different technology stacks. Two common requests have included Node.js and Sinatra/Ruby but there have been a number of others too. To help with this, you can find three of these integration examples below. There are more to come soon.
Developers have been reqesting examples of how to integrate Backbone.js with a number of different backend technology stacks. To help with this, you can find six of these integration examples in this repository, with their stacks listed below. There are more to come soon and I'm always happy to consider other stacks not already covered.

Option 1
=========
Expand All @@ -24,6 +24,28 @@ Option 3
* Sinatra
* MongoDB

Option 4
==========
* Grails
* MongoDB

(thanks to [Lauri Piispanen](https://github.com/lauripiispanen))

Option 5
==========
* PHP
* Slim PHP RESTful framework
* mySQL

(thanks to [Joshua Stauter](https://github.com/dthtvwls))

Option 6
==========
* Rails / Rails Asset Pipeline
* CoffeeScript
* Rails JSON API

(also thanks to [Joshua Stauter](https://github.com/dthtvwls))

##Instructions

Expand Down
1 change: 1 addition & 0 deletions option4_grails_mongo/README
@@ -0,0 +1 @@
Example to accompany blog post: http://lauripiispanen.github.com/blog/2012/01/31/building-a-backend-for-backbone-dot-js-todos-example-with-grails-and-mongodb/
7 changes: 7 additions & 0 deletions option4_grails_mongo/application.properties
@@ -0,0 +1,7 @@
#Grails Metadata file
#Wed Jan 25 16:27:14 EET 2012
app.grails.version=2.0.0
app.name=todo
app.servlet.version=2.5
app.version=0.1
plugins.mongodb=1.0.0.RC3
@@ -0,0 +1,5 @@
modules = {
application {
resource url:'js/application.js'
}
}
7 changes: 7 additions & 0 deletions option4_grails_mongo/grails-app/conf/BootStrap.groovy
@@ -0,0 +1,7 @@
class BootStrap {

def init = { servletContext ->
}
def destroy = {
}
}
46 changes: 46 additions & 0 deletions option4_grails_mongo/grails-app/conf/BuildConfig.groovy
@@ -0,0 +1,46 @@
grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve

repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()

// uncomment these to enable remote dependency resolution from public Maven repositories
//mavenCentral()
//mavenLocal()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.16'
}

plugins {
runtime ":mongodb:latest.integration"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.5"

build ":tomcat:$grailsVersion"
}
}
94 changes: 94 additions & 0 deletions option4_grails_mongo/grails-app/conf/Config.groovy
@@ -0,0 +1,94 @@
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties",
// "file:${userHome}/.grails/${appName}-config.groovy"]

// if (System.properties["${appName}.config.location"]) {
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }


grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
xml: ['text/xml', 'application/xml'],
text: 'text/plain',
js: 'text/javascript',
rss: 'application/rss+xml',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
all: '*/*',
json: ['application/json','text/json'],
form: 'application/x-www-form-urlencoded',
multipartForm: 'multipart/form-data'
]

// URL Mapping Cache Max Size, defaults to 5000
//grails.urlmapping.cache.maxsize = 1000

// What URL patterns should be processed by the resources plugin
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']

grails.app.context="/"

// The default codec used to encode data with ${}
grails.views.default.codec = "none" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
// enable Sitemesh preprocessing of GSP pages
grails.views.gsp.sitemesh.preprocess = true
// scaffolding templates configuration
grails.scaffolding.templates.domainSuffix = 'Instance'

// Set to false to use the new Grails 1.2 JSONBuilder in the render method
grails.json.legacy.builder = false
// enabled native2ascii conversion of i18n properties files
grails.enable.native2ascii = true
// packages to include in Spring bean scanning
grails.spring.bean.packages = []
// whether to disable processing of multi part requests
grails.web.disable.multipart=false

// request parameters to mask when logging exceptions
grails.exceptionresolver.params.exclude = ['password']

// enable query caching by default
grails.hibernate.cache.queries = true

// set per-environment serverURL stem for creating absolute links
environments {
development {
grails.logging.jul.usebridge = true
}
production {
grails.logging.jul.usebridge = false
// TODO: grails.serverURL = "http://www.changeme.com"
}
}

// log4j configuration
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}
14 changes: 14 additions & 0 deletions option4_grails_mongo/grails-app/conf/TodoResources.groovy
@@ -0,0 +1,14 @@
modules = {
todo {
dependsOn 'jquery, underscore, backbone'

resource url: '/todos.css'
resource url: '/todos.js'
}
backbone {
resource url: '/backbone.js'
}
underscore {
resource url: '/underscore.js'
}
}
17 changes: 17 additions & 0 deletions option4_grails_mongo/grails-app/conf/UrlMappings.groovy
@@ -0,0 +1,17 @@
class UrlMappings {

static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}

"/todos/$id?"(controller: "todos") {
action = [GET:"list", POST: "save", DELETE: "delete", PUT: "edit"]
}

"/"(view:"/index")
"500"(view:'/error')
}
}
3 changes: 3 additions & 0 deletions option4_grails_mongo/grails-app/conf/spring/resources.groovy
@@ -0,0 +1,3 @@
// Place your Spring DSL code here
beans = {
}
@@ -0,0 +1,27 @@
package todo

import grails.converters.JSON

class TodosController {

def index() {
render( Todo.findAll() as JSON )
}

def save() {
def todo = new Todo(request.JSON);
render( todo.save() as JSON )
}

def delete() {
def todo = Todo.findById(params.id)
todo?.delete()
render(todo as JSON );
}

def edit() {
def todo = Todo.findById(params.id)
bindData(todo, request.JSON)
render(todo.save() as JSON )
}
}
12 changes: 12 additions & 0 deletions option4_grails_mongo/grails-app/domain/todo/Todo.groovy
@@ -0,0 +1,12 @@
package todo

class Todo {

boolean done
int order
String text

static constraints = {
text(nullable: false, empty: false)
}
}
11 changes: 11 additions & 0 deletions option4_grails_mongo/grails-app/views/error.gsp
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Grails Runtime Exception</title>
<meta name="layout" content="main">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
</head>
<body>
<g:renderException exception="${exception}" />
</body>
</html>
82 changes: 82 additions & 0 deletions option4_grails_mongo/grails-app/views/index.gsp
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>

<head>
<title>Backbone Demo: Todos</title>
<r:require module="todo" />
<meta name="layout" content="main">
</head>

<body>

<!-- Todo App Interface -->

<div id="todoapp">

<div class="title">
<h1>Todos</h1>
</div>

<div class="content">

<div id="create-todo">
<input id="new-todo" placeholder="What needs to be done?" type="text" />
<span class="ui-tooltip-top" style="display:none;">Press Enter to save this task</span>
</div>

<div id="todos">
<ul id="todo-list"></ul>
</div>

<div id="todo-stats"></div>

</div>

</div>

<ul id="instructions">
<li>Double-click to edit a todo.</li>
<li><a href="../../docs/todos.html">View the annotated source.</a></li>
</ul>

<div id="credits">
Created by
<br />
<a href="http://jgn.me/">J&eacute;r&ocirc;me Gravel-Niquet</a>
</div>

<!-- Templates -->

<script type="text/template" id="item-template">
<div class="todo {{ done ? 'done' : '' }}">
<div class="display">
<input class="check" type="checkbox" {{ done ? 'checked="checked"' : '' }} />
<div class="todo-text"></div>
<span class="todo-destroy"></span>
</div>
<div class="edit">
<input class="todo-input" type="text" value="" />
</div>
</div>
</script>

<script type="text/template" id="stats-template">
{! if (total) { !}
<span class="todo-count">
<span class="number">{{ remaining }}</span>
<span class="word">{{ remaining == 1 ? 'item' : 'items' }}</span> left.
</span>
{! } !}
{! if (done) { !}
<span class="todo-clear">
<a href="#">
Clear <span class="number-done">{{ done }}</span>
completed <span class="word-done">{{ done == 1 ? 'item' : 'items' }}</span>
</a>
</span>
{! } !}
</script>

</body>

</html>
12 changes: 12 additions & 0 deletions option4_grails_mongo/grails-app/views/layouts/main.gsp
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<title><g:layoutTitle default="Grails"/></title>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<g:layoutBody/>
<r:layoutResources />
</body>
</html>

0 comments on commit ad40039

Please sign in to comment.