SlideShare a Scribd company logo
1 of 26
End-to-End
  CoffeeScript
Presented by Trevor Burnham
     at RailsConf 2011
Part I
CoffeeScript!?!?
What is CoffeeScript?
Do you have to use it?
But seriously...
Things I’ll cover today:

A brief primer on the CoffeeScript language
How it works with the Rails 3.1 asset
pipeline
Running the same JS/CS code on both the
client and the server
And things I won’t:

The CoffeeScript language in depth (that
would take a whole book... available at
http://coffeescript-book.com)
Sprockets 2 (#=
require
foo)

jQuery UJS ($.rails)
CoffeeScript crash course



 “Dash rocket” instead of function

 Semantic whitespace instead of {}

 Implicit parentheses, implicit var scoping
Awesome goodies for
      Rubyists


Postfix if/unless

Implicit returns

String interpolations
Things that feel weird to
        Rubyists



Parentheses are not optional on functions
with no arguments
It’s just JavaScript™
Things that feel weird to
     JavaScripters


CoffeeScript’s of is JavaScript’s in

CoffeeScript’s in is Python’s in

CoffeeScript’s == is JavaScript’s ===
Tradeoffs

Debugging (will get better, but currently
kind of a pain)
Changing versions (though it’s been
pretty stable for the last 5 months)
Less documentation (but there is a
book from PragProg...)
Even so!

After only a week of using CoffeeScript,
I felt more productive than I ever had in
JavaScript.
The community is awesome.
Learning CoffeeScript might make you think
more deeply about JavaScript.
Part II
CoffeeScript in Rails 3.1
Let’s make a Rails app!

rails
new
EndToEnd
cd
EndToEnd
rails
generate
controller
User
signup

Clone the repo if you want to follow along...
http://github.com/TrevorBurnham/EndToEnd)
JavaScripts are assets
New in Rails 3.1, generate
controller gives
us a CoffeeScript file automatically:
Compound extensions

.html.erb & .html.haml → HTML

.css.scss & .css.sass → CSS

.js.coffee → JavaScript

Want to use a different format? Just rename!
application.js → application.js.coffee
Compound extensions
Stylesheets and JavaScripts are automatically
concatenated by Sprockets 2, even in development:




All the CSS and JS is loaded on every page, so it’s
still up to you to isolate controller-specific
functionality.
Building a sign-up box
Adding JS validations
Great, but...
Client-side validations are just there to
provide a friendlier user experience. What
really matters are server-side validations.
Traditionally, we’d do this by using
ActiveRecord, repeating much of the work
we just did...
But there’s another way!
Server-side JavaScript!
  (And CoffeeScript)
If you’ve got coffee‐script in your
Gemfile, then you’ve already got ExecJS:
https://github.com/sstephenson/execjs
It uses the best available JS environment on
your system. Use therubyracer (or
therubyracer‐heroku) for maximum
portability.
No need to rewrite the
 same validation code!
ExecJS lets us turn our CoffeeScript
validation code into a Ruby object:
A small taste of
       what’s to come
Future plugins will make the server-side JS
process smoother in Rails
With jsdom, you can do practically anything
that you could do with client-side JS
(including manipulating HTML with jQuery!)
Validation, templating... anything you’re
duplicating can be done as end-to-end JS.
How can you become a
  CoffeeScript ninja?
Official site, great overview:
http://coffeescript.org
Nice screencast:
http://peepcode.com/products/coffeescript
Totally unbiased book recommendation:
http://coffeescript-book.com
Thanks
        Questions?
trevorburnham@gmail.com

More Related Content

What's hot

Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009pratiknaik
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails IntroductionThomas Fuchs
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e RubyFabio Kung
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumberBachue Zhou
 
Drupal + selenium
Drupal + seleniumDrupal + selenium
Drupal + seleniumhernanibf
 
JSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic AppsJSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic AppsSpike Brehm
 
Bundler is the Best
Bundler is the BestBundler is the Best
Bundler is the Bestdead_arm
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsJohn Anderson
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014ryanstout
 
The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)Andrea Tino
 
