background preloader

Coffescript

Facebook Twitter

Ruby5 - Getting started with Konacha. Js2coffee: convert JavaScript code to CoffeeScript. Learn coffeescript in Y Minutes. CoffeeScript is a little language that compiles one-to-one into the equivalent JavaScript, and there is no interpretation at runtime. As one of the succeeders of JavaScript, CoffeeScript tries its best to output readable, pretty-printed and smooth-running JavaScript codes working well in every JavaScript runtime.

See also the CoffeeScript website, which has a complete tutorial on CoffeeScript. Got a suggestion? A correction, perhaps? Open an Issue on the Github Repo, or make a pull request yourself! CoffeeConsole: A Chrome Extension. Harry Brundage, a co-worker of mine at Shopify, does a lot of CoffeeScript development and said he would love to be able to do CoffeeScript right from the console in Chrome's Web Inspector.

I asked Paul Irish, a "dev relations guy" at Google, to point me in the right direction on building just such a thing. The result of today's pet project is CoffeeConsole, a Chrome extension that adds a new panel inside the Web Inspector. Type in any CoffeeScript and then hit the run button (or hit Command-Enter or Shift-Enter). The code will be compiled into JavaScript and then run in the context of the current window. I've put together a quick video to demonstrate this. Behind the scenes, I cobbled together a bunch of resources. There's definitely more features that can (and maybe should) be added such as the ability to review the compiled JavaScript and the ability to view the compilation errors.

Download the extension or check out the repo on Github. CoffeeScript Classes Play Nicely with AngularJS Factories. Js2coffee: convert JavaScript code to CoffeeScript. A convention for using CoffeeScript with Rails — Rendered Text. On a recent new project we’ve had the opportunity to make the leap and use CoffeeScript exclusively for client-side scripting. This post describes a convention we came up with for using it with Rails. Typically what we’d previously do is write a JavaScript “class” like this: Our needs are usually modest and the class is in fact acting just like a namespace with a name that corresponds to the resource it’s being used on. We’d run the jQuery function and call our functions, often passing some resource-specific arguments, such as paths, inside a view file like this: By default, the new asset pipeline in Rails 3.1 bundles all JS files in one.

I learned that I need to prefix a function or class with window. to make it global, because the CoffeeScript compiler wraps all code in an anonymous function and doesn’t pollute the global scope. Then I looked for a way to embed CoffeeScript in a view file. We came up with this: Here are two helper methods we use: The view can call page_data like this: CoffeeScript. CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime.

The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Latest Version: 1.12.5 npm install -g coffee-script CoffeeScript 2 is coming! Overview CoffeeScript on the left, compiled JavaScript output on the right. number = 42 opposite = true number = -42 if opposite square = (x) -> x * x list = [1, 2, 3, 4, 5] math = root: Math.sqrt square: square cube: (x) -> x * square x race = (winner, runners...) -> print winner, runners alert "I knew it! " run: cubes Installation npm install --global coffee-script Usage Examples: Functions load.

CoffeeScript. A Case for CoffeeScript. I’ve been writing JavaScript applications for the past few years. I’ve spent a lot of time learning JavaScript, and I’ve established a pretty solid development work-flow. We use CoffeeScript here at Gaslight, so when I came on-board, I was not at all excited to switch. I’ve spent the past few months in CoffeeScript, I can honestly say that I was wrong. I think CoffeeScript is great and here’s why: Beauty I hate to admit it, but JavaScript is just plain ugly. Whitespace This had been one of my biggest perceived qualms with the CoffeeScript syntax. Debugging I spend a lot of time in the Chrome debugger, so the thought of stepping through code that I didn’t write was a real concern. Linting When I was writing JavaScript, I always ran my code through a linter. The Downside CoffeeScript is great, but it’s not all unicorns and rainbows. It’s also a pain when you need to convert someone else’s JavaScript into CoffeeScript.

Yay, now I don’t have to learn JavaScript! NO! Try it! The Absolute Beginner's Guide to CoffeeScript. CoffeeScript has become increasingly popular over the last couple of years due to its adoption by the Node.js and Rails communities. Let’s take a look why it’s become the go-to language when people are wanting to write JavaScript in their apps. What is CoffeeScript? CoffeeScript is a language that gets compiled to JavaScript. Code in .coffee files are not interpreted at run time, like JavaScript, but are compiled into .js files. Whether you’re writing for JavaScript for the Node.js or any given browser’s implementation, CoffeeScript can be written for any and all flavors of JavaScript. Why CoffeeScript? In the past, JavaScript hasn’t had the most stellar of reputations due to the copy-and-paste mentality of the 90′s and early 2000′s, it seemed that only a few had any idea what was going on.

