Developer Workflow

Getting Started with Yeoman & Grunt

Why use Grunt? In one word: automation. The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you’ve configured it, a task runner can do most of that mundane work for you—and your team—with basically zero effort.

Grunt is a task-based command line build tool for JavaScript projects.

The Grunt ecosystem is huge and it’s growing every day. With literally hundreds of plugins to choose from, you can use Grunt to automate just about anything with a minimum of effort. If someone hasn’t already built what you need, authoring and publishing your own Grunt plugin to npm is a breeze.


GruntJSGrunt is built on Node.js, and it’s available as a package via the Node package manager (npm).

Installing the CLI

In order to get started, you’ll want to install Grunt’s command line interface (CLI) globally. You may need to use sudo (for OSX, *nix, BSD etc) or run your command shell as Administrator (for Windows) to do this.

[ecko_code_highlight]npm install -g grunt-cli[/ecko_code_highlight]

This will put the grunt command in your system path, allowing it to be run from any directory. Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.

How the CLI Works

Each time grunt is run, it looks for a locally installed Grunt using node’s require() system. Because of this, you can run grunt from any subfolder in your project.

If a locally installed Grunt is found, the CLI loads the local installation of the Grunt library, applies the configuration from your Gruntfile, and executes any tasks you’ve requested for it to run. To really understand what is happening, read the code. It’s very short.

Working with an existing Grunt project

Assuming that the Grunt CLI has been installed and that the project has already been configured with a package.json and a Gruntfile, it’s very easy to start working with Grunt:

  1. Change to the project’s root directory.
  2. Install project dependencies with npm install.
  3. Run Grunt with grunt.

That’s really all there is to it. Installed Grunt tasks can be listed by running grunt –help but it’s usually a good idea to start with the project’s documentation.

The Gruntfile

The Gruntfile.js or Gruntfile.coffee file is a valid JavaScript or CoffeeScript file that belongs in the root directory of your project, next to the package.json file, and should be committed with your project source. A Gruntfile is comprised of the following parts:

  • The “wrapper” function
  • Project and task configuration
  • Loading Grunt plugins and tasks
  • Custom tasks

Example Gruntfile

In the following Gruntfile, project metadata is imported into the Grunt config from the project’s package.json file and the grunt-contrib-uglify plugin’s uglify task is configured to minify a source file and generate a banner comment dynamically using that metadata. When grunt is run on the command line, the uglify task will be run by default.

[ecko_code_highlight]var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World\n’);
}).listen(1337, ‘’);
console.log(‘Server running at’);[/ecko_code_highlight]

Most Grunt tasks rely on configuration data defined in an object passed to the grunt.initConfig method.

In this example, grunt.file.readJSON('package.json') imports the JSON metadata stored in package.json into the grunt config. Because <% %> template strings may reference any config properties, configuration data like filepaths and file lists may be specified this way to reduce repetition.

You may store any arbitrary data inside of the configuration object, and as long as it doesn’t conflict with properties your tasks require, it will be otherwise ignored. Also, because this is JavaScript, you’re not limited to JSON; you may use any valid JS here. You can even programmatically generate the configuration if necessary.

Like most tasks, the grunt-contrib-uglify plugin’s uglify task expects its configuration to be specified in a property of the same name. Here, the banner option is specified, along with a single uglify target named build that minifies a single source file to a single destination file.

This extract of text has been used as a demonstration of the Astro Ghost Theme. For more information on Grunt, see http://gruntjs.com.

Programming Patterns

JavaScript Design Patterns: Introduction

One of the most important aspects of writing maintainable code is being able to notice the recurring themes in that code and optimize them. This is an area where knowledge of design patterns can prove invaluable.

In the first part of this book, we will explore the history and importance of design patterns which can really be applied to any programming language. If you’re already sold on or are familiar with this history, feel free to skip to the chapter “What is a Pattern?” to continue reading.

Design patterns can be traced back to the early work of an architect named Christopher Alexander. He would often write publications about his experience in solving design issues and how they related to buildings and towns. One day, it occurred to Alexander that when used time and time again, certain design constructs lead to a desired optimal effect.

In collaboration with Sara Ishikawa and Murray Silverstein, Alexander produced a pattern language that would help empower anyone wishing to design and build at any scale. This was published back in 1977 in a paper titled “A Pattern Language”, which was later released as a complete hardcover book.

Some 30 years ago, software engineers began to incorporate the principles Alexander had written about into the first documentation about design patterns, which was to be a guide for novice developers looking to improve their coding skills. It’s important to note that the concepts behind design patterns have actually been around in the programming industry since its inception, albeit in a less formalized form.

One of the first and arguably most iconic formal works published on design patterns in software engineering was a book in 1995 called Design Patterns: Elements Of Reusable Object-Oriented Software. This was written by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides – a group that became known as the Gang of Four (or GoF for short).