Let's talk ChatOps - Hubot with less CoffeeScript
Let's talk ChatOps - Hubot with less CoffeeScriptLet's talk ChatOps - Hubot with less CoffeeScript
Let's talk ChatOps - Hubot with less CoffeeScriptSarahKowalik
 
Puppet at Pinterest
Puppet at PinterestPuppet at Pinterest
Puppet at PinterestPuppet
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application ServersLin Jen-Shin
 
Deploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationDeploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationBen Limmer
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRubyBen Hall
 

What's hot (20)

Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
Drupal + selenium
Drupal + seleniumDrupal + selenium
Drupal + selenium
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
 
JSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic AppsJSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic Apps
 
Bundler is the Best
Bundler is the BestBundler is the Best
Bundler is the Best
 
CouchApp - Build scalable web applications and relax
CouchApp - Build scalable web applications and relaxCouchApp - Build scalable web applications and relax
CouchApp - Build scalable web applications and relax
 
Ansible 202 - sysarmy
Ansible 202 - sysarmyAnsible 202 - sysarmy
Ansible 202 - sysarmy
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014
 
The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)
 
Let's talk ChatOps - Hubot with less CoffeeScript
Let's talk ChatOps - Hubot with less CoffeeScriptLet's talk ChatOps - Hubot with less CoffeeScript
Let's talk ChatOps - Hubot with less CoffeeScript
 
Puppet at Pinterest
Puppet at PinterestPuppet at Pinterest
Puppet at Pinterest
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application Servers
 
Vidoop CouchDB Talk
Vidoop CouchDB TalkVidoop CouchDB Talk
Vidoop CouchDB Talk
 
Volt 2015
Volt 2015Volt 2015
Volt 2015
 
Deploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationDeploying a Location-Aware Ember Application
Deploying a Location-Aware Ember Application
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRuby
 

Viewers also liked

E field disk
E field diskE field disk
E field diskFFMdeMul
 
Nz Marine Cluster May 12 Report
Nz Marine Cluster May 12 ReportNz Marine Cluster May 12 Report
Nz Marine Cluster May 12 ReportBen Mayson
 
The CoffeeScript Edge
The CoffeeScript EdgeThe CoffeeScript Edge
The CoffeeScript EdgeTrevorBurnham
 
2013 10-22 internet-arriskuak_andramendi_eu
2013 10-22 internet-arriskuak_andramendi_eu2013 10-22 internet-arriskuak_andramendi_eu
2013 10-22 internet-arriskuak_andramendi_euUrko Zurutuza
 
Internet-en, ze irudi ari naiz ematen?
Internet-en, ze irudi ari naiz ematen?Internet-en, ze irudi ari naiz ematen?
Internet-en, ze irudi ari naiz ematen?Urko Zurutuza
 
'Decisions For Life' -Project
'Decisions For Life' -Project'Decisions For Life' -Project
'Decisions For Life' -Projectwageindicator
 
Nz Marine Cluster May 12 Ppt
Nz Marine Cluster May 12 PptNz Marine Cluster May 12 Ppt
Nz Marine Cluster May 12 PptBen Mayson
 
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.guestc179d8
 
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...guestc179d8
 
Case Studies In Stroke
Case Studies In StrokeCase Studies In Stroke
Case Studies In Strokeguestc179d8
 
Internet arriskuak bidegoian_2011-09-22
Internet arriskuak bidegoian_2011-09-22Internet arriskuak bidegoian_2011-09-22
Internet arriskuak bidegoian_2011-09-22Urko Zurutuza
 
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocket
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocketTOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocket
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocketEmpowered Presentations
 

Viewers also liked (20)

E field disk
E field diskE field disk
E field disk
 
Cubmaster's Toolbox
Cubmaster's ToolboxCubmaster's Toolbox
Cubmaster's Toolbox
 