CoffeeScript makes use of the powerful features of JavaScript without learning the less known features of JavaScript by adding “syntactic sugar” to JavaScript. Installing CoffeeScript On OS X On Windows. Writing Better JavaScript with CoffeeScript: The Basics. By Jack Franklin I’m a huge fan of JavaScript. Its popularity has really surged in recent years with the advent of rich internet applications (RIAs), Ajax and web development libraries like jQuery that makes JavaScript more appealing and accessible to a broader audience. However, that doesn’t mean the language is without its quirks, and often these can come from nowhere to bite you. There’s a long running joke about JavaScript’s good parts compared to its bad parts and how the language has many problems. In this multi-part guide, I’ll present you with a solution to most of these problems: CoffeeScript. This is the first part a series of articles that introduces you to this wonderful programming language.

What is CoffeeScript? CoffeeScript is a small programming language that compiles into JavaScript. The official CoffeeScript website. CoffeeScript was created by developer Jeremy Ashkenas, a lead developer for DocumentCloud (an open source tool for journalists). How CoffeeScript Works a = 2. CoffeeScript: A Roundup for Beginners | aLittle{Code} #267 CoffeeScript Basics. CoffeeScript allows you to write JavaScript in a concise, elegant fashion. Here I convert JavaScript code to CoffeeScript in a Rails 3.1 app. Download: source codeProject Files in Zip (84 KB)mp4Full Size H.264 Video (21 MB)m4vSmaller H.264 Video (12.2 MB)webmFull Size VP8 Video (14.2 MB)ogvFull Size Theora Video (33.9 MB) Introduction to CoffeeScript. Welcome to the Introduction to CoffeeScript screencast. With the adoption of CoffeeScript by the Node.js community, the JavaScript community in general, and with CoffeeScript's inclusion in the upcoming Rails 3.1 release, it's probably a good idea to see what all the fuss is about.

What is CoffeeScript? CoffeeScript is a language that compiles down to JavaScript. This means that code in .coffee files are not interpreted at run time, but are compiled beforehand into .js files. CoffeeScript can be written for all implementations of JavaScript, whether it's for Node.js or the browser. Why CoffeeScript? First of all, JavaScript got a bad wrap in the past for the copy-and-paste mentality of the 90's and early 2000's, where no one really knew what was going on. Saying that, you can get lost in the curly brackets and semi-colons - It can get messy, and sometimes a tad unreadable. Installing CoffeeScript To install CoffeeScript we're going to use Homebrew. Next, we'll install CoffeeScript. Strings. CoffeeScript for Beginners (Part 2 of 2) - Dan DeMeyere. My first post on CoffeeScript was primarily focused on getting CoffeeScript installed and having Node.js continuously compile your .coffee files. I touched on creating simple objects and iterating in a for loop, but this post will be all about the standard .click() handler and AJAX function (as well as some nice tricks).

Click Handlers The .click() handler is probably the most used jQuery method and it happens to be an easy implementation in CoffeeScript. For the rest of this post, let's assume you have a JavaScript file (app.coffee) with a .setup() method that is called on page load. So somewhere in your view (after you have included the compiled JavaScript file), you have something that looks like this: That code will ensure your app.setup() method is called after the DOM has loaded and your JavaScript is aware of every element. AJAX, which stands for asynchronous JavaScript and XML, has become a staple for Front-end engineers.

Going the Extra Mile This does 2 things. Useful Resources. CoffeeScript for Beginners (Part 1 of 2) - Dan DeMeyere. If you're a Rails developer, CoffeeScript is something you need to pay attention to. With the news that CoffeeScript will be included by default in Rails 3.1, CoffeeScript is definitely generating a sizable amount of momentum and the core Rails team believes it's the future. Knowing this, I was looking for an opportunity to use it and a clean project presented itself this sprint at thredUP. So with the help of my colleagues Kylie and Chris, we dove in and started playing away. The first step is to install CoffeeScript (really?). To install Homebrew, just run this command in your terminal (assuming you have xCode installed already): Next, you need to install Node.js, which will compile your CoffeeScript for you.

You're almost there. Done! You can end your CS files with .coffee or .js.coffee, so create a new file in there so we can finally write some code. When I first got everything setup, I was a little bit paralyzed. Pretty sexy, right? CoffeeScript. CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript. Latest Version: 1.7.1 sudo npm install -g coffee-script Overview CoffeeScript on the left, compiled JavaScript output on the right. run: cubes Installation The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator.