The GoF’s publication is considered quite instrumental to pushing the concept of design patterns further in our field as it describes a number of development techniques and pitfalls as well as providing twenty-three core Object-Oriented design patterns frequently used around the world today. We will be covering these patterns in more detail in the section “Categories of Design Patterns”.

In this book, we will take a look at a number of popular JavaScript design patterns and explore why certain patterns may be more suitable for your projects than others. Remember that patterns can be applied not just to vanilla JavaScript (i.e standard JavaScript code), but also to abstracted libraries such as jQuery or dojo as well. Before we begin, let’s look at the exact definition of a “pattern” in software design.

What is a Pattern?

A pattern is a reusable solution that can be applied to commonly occurring problems in software design – in our case – in writing JavaScript web applications. Another way of looking at patterns are as templates for how we solve problems – ones which can be used in quite a few different situations.

  • Patterns are proven solutions: They provide solid approaches to solving issues in software development using proven techniques that reflect the experience and insights the developers that helped define them bring to the pattern.
  • Patterns can be easily reused: A pattern usually reflects an out of the box solution that can be adapted to suit our own needs. This feature makes them quite robust.
  • Patterns can be expressive: When we look at a pattern there’s generally a set structure and vocabulary to the solution presented that can help express rather large solutions quite elegantly.

Design Pattern Categorization

In my early experiences of learning about design patterns, I personally found the following table a very useful reminder of what a number of patterns has to offer – it covers the 23 Design Patterns mentioned by the GoF. The original table was summarized by Elyse Nielsen back in 2004 and I’ve modified it where necessary to suit our discussion in this section of the book.

I recommend using this table as reference, but do remember that there are a number of additional patterns that are not mentioned here but will be discussed later in the book.

A brief note on classes

Keep in mind that there will be patterns in this table that reference the concept of “classes”. JavaScript is a class-less language, however classes can be simulated using functions.

The most common approach to achieving this is by defining a JavaScript function where we then create an object using the new keyword. this can be used to help define new properties and methods for the object as follows:

[ecko_code_highlight language=”javascript”]function Car( model ) {
this.model = model;
this.color = “silver”;
this.year = “2012”;
this.getInfo = function () {
return this.model + ” ” + this.year;

Code Annotation

This is an example of a code annotation in Astro.

This extract of text has been used as a demonstration of the Astro WordPress Theme.

Copyright © Addy Osmani 2013.

Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It is available for purchase via O’Reilly Media but will remain available for both free online and as a physical (or eBook) purchase for readers wishing to support the project.

WordPress Theme

Astro WordPress Theme

Astro is a content focused responsive theme for the WordPress platform. Designed from the bottom up to be high performance, user friendly, and accessible on all devices. Astro adapts to the users viewport, so it looks great on smartphones, tablets, TVs, and even the latest 4K monitors. Astro includes two different post styles. The standard style is designed for update posts and short articles. The featured style includes full title images, suited towards larger articles, tutorials and other documentation.



Fully Responsive

Optimized for Mobile, Tablets, Notebooks, and Desktop Devices. Developed on iPhone, iPad, and Desktop.

High Resolution Support

CSS3 elements & SVG icons scale perfectly on all resolutions, including high resolution devices such mobile phones, retina displays, and 4K monitors.

Featured Posts

Feature posts have a full page title design with customizable image header. Make your articles and guides stand out.

High Performance

Optimized for fast page load times, completely imageless layout, javascript degrading, and CSS3 styling. Google Speed Test score of 94.

Article Flow Bar

Navigating large articles is made simple with the floating article bar which activates as you scroll down the post. It will update to show the current header section.


The documentation included provides all the information needed to get the theme installed and customized. However, if you have any questions you can email support@ecko.me, and we will be happy to help.

If you have any bug reports, or feature requests, please let us know!

Frontend Development

Presentation In Structured Content

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam nisi lorem, pulvinar id, commodo feugiat, vehicula et, mauris. Aliquam mattis porta urna. Maecenas dui neque, rhoncus sed, vehicula vitae, auctor at, nisi. Aenean id massa ut lacus molestie porta. Curabitur sit amet quam id libero suscipit venenatis.

Donec placerat mauris commodo dolor. Nulla tincidunt. Nulla vitae augue.

Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sed ligula. Sed volutpat odio non turpis gravida luctus. Praesent elit pede, iaculis facilisis, vehicula mattis, tempus non, arcu.

  • Lorem ipsum dolor sit amet.
  • Consectetuer adipiscing elit.
  • Nam at tortor quis ipsum tempor aliquet.

Suspendisse ac pede. Cras tincidunt pretium felis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque porttitor mi id felis. Maecenas nec augue. Praesent a quam pretium leo congue accumsan.

Header Two

Phasellus id risus id ligula iaculis elementum vel quis risus. Donec nunc purus, dapibus eu nulla a, bibendum congue justo. Mauris commodo ligula ullamcorper gravida condimentum. Donec id condimentum turpis, quis tempor metus.

Header Three

In feugiat enim quis lectus rutrum vulputate. Duis iaculis dignissim justo in volutpat. Aliquam vitae velit eu nisl fermentum tincidunt non sit amet metus.

[ecko_code_highlight language=”css”]p{
margin:30px 0;
font:400 16px ‘Merriweather’, Serif;

NodeJS Guides

Simple HTTP Server in NodeJS

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

This simple web server written in Node responds with “Hello World” for every request. To run the server, put the code into a file example.js and execute it with the node program from the command line.

[ecko_code_highlight language=”javascript”]var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello Worldn’);
}).listen(1337, ‘’);
console.log(‘Server running at’);[/ecko_code_highlight]


