Grails for hipsters

28
GRAILS FOR HIPSTERS ROB FLETCHER @rfletcherEW

description

Talk given on 2012-12-13 at Groovy & Grails Exchange, London.

Transcript of Grails for hipsters

Page 1: Grails for hipsters

GRAILS FOR HIPSTERS

ROB FLETCHER@rfletcherEW

Page 2: Grails for hipsters

who am I?

• Associate at Energized Work

• Currently at tv.sky.com

• Author of Betamax & various Grails plugins

• Into Grails before it was mainstream

Page 3: Grails for hipsters

javascript 2006

Page 4: Grails for hipsters

javascript 2012

Page 5: Grails for hipsters

is grails hipster-friendly?

Page 6: Grails for hipsters

enterprise development

Page 7: Grails for hipsters

hipster development

Page 8: Grails for hipsters

demo time…

bit.ly/TWdn1r192.168.1.57:8080

git.io/hipsteroid

Page 9: Grails for hipsters

async processing

Page 10: Grails for hipsters

push data

grails appvert.x bus

Page 11: Grails for hipsters

Grails app

offload expensive workgrails app vert.x app

AJAXHTTPPOST

HTTP202

push JSON

vert.x bus

Page 12: Grails for hipsters

Grails app

AJAXHTTPPOST

HTTP202

one request…n responsesvert.x appgrails app vert.x

bus

Page 13: Grails for hipsters

other options

• Atmosphere / Comet

• Grails events-push plugin

• Grails Servlet 3.0 support

Page 14: Grails for hipsters

front-end tooling

Page 15: Grails for hipsters

not invented here

the philosophy of social, corporate, or institutional cultures that avoid using or buying already existing products, research, standards, or knowledge because of their external origins

Wikipedia

Page 16: Grails for hipsters

build & packaging tools

gruntjs.comyeoman.io

livereload.com

incident57.com/codekittwitter.github.com/bower

brunch.io

jamjs.org

ender.jit.su

Page 17: Grails for hipsters

tl;dr - here’s a list…

github.com/codylindley/frontend-tools

Page 18: Grails for hipsters

codekit demo

LESS

CoffeeScript JavaScript

CSS bundled / cached

bundled / cached

CodeKit Resourcesplugin

Page 19: Grails for hipsters

testing

Page 20: Grails for hipsters

dual-rendering

Page 21: Grails for hipsters

one page app navigation

/ /timeline /pictures/$id /users/$name

http://hipsteroid.coHTMLCSSscript

JSONJSON

JSON

Page 22: Grails for hipsters

deep link: /pictures/$idserves

HTML & JS

app starts & route triggers

fetches data & serves JSON

renders view

template

bookmark or link

renders empty page

Page 23: Grails for hipsters

…with dual renderingserves

HTML & JS

app starts & route triggers

bookmark or link

renders full page

Page 24: Grails for hipsters

mirrored routing

'/' {controller = 'home'

}

'/timeline' {controller = 'pictures'action = 'list'

}

"/pictures/$id" {controller = 'pictures'action = 'show'

}

"/users/$name" {controller = 'user'action = 'show'

}

routes:'/': 'home''timeline': 'timeline''pictures:id': 'picture''users:name': 'profile'

UrlMappings.groovy hipsteroid-router.coffee

Page 25: Grails for hipsters

the handlebars plugin

github.com/davidtinker/grails-handlebars

Page 26: Grails for hipsters

handlebars<h1>Timeline</h1><ul>{{#each .}} <li data-id="{{id}}"> {{> picture}} </li>{{/each}}</ul>

<figure> <img src="{{url}}"> <figcaption> <p>Uploaded {{friendlyTime dateCreated}} by {{uploadedBy.username}}</p> {{#isCurrentUser uploadedBy}} <button type="button" class="delete" title="Delete">Delete</button> {{/isCurrentUser}} </figcaption></figure>

picture.handlebars

timeline.handlebars

Page 27: Grails for hipsters

template re-use

def show(String id) {def picture = Picture.get(id)if (picture) {

render text: handlebars.render(template: 'picture', model: picture

)} else {

response.sendError SC_NOT_FOUND}

}

PicturesController.groovy

class PictureView extends Backbone.View

template: Handlebars.templates.picture

render: ->@$el.html @template(@model.toJSON())

picture-view.coffee

web-app/templates/picture.handlebars

Page 28: Grails for hipsters

thanks

git.io/hipsteroid

@rfletcherEW

@hipsterdevstack

blog.freeside.co

hipsterdevstack.tumblr.com

energizedwork.com