Npm install -g coffee-script (Leave off the -g if you don't wish to install globally.) Usage Examples: load. Going Singular and Angular with your morning CoffeeScript | Agile Development Blog. I’ve long been fascinated by the plethora of JavaScript libraries and frameworks that began to flood the web around 2005. While it’s a given that jQuery has become ubiquitous in the general-purpose DOM-manipulation and AJAX spaces, the battle for the MV* space is not yet over, nor is the battle for the best way to do single page applications (SPA).

In fact, because there are so many options, Addy Osmani and Sindre Sorhus put together a great site to help you sort through the options: . It uses the also ubiquitous Todo app, implemented with thousands of different JavaScript libraries to help you compare and contrast. (Ok, dozens) In this post, you’ll learn the basics of creating responsive, single page application’s with Google’s well-designed, well-supported, and increasingly popular AngularJS. HTML is great for declaring static documents, but it falters when we try to use it for declaring dynamic views in web-applications. That’s enough to get started with. Enjoy! Walkthrough Angularjs - Using CoffeeScript in controllers. Hall Pass. Tutorials and snippets to get started with CoffeeScript. What is CoffeeScript?

To keep it simple, CoffeeScript is a little language that compiles into JavaScript. If you ever coded in languages such as Python or Ruby, you’ll probably love CoffeeScript a lot. Instead of awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript implementation, and tends to run as fast or faster than the equivalent handwritten JavaScript. Installing CoffeeScript Installing CoffeeScript is not hard at all.

Once done, you can install CoffeeScript by running the following command: npm install -g coffee-script CoffeeScript is now installed. Coffee --compile example.coffee Tutorial: Basics of CoffeeScript. Playing with CoffeeScript | All Aboard Rails. After having used Haml and Sass and loving them, a friend introduced me to CoffeeScript. In short CoffeeScript is to Javascript as Haml is to Html and Sass is to CSS. Not so strictly speaking but lets roll with this for now. So here is my how-to article to share my thoughts and experience, while I played with it.

What is CoffeeScript and why do you care? Instead of me, making something up, here is what the CoffeeScript site has to say: “CoffeeScript is a little language that compiles into JavaScript. Read more or try in your browser at the CoffeeScript website. Ok, now that we are clear on that, if you are still interested, let’s play with it some, shall we… First we will see how to get it installed on our machine, and then try out some code.

Installation on Mac OSx 1. After node.js is installed you will get some instructions. A. 2. 3. Once installed, you should have access to the “coffee” command, which can execute scripts, compile .coffee files into .js, and provide an interactive REPL. CoffeeScript: The beautiful way to write JavaScript. Smooth CoffeeScript by E. Hoigaard. Learn CoffeeScript. Ristrettolo.gy, CoffeeScript Ristretto Online. Code 34m0: Working together: AngularJS and Coffeescript. Coffee Taster: an Easy CoffeeScript Development Environment for Ruby Developers. Going Singular and Angular with your morning CoffeeScript | Agile Development Blog. Spectacular - Introduction.

#267 CoffeeScript Basics. Introduction to CoffeeScript. Better CoffeeScript Testing With Mocha. CoffeeScript for Beginners (Part 2 of 2) - Dan DeMeyere. CoffeeScript for Beginners (Part 1 of 2) - Dan DeMeyere. CoffeeScript. Playing with Yeoman, AngularJS, and CoffeeScript. Jens Krause - WEBSECTOR.DE - Fun with AngularJS + Rails + CoffeeScript + Sass: Another Cafe Townsend example. Sharing data across controllers – Angular JS & CoffeeScript by Mike Coutermarsh.

CoffeeScript Classes Play Nicely with AngularJS Factories. Going Singular and Angular with your morning CoffeeScript | Agile Development Blog. Test angularJS with jade stylus coffeescript | Fiddle Salad. Plunker - AngularJS Controllers with Class in Coffeescript. AngularJs Tutorial 3 - Creating a Simple Angular Application using Coffescript. CoffeeScript and AngularJS. Monocle. Walkthrough Angularjs - Using CoffeeScript in controllers. Playing with CoffeeScript | All Aboard Rails. Should You Learn CoffeeScript? CoffeeScript: The beautiful way to write JavaScript.

Smooth CoffeeScript by E. Hoigaard. Comparing Ranges. Exploring CoffeeScript Part 4 – Objects and Classes. Exploring CoffeeScript Part 3 – More on Functions. Exploring CoffeeScript Part 2 – Variables and Functions. Exploring CoffeeScript Part 1 – And Then There Was Coffee. Exploring CoffeeScript Part 5 – Ranges, Loops and Comprehensions. Coffee Taster: an Easy CoffeeScript Development Environment for Ruby Developers.

Brunch | HTML5 application assembler. Try CoffeeScript Enhanced. Js2coffee: convert JavaScript code to CoffeeScript. Tutorials and snippets to get started with CoffeeScript. Home. CoffeeScript is just JavaScript | Float Left.