CSC/ECE 517 Fall 2014/ch1b 34 kr: Difference between revisions
Line 59: | Line 59: | ||
BackboneJS doesn't provide any templating engine of its own but AngularJS and EmberJS have there own templating system. The difference between the templating engines of the three frameworks can be understood from the following examples : | BackboneJS doesn't provide any templating engine of its own but AngularJS and EmberJS have there own templating system. The difference between the templating engines of the three frameworks can be understood from the following examples : | ||
====AngularJS==== | =====AngularJS===== | ||
Angular's templating engine simply extends HTML syntax. It uses binding expressions to bind variables between controllers and models. These binding expressions are enclosed by doubly curly braces. | Angular's templating engine simply extends HTML syntax. It uses binding expressions to bind variables between controllers and models. These binding expressions are enclosed by doubly curly braces. For example: | ||
<pre> | <pre> | ||
Line 72: | Line 72: | ||
</pre> | </pre> | ||
====EmberJS==== | =====EmberJS===== | ||
EmberJS uses Handlebars template engine. Handlebars is an extension of Mustache templating engine. It does not understand the DOM structure so it is not aware of the context in which it is being used. It just does the simple string transformation. Another templating engine is being developed called HTMLBars which works on these flaws of the Handlebars. | EmberJS uses Handlebars template engine. Handlebars is an extension of Mustache templating engine. It does not understand the DOM structure so it is not aware of the context in which it is being used. It just does the simple string transformation. Another templating engine is being developed called HTMLBars which works on these flaws of the Handlebars. For example: | ||
<pre> | <pre> | ||
Line 83: | Line 83: | ||
</li> | </li> | ||
{{/each}} | {{/each}} | ||
</ul> | |||
</pre> | |||
=====BackboneJS===== | |||
BackboneJS doesn't have any templating engine of its own but it can be integrated with many third party templating engines. Since, Underscore is a Backbone dependency so it is used by default for the templating purposes. But, underscore has a very basic templating engine and it has to be used in the mix with javascript. For example: | |||
<pre> | |||
<ul> | |||
<% _.each(recipes, function(recipe) { %> | |||
<li title="<%- recipe.name %>"> | |||
<%- recipe.desc %> | |||
</li> | |||
<% }); %> | |||
</ul> | </ul> | ||
</pre> | </pre> |
Revision as of 20:49, 6 October 2014
AngularJS + Rails
Overview
AngularJS is an open source client-side Javascript framework for creating web applications with dynamic web pages and is maintained by Google. AngularJS has extended HTML's syntax and implemented it with Model-View-Controller architecture so that the various components of Javascript can be expressed clearly. It provides functionalities like data binding and dependency injection which helps shorten the crude javascript code. It has a simple object model that supports testability and clean code organization.
Rails is an open source web application framework written in Ruby by David Heinemeier Hansson. It is extremely productive for developing database-backed web applications. It uses Model-View-Controller architecture and requires fewer total lines of code than other frameworks thus making it atleast ten times faster.
Background
AngularJS
AngularJS was developed by Misko Hevery and Adam Abrons at Brat Tech LLC in 2009 as the software behind an oline JSON storage service. Later, it was released as an open source library. The library is being developed and maintained by Hevery with his fellow Google employees.
Rails
Rails was extracted from Basecamp, a project management tool by 37signals but it was released as an open source project in July 2004. It gained fame after Apple decided to ship it with Mac OS X, which was released in October 2007.
Why AngularJS + Rails?
One of the key reasons of using AngularJs is API-Driven Application approach, i.e. separation of User Interface from back-end (Rails in our case). Increasing number of application these days (Rails Application) are building their own APIs which can they interface with mobile applications (like iOS), or other developer applications can communicate with their applications, and in our case to communicate with front-end applications. By following this paradigm, developers gets an opportunity to build a front-end as well as back-end APIs along with your application, it means front-end exposes its methods to the JSON API in the back-end and the front-end API can be clubbed with any back-end and vice-versa without any need for re-configuration.
So the question is why to club AngularJS with Rails and what are its advantages? AngularJS is a front-end framework, what this means is, it is designed to run on the client side, therefore for any real application requiring CRUD operations a back-end is necessary. This is where Rails comes into picture, it provides a back-end to the AngularJS application so that large amount of data can be stored in database. Another issue with using standalone AngularJS application is that it creates Single-page Applications (SPA), i.e. the same page or components on the page gets refreshed, which makes Search Engine Optimization extremely tricky, as a result the possibility of making the web page searchable reduces drastically. Whereas in case of Rails the web pages are rendered by Rails on the server, which makes them available to Google for SEO based search.
Getting Started
Pre-requisite
In order to get started with AngularJS you should must know HTML, CSS & JavaScript. Add-on advantage if you know: Test Driven Development and Behavioral Driven Development. From Rails's point of view you should have working knowledge of Ruby language.
Comparison with other front-end frameworks
The most popular front end frameworks these days include AngularJS, BackboneJS and EmberJS. These can be compared on the basis of the following factors<ref>http://www.airpair.com/js/javascript-framework-comparison</ref>:
Community
Community is the most important factor to consider when choosing a framework as a strong and large community means strong support and help towards the framework. More questions will be answered, more tutorials will be available. In short, larger the community means more the number of resources to exploit.
So, if compared on the basis of community, AngularJS is the clear winner as there are more StackOverflow questions, YouTube videos, GitHub Contributors available for Angular then the rest of the frameworks. Also, in the recent years AngularJS has gained more and more popularity compared to the other two.
Framework Size
For a website to be successful, it should have good page load speed as users these days need good speed of browsing. In order to load pages fast, the front end framework should be as small as possible so that they can be loaded faster. If we compare the sizes of the frameworks, BackboneJS (6.5 kb) is the smallest among AngularJS(39.5 kb) and EmberJS(90 kb). But, BackboneJS needs UnderscoreJS(5 kb) and jQuery(32 kb) along with some other third party plugins which makes the size large. Thus, AngularJS is the clear winner among these frameworks.
Templating
BackboneJS doesn't provide any templating engine of its own but AngularJS and EmberJS have there own templating system. The difference between the templating engines of the three frameworks can be understood from the following examples :
AngularJS
Angular's templating engine simply extends HTML syntax. It uses binding expressions to bind variables between controllers and models. These binding expressions are enclosed by doubly curly braces. For example:
<ul> <li ng-repeat="recipe in recipes" title="{{recipe.title}}"> {{recipe.description}} </li> </ul>
EmberJS
EmberJS uses Handlebars template engine. Handlebars is an extension of Mustache templating engine. It does not understand the DOM structure so it is not aware of the context in which it is being used. It just does the simple string transformation. Another templating engine is being developed called HTMLBars which works on these flaws of the Handlebars. For example:
<ul> {{#each recipes}} <li {{bind-attr title=name}}> {{desc}} </li> {{/each}} </ul>
BackboneJS
BackboneJS doesn't have any templating engine of its own but it can be integrated with many third party templating engines. Since, Underscore is a Backbone dependency so it is used by default for the templating purposes. But, underscore has a very basic templating engine and it has to be used in the mix with javascript. For example:
<ul> <% _.each(recipes, function(recipe) { %> <li title="<%- recipe.name %>"> <%- recipe.desc %> </li> <% }); %> </ul>
Reference Material
References
<references/>
Name | AngularJS + Rails |
Category | Open Source Software |
Type | Web Application Framework |