Nz Marine Cluster May 12 Report
Nz Marine Cluster May 12 ReportNz Marine Cluster May 12 Report
Nz Marine Cluster May 12 Report
 
Presentation1
Presentation1Presentation1
Presentation1
 
Presentation1
Presentation1Presentation1
Presentation1
 
The CoffeeScript Edge
The CoffeeScript EdgeThe CoffeeScript Edge
The CoffeeScript Edge
 
Magazine Evaluation
Magazine EvaluationMagazine Evaluation
Magazine Evaluation
 
2013 10-22 internet-arriskuak_andramendi_eu
2013 10-22 internet-arriskuak_andramendi_eu2013 10-22 internet-arriskuak_andramendi_eu
2013 10-22 internet-arriskuak_andramendi_eu
 
Internet-en, ze irudi ari naiz ematen?
Internet-en, ze irudi ari naiz ematen?Internet-en, ze irudi ari naiz ematen?
Internet-en, ze irudi ari naiz ematen?
 
'Decisions For Life' -Project
'Decisions For Life' -Project'Decisions For Life' -Project
'Decisions For Life' -Project
 
Nz Marine Cluster May 12 Ppt
Nz Marine Cluster May 12 PptNz Marine Cluster May 12 Ppt
Nz Marine Cluster May 12 Ppt
 
Magazine Evaluation
Magazine EvaluationMagazine Evaluation
Magazine Evaluation
 
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.
Case Studies In Stroke Prepared By Arlyn M. Valencia, M.D.
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...
Cerebral Hemorrhage By Arlyn M. Valencia, M.D. Associate Professor, Universit...
 
Case Studies In Stroke
Case Studies In StrokeCase Studies In Stroke
Case Studies In Stroke
 
Internet arriskuak bidegoian_2011-09-22
Internet arriskuak bidegoian_2011-09-22Internet arriskuak bidegoian_2011-09-22
Internet arriskuak bidegoian_2011-09-22
 
Things Dogs Carry #THINGSICARRY
Things Dogs Carry #THINGSICARRYThings Dogs Carry #THINGSICARRY
Things Dogs Carry #THINGSICARRY
 
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocket
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocketTOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocket
TOP 121 TWEETS ON HOW TO PREACH BETTER @therocketco #preachrocket
 
El tiempo
El tiempoEl tiempo
El tiempo
 

Similar to End to-End CoffeeScript

Writing Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptWriting Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptSusan Potter
 
CoffeeScript the Awesome
CoffeeScript the AwesomeCoffeeScript the Awesome
CoffeeScript the AwesomeJames Hughes
 
Coffee scripts with rails
Coffee scripts with railsCoffee scripts with rails
Coffee scripts with railsDevilal Dheer
 
Coffeescript unfancy javascript
Coffeescript unfancy javascriptCoffeescript unfancy javascript
Coffeescript unfancy javascriptDimitris Tsironis
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013Spyros Ioakeimidis
 
Front-End Engineering 101
Front-End Engineering 101Front-End Engineering 101
Front-End Engineering 101Milan Korsos
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"testflyjets
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...Paul Jensen
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovMichael Kimathi
 
appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemappborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemendian7000
 
CoffeeScript: The Good Parts
CoffeeScript: The Good PartsCoffeeScript: The Good Parts
CoffeeScript: The Good PartsC4Media
 

Similar to End to-End CoffeeScript (20)

Writing Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptWriting Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScript
 
CoffeeScript the Awesome
CoffeeScript the AwesomeCoffeeScript the Awesome
CoffeeScript the Awesome
 
Coffee scripts with rails
Coffee scripts with railsCoffee scripts with rails
Coffee scripts with rails
 
Smooth CoffeeScript
Smooth CoffeeScriptSmooth CoffeeScript
Smooth CoffeeScript
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
Coffeescript unfancy javascript
Coffeescript unfancy javascriptCoffeescript unfancy javascript
Coffeescript unfancy javascript
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013
 
