Articles tagged 'javascript'

  • The joy of writing CoffeeScript

    November 11, 2011


    This post was originally published in the Rambling Labs Blog on November 11, 2011.


    I have been a fan of JavaScript for a while now, and I have dived into the CoffeeScript world for the last month or so.

    Guess what? I love it! It’s been a great experience so far.

    Definitely the one thing that I’m loving the most right now about CoffeeScript is the syntactic sugar. It’s basically a lot of simple shorthands for certain things (the -> is so handy). Take this example (and ignore what the excluded methods are doing):

    I had this:

    class BuildUtils
      combine_source_files: (callback) ->
        self = @
        fs.readdir './src', (err, files) ->
          self.error_handler err
          content = new Array()
    
          files = files.sort()
          for file, index

    Continue Reading →

  • Unit testing the jQuery Rambling Slider - Part 2 - The DOM, jQuery and node.js

    November 9, 2011


    This post was originally published in the Rambling Labs Blog on November 9, 2011.


    In order to continue to add tests to the jQuery Rambling Slider, I needed to test something against the DOM. Problem is, you don’t count with the DOM when you’re running the Jasmine tests from console. So what should I do?

    As expected, I found that there is a DOM emulator in node.js :D. Also, to test using jQuery I needed to download the corresponding node package. So I didn’t waste any time and went ahead to install them:

    npm install -g jsdom
    npm install -g jquery
    

    So now, I can write something like this in my src/jquery.plugins.coffee:

    (($) ->
      $.fn.reverse = [].reverse
    )(jQuery)
    

    And test it on my spec/jquery.plugins.spec.coffee with something like this…

    Continue Reading →

  • Unit testing the jQuery Rambling Slider - CoffeeScript, Jasmine and node.js

    November 9, 2011


    This post was originally published in the Rambling Labs Blog on November 9, 2011.


    As you may know, I have been working lately on the jQuery Rambling Slider. One of my personal milestones with this project is to write as many unit tests as possible, so I began my research.

    Honestly, I didn’t know where to begin. I remember to have read once on twitter that someone was writing their tests with Jasmine and CoffeeScript, so that could be a good starting point (and it sounds really fun too!). I have worked with Jasmine before and it sure was a great experience. It’s yet another productivity tool made by the great Pivotal Labs guys.

    After googling for a while, I stumbled into a post from someone that was writing tests in Jasmine and node.js

    Continue Reading →

  • jQuery Rambling Slider has been released!

    October 22, 2011


    This post was originally published in the Rambling Labs Blog on October 22, 2011.


    A while ago I was looking for a good image slider jQuery plugin to use on a project, and Nivo Slider turned out to be the best candidate. I made some modifications for my needs at the moment and issued a pull request, but had no luck. I also said that if my pull request didn’t get accepted or took too long to be accepted, I would release it myself.

    Guess what? I got tired of waiting, so here it is! I just uploaded my first stable release of the now called jQuery Rambling Slider. :)

    It’s still basically the same Nivo Slider with the tweaks I made in my fork. It’s now written in CoffeeScript, which I’m having a lot of fun with, while the compiled JavaScript…

    Continue Reading →

  • Rails 3.1 "rails server" error Could not find a JavaScript runtime

    September 19, 2011


    This post was originally published in the Rambling Labs Blog on September 19, 2011.


    I upgraded to rails 3.1.0 and created a new ‘test_app’.

    rails new test_app
    

    Got into the directory. Everything was fine, until I tried to run:

    rails server
    

    It threw a weird error:

    Could not find a JavaScript runtime.
    See https://github.com/sstephenson/execjs for a list of available runtimes.
    

    That’s kinda weird. What does a rails app have to do with any JavaScript runtime? I guess it’s support for something that I still don’t know anything about.

    I googled that and found a stackoverflow question. So, two solutions for the issue: either*** install nodejs*** or include “gem ‘execjs’” and “gem ‘therubyracer’” in the Gemfile and run bundle install.

    Pick…

    Continue Reading →