html5 with play scala, coffeescript and jade - jfokus 2012

111
Photos by Trish - http://mcginityphoto.com with Play Scala, CoffeeScript and Jade Matt Raible http://raibledesigns.com

Upload: matt-raible

Post on 12-May-2015

48.349 views

Category:

Technology


0 download

DESCRIPTION

HTML5 Development with Play Scala, CoffeeScript and Jade Presentation from Jfokus 2012. Discusses these technologies, as well as my story of using them to develop an HTML5 Fitness Tracking application. Read more about this presentation at: http://raibledesigns.com/rd/entry/comparing_web_frameworks_and_html5

TRANSCRIPT

Page 1: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

Photos by Trish - http://mcginityphoto.com

with Play Scala, CoffeeScript and Jade

Matt Raiblehttp://raibledesigns.com

Page 2: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Introductions

‣ Have you used HTML5?‣ Have you used Play

Framework?‣ Have you tried Scala?‣ Tried CoffeeScript?‣ Scalate or Jade?

2

Page 3: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Blogger on raibledesigns.com

Founder of AppFuse

Father, Skier, Cyclist

Web Framework Connoisseur

Who is Matt Raible?

Page 4: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Agenda

4

‣ Introductions‣ Why am I doing this talk?‣ What are these technologies?‣ My Development Experience‣ Demo‣ Q and A‣ Conclusion

Page 5: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

5

Page 6: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

6

http://www.flickr.com/photos/question_everything/2931013045/

Page 7: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

7

Page 8: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

8

‣ I like a Challenge to...- Learn Scala

- Via Play!

- And Jade is cool too!

- So is CoffeeScript!

Page 9: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

9

‣ Honestly, it’s because of James Strachan...

Page 10: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

10

‣ Who likes beer too!

Page 11: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Why am I doing this talk?

11

Page 12: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

What are these technologies?

12

Page 13: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5

13http://on.wsj.com/tEGIJL

Page 14: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

How do you write HTML5?

<!DOCTYPE html>

14

<article> <aside> <section><header> <footer> <nav><audio> <canvas> <video><datalist> <details>

http://www.w3schools.com/html5/html5_reference.asp

<applet> <center> <font><frame> <frameset>

Page 15: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CSS3

‣ Animated Transitions‣ Rounded Corners‣ Drop Shadows‣ Gradient Colors‣ Styling based on sibling count‣ More cursors for better usability‣ Custom Checkboxes and Radio Buttons

15

http://lea.verou.me/css3-secrets

transform: rotateY(180deg);

border-radius: 8px 8px 0 0;

box-shadow: 2px 2px 4px 4px;

Page 16: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play Framework

‣ A full-stack Java Web Framework made by Web Developers

‣ Compile on-the-fly‣ Stateless Architecture‣ Breaks web framework norms

- Uses static methods

- Doesn’t use Servlet API

16

Page 17: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Matrix Results

0

4.5

9

13.5

18Gr

ails

Sprin

gRa

ilsGW

TVa

adin

Wick

etTa

pestr

ySt

ruts

2St

ripes Play

Flex

JSF Lift

11.513.513.5141414.5151515.5

17171717.5

17

Page 18: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Weighted Results

‣ Grails (90)‣ Spring MVC (85)‣ Ruby on Rails (82.5)‣ Vaadin (82.5)‣ Play (82.5)‣ GWT (80)

18

Page 19: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Mailing List Traffic

Wicket

GWT

Grails

Rails

Tapestry

Play

0 475 950 1425 1900

1451

1538

1604

1635

1753

1841

July 2011* Spring MVC and Vaadin use Forums, which don’t provide this data.

19

Page 20: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play Scala

20

But really, it’s more like this

Page 21: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play Scala

21

Page 22: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scala

“Scala is like the dragon in Avatar. It will try to kill you, but if you master it, you can fly great distances

with it and have a wonderful time.”

-- Venkat Subramaniam

22

Page 23: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scala Basics‣ def starts a method

‣ variables are started with var or val‣ variables are defined with name:type ‣ semicolons are not required

23