Coffee script throwdown
Coffee script throwdownCoffee script throwdown
Coffee script throwdown
 
Front-End Engineering 101
Front-End Engineering 101Front-End Engineering 101
Front-End Engineering 101
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Where is my scalable API?
Where is my scalable API?Where is my scalable API?
Where is my scalable API?
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
 
React js basics
React js basicsReact js basics
React js basics
 
appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemappborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-system
 
Rails 3.1
Rails 3.1Rails 3.1
Rails 3.1
 
CoffeeScript: The Good Parts
CoffeeScript: The Good PartsCoffeeScript: The Good Parts
CoffeeScript: The Good Parts
 

Recently uploaded

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

End to-End CoffeeScript

  • 1. End-to-End CoffeeScript Presented by Trevor Burnham at RailsConf 2011
  • 4. Do you have to use it?
  • 6. Things I’ll cover today: A brief primer on the CoffeeScript language How it works with the Rails 3.1 asset pipeline Running the same JS/CS code on both the client and the server
  • 7. And things I won’t: The CoffeeScript language in depth (that would take a whole book... available at http://coffeescript-book.com) Sprockets 2 (#=
require
foo) jQuery UJS ($.rails)
  • 8. CoffeeScript crash course “Dash rocket” instead of function Semantic whitespace instead of {} Implicit parentheses, implicit var scoping
  • 9. Awesome goodies for Rubyists Postfix if/unless Implicit returns String interpolations
  • 10. Things that feel weird to Rubyists Parentheses are not optional on functions with no arguments It’s just JavaScript™
  • 11. Things that feel weird to JavaScripters CoffeeScript’s of is JavaScript’s in CoffeeScript’s in is Python’s in CoffeeScript’s == is JavaScript’s ===
  • 12. Tradeoffs Debugging (will get better, but currently kind of a pain) Changing versions (though it’s been pretty stable for the last 5 months) Less documentation (but there is a book from PragProg...)
  • 13. Even so! After only a week of using CoffeeScript, I felt more productive than I ever had in JavaScript. The community is awesome. Learning CoffeeScript might make you think more deeply about JavaScript.
  • 15. Let’s make a Rails app! rails
new
EndToEnd cd
EndToEnd rails
generate
controller
User
signup Clone the repo if you want to follow along... http://github.com/TrevorBurnham/EndToEnd)
  • 16. JavaScripts are assets New in Rails 3.1, generate
controller gives us a CoffeeScript file automatically:
  • 17. Compound extensions .html.erb & .html.haml → HTML .css.scss & .css.sass → CSS .js.coffee → JavaScript Want to use a different format? Just rename! application.js → application.js.coffee
  • 18. Compound extensions Stylesheets and JavaScripts are automatically concatenated by Sprockets 2, even in development: All the CSS and JS is loaded on every page, so it’s still up to you to isolate controller-specific functionality.
  • 21. Great, but... Client-side validations are just there to provide a friendlier user experience. What really matters are server-side validations. Traditionally, we’d do this by using ActiveRecord, repeating much of the work we just did... But there’s another way!
  • 22. Server-side JavaScript! (And CoffeeScript) If you’ve got coffee‐script in your Gemfile, then you’ve already got ExecJS: https://github.com/sstephenson/execjs It uses the best available JS environment on your system. Use therubyracer (or therubyracer‐heroku) for maximum portability.
  • 23. No need to rewrite the same validation code! ExecJS lets us turn our CoffeeScript validation code into a Ruby object:
  • 24. A small taste of what’s to come Future plugins will make the server-side JS process smoother in Rails With jsdom, you can do practically anything that you could do with client-side JS (including manipulating HTML with jQuery!) Validation, templating... anything you’re duplicating can be done as end-to-end JS.
  • 25. How can you become a CoffeeScript ninja? Official site, great overview: http://coffeescript.org Nice screencast: http://peepcode.com/products/coffeescript Totally unbiased book recommendation: http://coffeescript-book.com
  • 26. Thanks Questions? trevorburnham@gmail.com