Slides for DrupalCamp Cork 2013 talk. It covers the features of CoffeeScript and how to integrate it into your development environment for Drupal themes.
them most of the time, but it’s handy to leave them out in callbacks. $(‘.button’).click -> $.ajax ‘/delete’, type: ‘POST’ success: (data) -> alert(‘Success’) error: (jqXHR) -> alert(“There was an error deleting your data: #{jqXHR.responseText}”) CoffeeScript
Which means the return statement is optional but I prefer to insert them anyway. grade = (student) -> if student.excellentWork “A+” else if student.okayStuff if student.triedHard then “B” else “B-” else “C” var grade; grade = function(student) { if (student.excellentWork) { return “A+”; } else if (student.okayStuff) { if (student.triedHard) { return “B”; } else { return “B-”; } } else { return “C”; } }; CoffeeScript JavaScript
console.log(‘property of obj exists’) x = a ? b x ?= defaultValue x is equal to a if a exists, otherwise it’s equal to b if x doesn’t exist, set it to defaultValue CoffeeScript CoffeeScript CoffeeScript
#{@type}") class Dog extends Animal constructor: -> super('dog') class Cat extends Animal -> constructor: -> super('cat') dog = new Dog() dog.whatAmI() cat = new Cat() cat.whatAmI() Support for classes CoffeeScript
• Verbally readable != quicker comprehension Though you can still use && instead of and • Significant white-space means CoffeeScript will always be compiled. Since you will want to minify the code when serving it to a browser. if (five && six && seven) doStuff(); doSomething() if five and six and seven from Ryan Florence’s Blog - bit.ly/IsGZMk
theme. Omega 4 supports Sass, Grunt and Bower. To set up the client-side development environment on OSX see my blog post - bit.ly/19hJqRo Grunt builds your Sass and Cofffeescript Bower manages your 3rd-party libraries
you make changes: Grunt supports LiveReload so any changes to Sass or CoffeeScript will be updated in the browser without having to press the Refresh button. Google Chrome supports JavaScript source maps so you can debug CoffeeScript in the browser: grunt watch Terminal