Page 24: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scala vs. Java

24

Page 25: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play with Scala

25

Page 26: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Learning Scala

‣ Venkat’s Scala for the Intrigued- PragPub Magazine, starting in Sep 2011

‣ Scala for the Impatient - Cay Horstmann‣ Programming in Scala, 2nd Edition - Martin

Odersky, Lex Spoon, and Bill Venners‣ Twitter’s Scala School

26

Page 27: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CoffeeScript

27

Page 28: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

JavaScript: The Good Parts

28

Page 29: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Jade

29

Page 30: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Jade Example

30

Page 31: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CoffeeBar

31

Page 32: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

My Development Experience

32

Page 33: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Getting Started

33

Page 34: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Developing with Play Scala

34

Page 35: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Tools I started with...

35

Page 36: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scalate Module

36

Page 37: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scalate Integration Solution

37

Page 38: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Integrating Scalate with Play

38

play deps --sync

Page 39: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Integrating Scalate with Play

39

Page 40: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Integrating Scalate with Play

40

Page 41: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Cannot start in PROD mode with errors Template compilation error (In /app/views/Application/index.jade around line 2) The template /app/views/Application/index.jade does not compile : #{user.name} is not closed. play.exceptions.TemplateCompilationException: #{user.name} is not closed. at play.templates.TemplateCompiler.generate(TemplateCompiler.java:102) at play.templates.TemplateCompiler.compile(TemplateCompiler.java:15) at play.templates.GroovyTemplateCompiler.compile(GroovyTemplateCompiler.java:4 1)

Page 42: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Integrating Scalate with Play

42

http://raibledesigns.com/rd/entry/integrating_scalate_and_jade_with

Page 43: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play 2.0

43

Page 44: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play 2.0

44

Page 45: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play 2.0

45

Page 46: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play 2.0 Beta

46

http://raibledesigns.com/rd/entry/play_2_0_a_web

Page 48: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CoffeeScript with Play

48

Page 49: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CoffeeScript with Play

49

http://raibledesigns.com/rd/entry/trying_to_make_coffeescript_work

Page 50: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

My Development Experience

50

Page 51: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Page 52: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

H5BP and Play

52

cd $boilerplate-downloadcp 404.html ~/dev/play-more/app/views/errors/404.htmlcp *.png ~/dev/play-more/public/.cp crossdomain.xml ~/dev/play-more/public/.cp -r css ~/dev/play-more/public/stylesheets/.cp favicon.ico ~/dev/play-more/public/.cp humans.txt ~/dev/play-more/public/.cp -r js/libs ~/dev/play-more/public/javascripts/.cp robots.txt ~/dev/play-more/public/.

Page 53: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scalate Layouts

53

Page 54: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Boilerplate

54

http://raibledesigns.com/rd/entry/integrating_html5_boilerplate_with_scalate

Page 55: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Development

55

Page 56: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

StopWatch with Coffee

56

Page 57: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Jade Template for Watch

57

Page 58: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Development

58

Page 59: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Geo API

59

Page 60: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Google Maps JS API

60

Page 61: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Jade View for Map

61

Page 62: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Development

62

Page 63: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Odometer

63

Page 64: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Testing

64

‣ Tried Trip Meter on a bike ride‣ Said I’d traveled 5 km, when I knew I’d gone 10

- Was calculating start to end w/o waypoints

‣ To Visualize: integrated odometer with maps using Google Maps Polylines

Page 65: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Discovered

65

‣ HTML5 Geolocation was highly inaccurate- Fixed by passing {enableHighAccuracy: true} to

navigator.geolocation.watchPosition()

Page 66: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Discovered

66

Page 67: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Show Stopper?

67

‣ Geolocation doesn’t run in the background

Page 68: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Making it look good

68

Page 69: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Twitter’s Bootstrap

69

Page 70: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Bootstrap

70

Page 71: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

LESS

71

Page 72: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

LESS

72

Page 73: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

CSS3 Media Queries

73

Page 74: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 Features

‣ Geolocation‣ CSS 3‣ Audio‣ History‣ Local Storage‣ Canvas

74