Yosemite Time-lapse Video

This video is a collaboration between Sheldon Neill and Colin Delehanty. All timelapses were shot on the Canon 5D Mark II with a variety of Canon L and Zeiss CP.2 Lenses.

This whole project has been an amazing experience. The two of us became friends through Vimeo and explored a shared interest in timelapsing Yosemite National Park over an extended period of time. We’d like to expand this idea to other locations and would appreciate any suggestions for a future project.

Project Yosemite Website: http://projectyose.com
Facebook Page: http://facebook.com/projectyose
Twitter: http://twitter.com/projectyose
Contact info: info@projectyose.com

Social Networking

Social Profiles

Beside and below each blog post is an author profile which contains the post authors information (this can be set in the user settings of the ghost admin dashboard). Astro includes support for linking to social platforms such as facebook, twitter, github etc. within this section. This is a short post to demonstrate the author panel which can be seen below…

Frontend Development

Responsive & Mobile Design

Responsive web design (RWD) is a web design approach aimed at crafting sites to provide an optimal viewing experience—easy reading and navigation with a minimum of resizing, panning, and scrolling—across a wide range of devices (from mobile phones to desktop computer monitors).

A site designed with RWD adapts the layout to the viewing environment by using fluid, proportion-based grids, flexible images,and CSS3 media queries, an extension of the @media rule.

  • The fluid grid concept calls for page element sizing to be in relative units like percentages, rather than absolute units like pixels or points.

  • Flexible images are also sized in relative units, so as to prevent them from displaying outside their containing element.

  • Media queries allow the page to use different CSS style rules based on characteristics of the device the site is being displayed on, most commonly the width of the browser.

  • Server-side components (RESS) in conjunction with client-side ones such as media queries can produce faster-loading sites for access over cellular networks and also deliver richer functionality/usability avoiding some of the pitfalls of device-side-only solutions.

Related Concepts

Audience and Device Aware (ADA)

Audience and Device Aware is an approach aimed at ensuring that a site is optimised to deliver what a user wants and that works effectively on the device being used to access the site. Unlike Responsive web design (RWD), which crafts a site visually for a range of devices, ADA aims to reflect the many different elements that enhance and impact on the performance and usability of a site. The predominant application for the ADA approach is for mobile and smaller screen devices. The principle truly sees the adoption of a “mobile first” strategy and focuses on the performance of a site and value that it delivers to a user and the business.

Mobile First

“Mobile first”, unobtrusive JavaScript, and progressive enhancement (strategies for when a new site design is being considered) are related concepts that predated RWD: browsers of basic mobile phones do not understand JavaScript or media queries, so the recommended practice is to create a basic web site, and enhance it for smart phones and PCs—rather than try graceful degradation to make a complex, image-heavy site work on the most basic mobile phones.

Frontend Development

Cascade Stylesheets

Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language. Its most common application is to style web pages written in HTML and XHTML, but the language can also be applied to any kind of XML document, including plain XML, SVG and XUL.

Cascading Style Sheets

Praesent malesuada leo quis varius tincidunt. Quisque tempor, tellus vitae imperdiet lacinia, arcu ante lacinia lectus, condimentum dictum nulla neque ut nunc. Cras cursus ultricies mauris sed dignissim. Integer blandit, quam eget sollicitudin placerat, metus tortor vestibulum tellus, facilisis pretium erat ligula a ipsum. Etiam tristique, eros in lacinia dictum, nibh sapien consequat sapien, ac varius sapien urna ut libero. Praesent vel euismod nunc. Curabitur a lacus turpis. Vivamus id tincidunt nisl. Suspendisse iaculis gravida tellus quis viverra. Quisque non tellus felis.

Declaration block

Cras lacus massa, posuere id pellentesque nec, pretium at urna. Cras gravida justo ut dui suscipit, nec convallis libero tincidunt. Donec ligula ipsum, adipiscing sed elementum eu, convallis non eros. Sed sit amet enim fermentum nibh feugiat luctus eu sit amet purus. Duis aliquam odio in urna cursus, sit amet convallis purus varius. Integer id enim tincidunt enim feugiat fermentum a non neque. Sed vel sap