Page 75: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 and Bootstrap

75

http://raibledesigns.com/rd/entry/developing_with_html5_coffeescript_and

Page 76: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Anorm and PostgreSQL

76

‣ I’m a big fan of ORMs like Hibernate and JPA- Learn a new JDBC abstraction? Really!?

‣ Anorm is and will be the default for Play Scala‣ Chose PostgreSQL since that’s what Heroku uses

Page 77: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Data Model

77

Page 78: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

ScalaTest

78

Page 79: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Anorm in Action

79

Page 80: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Controller and View

80

Page 81: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Anorm, Dates & PostgreSQL

81

Page 82: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

‣ Discovered “support of Date for insertion” was added to Anorm in August 2011

‣ Cloned play-scala, built locally and uploaded‣ Modified dependencies.yml to use new version

Anorm, Dates & PostgreSQL

82

Page 83: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Anorm and PostgreSQL

83

http://raibledesigns.com/rd/entry/play_scala_s_anorm_heroku

Page 84: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

More Scalate Goodness

84

Page 85: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

More Scalate Goodness

85

Page 86: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

More Scalate Goodness

86

Page 87: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Scalate as a Play Module

87

http://raibledesigns.com/rd/entry/more_scalate_goodness_for_play

Page 88: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

App was still unusable‣ I still hadn’t solved the fundamental problem‣ The app couldn’t run in the background on a

mobile phone

88

Page 89: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

PhoneGap to the Rescue!

89

Page 90: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Requirements

90

‣ Intel-based computer with Mac OS X Snow Leopard (10.6)

‣ Xcode‣ PhoneGap‣ Necessary for Installation:

- An Apple iOS Device

- iOS Developer Certification

Page 91: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Icons and Splash Screen

91

Page 92: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Background Modes

92

Page 93: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Success!

93

Page 94: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

PhoneGap Writeup

94

http://raibledesigns.com/rd/entry/phonegap_to_the_rescue

Page 95: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Was it worth it?

‣ Development Hours: $$$‣ play-more.com domain: $180‣ GoPro Helmet Cam: $239‣ iOS Certified Developer: $100‣ Free Trip to Devoxx: Priceless

95

Page 96: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Was it worth it?

‣ Development Hours: $$$‣ play-more.com domain: $180‣ GoPro Helmet Cam: $239‣ iOS Certified Developer: $100‣ Free Trip to Jfokus: Awesome!

96

Page 97: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Since Devoxx

‣ Tried to upgrade to Play 2.0‣ Integrated RESTful Services‣ Integrated Secure Social for

Authentication‣ Added ability to save, edit

and delete workouts

97

Page 98: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Upgrading to Play 2.0

98

Page 99: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Upgrading to Play 2.0

99

“If it's a critical project, to be finished before next March 2012, I would go with Play 1.x.”

Page 100: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

JSON Services

100

Page 101: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

API Tests

101

Page 102: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Secure Social

102

Page 103: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Secure Social

103

Page 104: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Secure Social

104

http://raibledesigns.com/rd/entry/secure_json_services_with_play

Page 105: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Developing Play More

105

http://vimeo.com/36826202

Page 106: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Tools

106

Page 107: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Lessons Learned

‣ Develop Mobile Client first‣ Develop Web Client as a one-

page app‣ Don’t rely on the internet for

mobile‣ Keep static assets local for

faster startup‣ Bleeding edge can be painful

107

Page 108: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Or, What Rich Said...

108

Page 109: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

HTML5 vs. Native‣ If you need background services like geolocation

or audio, native is necessary‣ Can still write your apps in HTML5

- Bridge the Gap with PhoneGap or Titanium

‣ If mobile is important, consider fully native with WebViews for common features - a.k.a. Hybrid

109

Page 110: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Questions?

Contact- http://raibledesigns.com

- @mraible

Download- http://slideshare.net/mraible

110

Page 111: HTML5 with Play Scala, CoffeeScript and Jade - Jfokus 2012

© 2012 Raible Designs

Play More!‣ Learn Something New‣ Have Fun‣ Get out there and Play!

111