<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Resume &#124; Martin Gontovnikas: Freelance Software Architect</title>
	<atom:link href="http://gon.to/feed/" rel="self" type="application/rss+xml" />
	<link>http://gon.to</link>
	<description>This is the Resume and Portfolio of Martin Gontovnikas (@mgonto): A software engineer currently working with Javascript, Node, AngularJS, Scala and Akka.</description>
	<lastBuildDate>Thu, 12 Jun 2014 02:14:48 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.3</generator>
	<item>
		<title>New Play Framework 2 Video Course: How to create WebApps</title>
		<link>http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/</link>
		<comments>http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/#comments</comments>
		<pubDate>Fri, 28 Jun 2013 18:28:55 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[Play! Framework]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[course]]></category>
		<category><![CDATA[play!]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://gon.to/?p=373</guid>
		<description><![CDATA[<p>TL;DR: I&#8217;ve created a new Play Framework Video Course. Please click here to check it out. Hey, I know there&#8217;re a lot of people trying to learn Play Framework 2, as they want a nicer and easier Java or Scala &#8230; <a href="http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/">New Play Framework 2 Video Course: How to create WebApps</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><strong><a href="https://www.packtpub.com/play-framework-for-web-application-development/video">TL;DR: I&#8217;ve created a new Play Framework Video Course. Please click here to check it out.</a><br />
</strong></p>
<p>Hey,</p>
<p>I know there&#8217;re a lot of people trying to learn Play Framework 2, as they want a nicer and easier Java or Scala framework than using Spring MVC, JSP, Servlets and so on.</p>
<p>This is why I&#8217;ve created jointly with PacktPub editorial a Play Framework 2 video course. In this course, you&#8217;ll learn how to create a WebApplication and you&#8217;ll learn it with a lot of examples and comparison. You&#8217;ll also learn how to create and consume REST APIs, how to secure your app, how to use Twitter Bootstrap and much much more.</p>
<p>After finishing the course you&#8217;ll be able to create your own app. If you have any questions or concerns, please contact me.</p>
<p>I hope you enjoy it. <strong><a href="https://www.packtpub.com/play-framework-for-web-application-development/video">To check it out, please click here.</a></strong></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/">New Play Framework 2 Video Course: How to create WebApps</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/06/28/new-play-framework-2-video-course-how-to-create-webapps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Angularytics: The solution to tracking page views and events in a SPA with AngularJS</title>
		<link>http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/</link>
		<comments>http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/#comments</comments>
		<pubDate>Tue, 04 Jun 2013 02:37:46 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[angularytics]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[kissmetrics]]></category>
		<category><![CDATA[pageview]]></category>
		<category><![CDATA[spa]]></category>
		<category><![CDATA[track]]></category>

		<guid isPermaLink="false">http://gon.to/?p=364</guid>
		<description><![CDATA[<p>TL;DR: Check out the Angularytics GitHub repo and quick bootstrap here Hey, We need Analytics to improve our app. However, most analytics (Like Google Analytics) aren&#8217;t yet fully prepared for Single Page Apps (SPA). Google Analytics tracks page views once &#8230; <a href="http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/">Angularytics: The solution to tracking page views and events in a SPA with AngularJS</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><strong><a href="https://github.com/mgonto/angularytics" target="_blank">TL;DR: Check out the Angularytics GitHub repo and quick bootstrap here</a></strong></p>
<p>Hey,</p>
<p><strong>We need Analytics to improve our app</strong>. However, <strong>most analytics</strong> (Like Google Analytics) <strong>aren&#8217;t yet fully prepared for Single Page Apps (SPA)</strong>. Google Analytics tracks page views once your browser refreshes the page, which in old pages meant changing the URL. <strong>Now, with AngularJS, we never refresh the page</strong>. We have a complete WebApp which changes URLs, changes resources, but never does a refresh. So, the question is <strong>how can we track page views and events now?</strong></p>
<p><strong>That&#8217;s why I&#8217;ve created Angularytics</strong>. Angularytics makes it easy to track page views and events. For now, it works with a console logger and with Google Analytics.</p>
<p><strong>In order to configure this to automatically track page views, all you need to do is the following:</strong></p>
<script src="https://gist.github.com/5703159.js"></script><noscript><pre><code class="language-javascript javascript">angular.module('sample-app', ['angularytics'])
  .config(function(AngularyticsProvider) {
    AngularyticsProvider.setEventHandlers(['Console', 'Google']);
  })
  .run(function(Angularytics) {
    Angularytics.init();
  });</code></pre></noscript>
<p><strong>Withi this, every time the URL changes in your SPA, Google is going to track this page view. Just 5 lines of code and you have this working in your SPA.</strong></p>
<p><strong></strong>Now, if you want to track events, you can do this by either using the trackEvent filter or the Angularytics service. <strong>The track event method signature is the same as the one in Google Analytics and <a href="https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide" target="_blank">can be checked by clicking here</a></strong></p>
<p><strong>Let&#8217;s see how we can use the filter</strong>. Imagine we want to track an event when a user clicks on certain button that actually calls a function in the scope.</p>
<script src="https://gist.github.com/5703172.js"></script><noscript><pre><code class="language-html html">&lt;label&gt;Click here to submit buddy&lt;/label&gt;

&lt;input type=&quot;submit&quot; 
  ng-click=&quot;doSomething() | trackEvent:'Home Category':'Button clicked'&quot; /&gt;</code></pre></noscript>
<p>Pretty easy, right?</p>
<p>Now, let&#8217;s see how we can do this in a service:</p>
<script src="https://gist.github.com/5703189.js"></script><noscript><pre><code class="language-javascript javascript">angular.controller('MainCtrl', function(Angularytics, $scope) {
    $scope.click = function() {
        Angularytics.trackEvent(&quot;Home Category&quot;, &quot;Button clicked&quot;);
    }
});</code></pre></noscript>
<p>This is it :). <strong>What do you think about this? I&#8217;d love your feedback :).</strong></p>
<p><a href="https://github.com/mgonto/angularytics" target="_blank">If you want to learn how to add an extra event handler like KissMetrics or for further information, please check on GitHub by clicking here.</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/">Angularytics: The solution to tracking page views and events in a SPA with AngularJS</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/06/03/angularytics-the-solution-to-tracking-page-views-and-events-in-a-spa-with-angularjs/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Check and inspect Angular&#8217;s scope for any DOM element in Developer Console from Chrome</title>
		<link>http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/</link>
		<comments>http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/#comments</comments>
		<pubDate>Thu, 30 May 2013 03:42:30 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[developer console]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[protip]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://gon.to/?p=351</guid>
		<description><![CDATA[<p>Hey guys, Today I come with a quick tip that you might not know. angular has a method where you can actually send either an element or a selector and angular will select that element. That element has some cool &#8230; <a href="http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/">Check and inspect Angular&#8217;s scope for any DOM element in Developer Console from Chrome</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Hey guys,</p>
<p>Today I come with a quick tip that you might not know.</p>
<p>angular has a method where you can actually send either an element or a selector and angular will select that element. That element has some cool functions that aren&#8217;t available if we select that element any other way.</p>
<p>One of this methods is <em>scope()</em>. It actually returns the scope binded to the selected element, which is really cool :). It also supports using $0 as the selector, so if we inspect some element in the developer console and then we do <em>angular.element($0).scope()</em> it will return the scope of the selected element.</p>
<p>I know that using the AngularJS developer console extension you can do this as well, but I actually hate that console. I&#8217;d rather do this and jsut work with the &#8220;regular&#8221; Developer console.</p>
<p>Check the following <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://gon.to/wp-content/uploads/2013/05/Screen-Shot-2013-05-30-at-12.34.50-AM.png" rel="lightbox" title="Check and inspect Angular's scope for any DOM element in Developer Console from Chrome" rel="lightbox"><img class="aligncenter  wp-image-352" alt="Screen Shot 2013-05-30 at 12.34.50 AM" src="http://gon.to/wp-content/uploads/2013/05/Screen-Shot-2013-05-30-at-12.34.50-AM-1024x198.png" width="475" height="92" /></a></p>
<p>I hope this works out for you guys <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/">Check and inspect Angular&#8217;s scope for any DOM element in Developer Console from Chrome</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/05/30/check-and-inspect-angulars-scope-for-any-dom-element-in-developer-console-from-chrome/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fix to Blank (Empty) pages in Google Analytics</title>
		<link>http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/</link>
		<comments>http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/#comments</comments>
		<pubDate>Tue, 21 May 2013 00:37:37 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[adblock]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[blank page]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://gon.to/?p=344</guid>
		<description><![CDATA[<p>Hey guys, This is a quick post on a fix that I&#8217;ve found for the Google Analytics problem. I&#8217;ve had been going to Google ANalytics page getting a blank screen. First I get a warning message above and then just &#8230; <a href="http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/">Fix to Blank (Empty) pages in Google Analytics</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Hey guys,</p>
<p>This is a quick post on a fix that I&#8217;ve found for the Google Analytics problem.</p>
<p>I&#8217;ve had been going to Google ANalytics page getting a blank screen. First I get a warning message above and then just a blank screen. I checked the HTML and there was just an iFrame so I didn&#8217;t know what was going on. Tried different browsers, deleting cookies, cache, etc.</p>
<p>The real problem is that AdBlock plugin from Chrome is actually blocking this page. So <strong>the solution is to go to the Extension options and whitelist analytics.google.com so that it&#8217;ll load.</strong></p>
<p>I hope this helps you. I&#8217;ve had this problem for a week and it was driving me nuts!</p>
<p>See ya!</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/">Fix to Blank (Empty) pages in Google Analytics</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/05/20/fix-to-blank-empty-pages-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Proposed Angular&#8217;s WebPage structure</title>
		<link>http://gon.to/2013/05/18/proposed-angulars-project-structure/</link>
		<comments>http://gon.to/2013/05/18/proposed-angulars-project-structure/#comments</comments>
		<pubDate>Sun, 19 May 2013 02:02:38 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[directive]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[inherit]]></category>
		<category><![CDATA[proposed]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://gon.to/?p=340</guid>
		<description><![CDATA[<p>Guideline on creating pages on AngularJS. This applies for angularizing per page and not a SPA. Basic Structure The basic idea is to have **one Main Controller** which will have in the scope all the common models and functions that &#8230; <a href="http://gon.to/2013/05/18/proposed-angulars-project-structure/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/18/proposed-angulars-project-structure/">Proposed Angular&#8217;s WebPage structure</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Guideline on creating pages on AngularJS. This applies for angularizing per page and not a SPA.</p>
<p><strong>Basic Structure</strong><br />
The basic idea is to have **one Main Controller** which will have in the scope all the common models and functions that will be used troughout the entire page. In Angular, if you have a child controller, that controlller&#8217;s scope will use prototypal inheritance with the MainCtrl. This means that the scope of the child controller will have all the models and functions from the MainCtrl.</p>
<p>Then, the page will have one controller per each main &#8220;view&#8221;. For example, if you have a page with 5 tabs, each of this tabs is a main view. Each view is different from the other. This views will actually be `ng-view` which means that they will be resolved by `$routeProvider`. So, each time you click on a tab, it actually changes the URL (for example `/properties/spaces`), once that URL changes, the controller defined in the `$routeProvider` will be used together with the template defined. This controller will be the view controller and will inherit from the main Controller.</p>
<p>Inside each view, we&#8217;ll be using directives for the different components of the page. If some of this components is reusable (can be used in another page/view), it **MUST** be defined with an isolated scope and it&#8217;ll receive via HTML attributes the parameters it needs to work. This ensures that the directive isn&#8217;t coupled to the parent as it doesn&#8217;t inherit the parent scope, which makes it easy to reuse it.<br />
If the directive we&#8217;re using is only to organize code and will not be reused in another view, we **CAN** inherit the parent scope (not making it isolated). However, if you want, you can make them isolated anyway.</p>
<p><strong>Reasons</strong><br />
Using this basic structure, we leverage scope inheritance and binding to get things done. If you modify a model in a directive, as it was inherited from the parent scope (or given to the directive via attribute if it&#8217;s isolated), the parent controller and the view from that controller will actually get notified when this happend and the HTML will be modified by itself.</p>
<p>If we need to also be notified of this changes, we can use the `$scope.$watch` function to watch some model for changes and get notified. This is exactly what the template uses to update itself.<br />
If we were to use events, we wouldn&#8217;t have this bidirectional binding, which makes creating with angular MUCH less useful.</p>
<p><strong>Example</strong></p>
<p>Let&#8217;s view an example of an app with this configuration.<br />
First, the main HTML will look something like this:</p>
<script src="https://gist.github.com/5606359.js"></script><noscript><pre><code class="language-html html">&lt;html&gt;
  &lt;head&gt;
    &lt;!-- Include here Styles and AngularJS scripts--&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class=&quot;container&quot; ng-app=&quot;example&quot; ng-controller=&quot;MainCtrl&quot; ng-cloak&gt;
      &lt;header&gt;
      &lt;div&gt;This is the common headers for all of the tabs of this little app&lt;/div&gt;
      &lt;/header&gt;
      &lt;!-- This is the div that will change when the URL changes via the $routeProvider--&gt;
      &lt;div ng-view&gt;
      &lt;/div&gt;
      &lt;footer&gt;&lt;div id=&quot;white-logo&quot;&gt;My Company Logo&lt;/div&gt;&lt;span id=&quot;copyright&quot;&gt;&amp;copy; 2013 My Company&lt;/span&gt;&lt;/footer&gt;
    &lt;/div&gt;
    
  &lt;/body&gt;
&lt;/html&gt;</code></pre></noscript>
<p>In here you can see we define the MainCtrl and then we define the ng-view to be used with the RouteProvider</p>
<p>Now, let&#8217;s see the app.js the app definition:</p>
<script src="https://gist.github.com/5606366.js"></script><noscript><pre><code class="language-javascript javascript">'use strict';

/**
* Application start point.
* 
* Note, we use minifyer, so all dependencies should be explicitly defined with ['&lt;dependency&gt;',
* function(&lt;dependency&gt;) {}];
*/
var module = angular.module('example',
  [ 'restangular', 'ngResource']).config(
  ['$routeProvider', '$locationProvider', 
  function($routeProvider, $locationProvider) {
    $routeProvider
    .when('/test/firstTab',
      {
      templateUrl: '/js/test/angular/views/firstTab.html',
      controller: 'FirstTabCtrl'
      })
    .when('/test/secondTab',
      {
      templateUrl: '/js/test/angular/views/secondTab.html',
      controller: 'SecondTabCtrl'
      })
    .otherwise({
      redirectTo: '/test/firstTab'
    });
    
  $locationProvider.html5Mode(true);
} ]);
</code></pre></noscript>
<p>Here we define for each URL the HTML to be used and the template for that URL.<br />
We then must define all of this controllers remembering that all we set in the MainCtrl will be visible in the rest.<br />
Now, let&#8217;s see an example of a directive, in the firstTab.html we have the following:</p>
<script src="https://gist.github.com/5606369.js"></script><noscript><pre><code class="language-html html">&lt;div&gt;
  &lt;h1&gt;First Tab&lt;/h1&gt;
  &lt;input type=&quot;text&quot; ng-model=&quot;query.searchText&quot; /&gt;
  &lt;pie data=&quot;data.valuesData | forPie&quot; type=&quot;valuesPie&quot; /&gt;
&lt;/div&gt;</code></pre></noscript>
<p>The first tab controller changes the searchText property of the query model. The query model is inherited from the MainCtrl. The MainCtrl is watching this query object for changes. Once it changes, it fetches some information from the server, and sets that in the valuesData property of the data model. This `data.valuesData` is being sent as a parameter to the pie directive, so as soon as it changes, the directive will be watching it. Let&#8217;s see the code of the directive.</p>
<script src="https://gist.github.com/5606372.js"></script><noscript><pre><code class="language-javascript javascript">module.directive('pie', function () {
  return {
    replace: true,
    restrict: 'EA',
    scope: {type: '@', data:'='},
    templateUrl: &quot;/js/test/angular/partials/pie.html&quot;,
    controller: ['$scope', '$routeParams', '$element', '$filter', function($scope, $routeParams, $element, $filter) {
    
      $scope.$watch('data', function() {
        if (_.isUndefined($scope.data) || _.isNull($scope.data) || $filter('isZeroData')($scope.data)) {
          $element.hide();
        } else {
          $element.show();
          $element.plot($scope.data);
        }
      });
    }]
  }
});</code></pre></noscript>
<p>In here we define an isolated scope. We set that the data HTML attribute will actually contain a scope variable name and that it&#8217;ll create a bidirectional asociation with it. This way, we can actually use a model from the parent scope, without inehriting the whole scope. Then, we set that the `type` attribute is just a string to be set in our current scope.<br />
Then, we watch the data for changes. If it changes and it&#8217;s either undefined or it has no data, we hide the pie element. Otherwise, we show it and we plot it using the data.</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/18/proposed-angulars-project-structure/">Proposed Angular&#8217;s WebPage structure</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/05/18/proposed-angulars-project-structure/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Enhancing Angular Promises: Returning new promise of field or method called from original promise&#8217;s result</title>
		<link>http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/</link>
		<comments>http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/#comments</comments>
		<pubDate>Fri, 03 May 2013 02:15:18 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[$q]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[enhanced]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[promise]]></category>

		<guid isPermaLink="false">http://gon.to/?p=331</guid>
		<description><![CDATA[<p>The title is kind of confusing as it&#8217;s really hard for me to explain what I want to enhance on Angular promises without actually showing. So, what&#8217;s the idea? You have a function that returns a promise for an object &#8230; <a href="http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/">Enhancing Angular Promises: Returning new promise of field or method called from original promise&#8217;s result</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>The title is kind of confusing as it&#8217;s really hard for me to explain what I want to enhance on Angular promises without actually showing.</p>
<p>So, what&#8217;s the idea? You have a function that returns a promise for an object A. Let&#8217;s assume that that object is an Array for our example. And what you want is actually the length fo that array. So, given the promise, instead of setting the callback for the value and then assigning that value to some variable and doing something, what we&#8217;re going to do is to apply a transformation. We&#8217;re going to transform this Promise of an Array to a Promise of a Number (the length). Normally, for this you actually set a function called map which transforms the A to B (once A is received) and therefore returns a Promise of B. Scala for example has map and flatMap for promises.</p>
<p>I implemented this without functions, using names of the fields or of the function. So, let&#8217;s see some code to finally understand this.</p>
<script src="https://gist.github.com/5506668.js"></script><noscript><pre><code class="language-javascript javascript">// This will return a promise of an Array
var promisedArray = $q.when([1,2,3]);

//Normal way of getting length in angular
promisedArray.then(function(arr) {
  var length = arr.length;
  // Do something with length in callback
})

//Using promises transformation
// This is a promise of a number
var lengthPromise = promisedArray.get('length');

//Calling methods
var biggerArrayPromise = promisedArray.call(&quot;push&quot;, {name: &quot;Gonto&quot;});</code></pre></noscript>
<p>So, what&#8217;s the usage of this? Angular already knows how to work with promises and how to resolve them when working with views. What this means is that if in our template we put <em>{{lengthPromise}}, </em>once the promise is resolved (value is returned), it will be shown in the HTML. Before, nothing will be shown. That&#8217;s thanks to using $q from Angular.</p>
<p>So, let&#8217;s see the implementation.</p>
<script src="https://gist.github.com/5506774.js"></script><noscript><pre><code class="language-javascript javascript">function enhancePromise(promise, isCollection) {
    promise.call = angular.bind(promise, promiseCall);
    promise.get = angular.bind(promise, promiseGet);
    return promise;
}

function promiseCall(method) {
    var deferred = $q.defer();
    var callArgs = arguments;
    this.then(function(val) {
        var params = Array.prototype.slice.call(callArgs, 1);
        var func = val[method];
        var result = func.apply(val, params);
        deferred.resolve(result);
    });
    return enhancePromise(deferred.promise);
}

function promiseGet(what) {
    var deferred = $q.defer();
    this.then(function(val) {
        deferred.resolve(val[what]);
    });
    return enhancePromise(deferred.promise);
}</code></pre></noscript>
<p>I&#8217;ve <a href="https://github.com/mgonto/restangular#enhanced-promises">implemented it in Restangular</a> but I&#8217;m thinking in creating an Angular module for this. Do you think it&#8217;d be useful?</p>
<p>That&#8217;s all folks</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/">Enhancing Angular Promises: Returning new promise of field or method called from original promise&#8217;s result</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/05/02/enhancing-angular-promises-returning-new-promise-of-field-or-method-called-from-original-promises-result/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Sharing Data, State and Models on AngularJS: Alternatives, comparison and my solution</title>
		<link>http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/</link>
		<comments>http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/#comments</comments>
		<pubDate>Wed, 01 May 2013 18:30:11 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[alternatives]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[share]]></category>
		<category><![CDATA[share data]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[state]]></category>

		<guid isPermaLink="false">http://gon.to/?p=325</guid>
		<description><![CDATA[<p>Once you start using AngularJS for all of your apps, you&#8217;ll see that each time your apps are bigger and they use more JS and Angular. At this point, the regular example of TODO list isn&#8217;t really useful anymore. At &#8230; <a href="http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/">Sharing Data, State and Models on AngularJS: Alternatives, comparison and my solution</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Once you start using AngularJS for all of your apps, <strong>you&#8217;ll see that each time your apps are bigger and they use more JS and Angular</strong>. At this point, the regular example of TODO list isn&#8217;t really useful anymore. At this point <strong>we really need to start sharing data and state.</strong> In other words, we need to have models that are known by several controllers and directives and we need to be able to be notified of this model changes.</p>
<p><strong>Once we realize this, we&#8217;ll see that there&#8217;re actually a bunch of options for doing so</strong>, and at first we don&#8217;t really know which is the best one. I&#8217;ve personally tried all of them, and have had to refactored the code sometimes as I ended up getting the unfourtenately-too-well-known spaghetti code.</p>
<p>Let&#8217;s first state all of the options:</p>
<p><strong>1) We can use Models as a service.</strong> What does this mean? We create a service that will actually be a model. This &#8220;service&#8221; will have state and data. So, each time we need to use this model, we just import it in the controller or in the directive and we use it to set or get values. But what about being notified? We can actually assign this &#8220;service&#8221; to a scope variable in the first line of our controller and then use the <em>$watch</em> method from the scope to see if it has changed. For example:</p>
<script src="https://gist.github.com/5497061.js"></script><noscript><pre><code class="language-javascript javascript">angular.module(&quot;test&quot;).service(&quot;Greeting&quot;, function() {
  this.greet = null;
  
  this.greetTo = function(name) {
    this.greet = &quot;Hello &quot; + name;
  }
});

angular.module(&quot;test&quot;).controller(&quot;TestCtrl&quot;, function(Greeting) {
  $scope.greeting = Greeting;
  
  $scope.$watch(&quot;greeting&quot;, function(){
    // The model has changed. Do something
  });
  
  $scope.greeting.greetTo(&quot;Gonto&quot;);
});</code></pre></noscript>
<p><strong>2) Using ng-include. </strong>Using ng-include, we can include some other piece of HTML. This HTML will have a new scope (ng-include does this) and will create a controller for it. So, we&#8217;ll have a Controller inheritance with ng-include. $scope is inherited as well (It uses prototypal inheritance), so when you call something in the child controller&#8217;s scope, if it&#8217;s not there, it&#8217;ll go look to the parent. We can get notified of changes using $watch as well.</p>
<p><strong>3) Using NOT isolated directives.</strong> This is very similar to the option #2. We can create some directives that will inherit scope from parent and share model like this. Remember that each directive can have a Controller. In this case Scope won&#8217;t be isolated.</p>
<p><strong>4) Using isolated directives. </strong>We can use directives with an isolated scope (declaring scope: {stuff: &#8216;=&#8217;} for example) so that we can actually reuse them easier. This directive don&#8217;t depend on the parent scope. They depend on getting some parameters from the parent. Those paramters are stated in the scope configuration of the directive declaration. In the example 2 lines above, we expect to get an attribute named stuff. The value will be name of the model from the parent to which we&#8217;ll have a bidirectional asociation. In this case, we can use $watch to get notified as well</p>
<p><strong>5) Using events. </strong>We can use events to comunicate between controllers, directives, etc. This events can carry extra information like a model. So we can say something like Greet Changed and sending in the event payload the new greeting. This way, all that want to know about it just gotta call the $on method from the scope stating the method name.</p>
<p><strong>Let&#8217;s compare them and find their advantages and disadvantages.</strong></p>
<p>As you can see, there&#8217;re a lot of options. Some of them are very similar, but have one or 2 differences.</p>
<p>I&#8217;ve started using events at first to decouple everything to the maximum. What&#8217;s the problem of this? That as we need to send this models or changes to model through events, we cannot rely or use the full advantages of the binding (bidirectional asociations) for models in scope. What does this mean? That I need to receive the event and manually set the value to some local scope variable. Then, the scope will taken as changed and then the DOM will change. This way, I need to send events receive them and a lot of boilerplate.</p>
<p>If we use option #2 or #3, as the scope variables are inherited, if we change in the child scope something in the model that was inherited, then the DOM from the parent controller (and the $watch functions) will get notified inmediately and the change will be done. This means that we don&#8217;t need to pass any value around. We just change this value where it needs to be changed and automatically this will be shown in the DOM, even if the HTML for what was changed actually &#8220;belongs&#8221; to the parent controller. But what is the disadvantage of this? Our directives and controllers are coupled with their parents. If the parent isn&#8217;t there, it doesn&#8217;t work.</p>
<p>So, at this point, we start thinking about #3 having isolated directives. But if a directive needs a lot of things from the parent, setting all this attributes in the directive declaration is a pain in the ass. And if we need some new attribute it&#8217;s not &#8220;magically inherited&#8221;, but we need to set it in the attribute and also define it in the scope definition from Directive.</p>
<p>Now, you&#8217;re thinking OK, Services models are the solution then. Well, I don&#8217;t really like it. You gotta set them to a scope variable at the first line if you want to get notified of stuff using $watch. If you have this service at multiple controllers in a &#8220;controller chain&#8221; of inehritance, you&#8217;d have this scope variable repeated all over the place in the scope. It might eventually make your app much slower, even more if this model is huge as it&#8217;s going to be in several scopes. But the good thing is that here, when we have a model dependency, it&#8217;s not implicit as with options #2 and #3, but it&#8217;s explicit, so it&#8217;s much easier to understand once it&#8217;s read.</p>
<p><strong>So, what&#8217;s the best?</strong> I don&#8217;t really know. <strong>I can tell you what I&#8217;ve chosen to use.</strong></p>
<p>Right now, I&#8217;m using #3 and #4. I like directives more than ng-include as they&#8217;re much more declarative and the HTML is very clear. ng-include and NOT isolated directive are VERY similar. Also another cool thing about directives is that I can transclude them.</p>
<p>So what I do is, I have always one parent controller that has all the important variables and methods for the whole page (for example if it has a lot of tabs). Then, I have one controller per tab (the one changed with the Route). Then, I try to divide most of the things in Directives. If the thing I&#8217;m coding is reusable in some other stuff, I use an isolated directive. When it&#8217;s isolated, the &#8220;dependencies&#8221; are explicit and it&#8217;s much easier to reuse. If I don&#8217;t want to reuse the directive, but I just use it to organize code and also need a lot of variables from the parent, then I use a NOT isolated directive. This approach has worked for me VERY well.</p>
<p>&nbsp;</p>
<p>So, it&#8217;s time for u guys to try. Tell me which option you like the more, which one you&#8217;re using and why :).</p>
<p>Happy coding!!</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/">Sharing Data, State and Models on AngularJS: Alternatives, comparison and my solution</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/05/01/sharing-data-state-on-angularjs-alternatives-comparison-and-my-solution/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>New features on Restangular: the ultimate Rest API client for Angular</title>
		<link>http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/</link>
		<comments>http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/#comments</comments>
		<pubDate>Sat, 27 Apr 2013 01:44:06 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restangular]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[ultimate]]></category>

		<guid isPermaLink="false">http://gon.to/?p=304</guid>
		<description><![CDATA[<p>Hey, I&#8217;ve been working more and more on Restangular and added a bunch of more features. You don&#8217;t know about it yet? Click here to find out @Github Let&#8217;s get down to business. What are the cool new features? &#160; &#8230; <a href="http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/">New features on Restangular: the ultimate Rest API client for Angular</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Hey,</p>
<p>I&#8217;ve been working more and more on Restangular and added a bunch of more features. <strong><a style="font-size: 15px;" href="https://github.com/mgonto/restangular" target="_blank">You don&#8217;t know about it yet? Click here to find out @Github</a></strong></p>
<p>Let&#8217;s get down to business. What are the cool new features?</p>
<p>&nbsp;</p>
<p><strong>1) You can now do URL Building with Restangular:</strong></p>
<p>Sometimes, we have a lot of entities names with their ids and we just want to fetch the later entity. In those cases, doing a request for everything to get the last entity is an overkill. For those cases, I&#8217;ve added the possibility to create URLs using the same API as creating a new Restangular object. This connections are created without doing any request. Let&#8217;s see how to do this:</p>
<script src="https://gist.github.com/5471520.js"></script><noscript><pre><code class="language-javascript javascript">var restangualrSpaces = Restangular.one(&quot;accounts&quot;,123).one(&quot;buildings&quot;, 456).all(&quot;spaces&quot;);

// This will do ONE get to /accounts/123/buildings/456/spaces
restangularSpaces.getList()

// This will do ONE get to /accounts/123/buildings/456/spaces/789
Restangular.one(&quot;accounts&quot;, 123).one(&quot;buildings&quot;, 456).one(&quot;spaces&quot;, 789).get()

// POST /accounts/123/buildings/456/spaces
Restangular.one(&quot;accounts&quot;, 123).one(&quot;buildings&quot;, 456).all(&quot;spaces&quot;).post({name: &quot;New Space&quot;});</code></pre></noscript>
<p><strong>2) Now you can manually run any custom Rest operation that&#8217;s not 100% Restful anyway.</strong></p>
<p>Sometimes our APIs have other operations besides the regular one. For example <em>/messages/123/archive</em> or <em>/messages/clear-all</em> For those cases, we can now use Restangular anyway. Restangular provides a set of &#8220;customOPERATION&#8221; methods like <em>customGET, customPOST, customGETLIST, customPUT. </em>Let&#8217;s see an example</p>
<script src="https://gist.github.com/5471535.js"></script><noscript><pre><code class="language-javascript javascript">//GET /messages/123/archive
Restangular.one(&quot;messages&quot;, 123).customGET(&quot;archive&quot;)

//POST /messages/clear-all?param=param2 with body of {force: true}
Restangular.all(&quot;messages&quot;).customPOST(&quot;clear-all&quot;, {param: &quot;param2&quot;}, {}, {force: true})</code></pre></noscript>
<p><strong>3) You can also create your own Restangular methods and extend it as you want.</strong></p>
<p>Let&#8217;s assume that your API needs some custom methods to work. If that&#8217;s the case, always calling customGET or customPOST for that method with all parameters is a pain in the ass. That&#8217;s why every element has a <code>addRestangularMethod</code> method. This can be used together with the hook <code>setOnElemRestangularized</code> to do some neat stuff. Let&#8217;s see an example to learn this.</p>
<script src="https://gist.github.com/5471539.js"></script><noscript><pre><code class="language-javascript javascript">//In your app configuration (config method)
RestangularProvider.setOnElemRestangularized(function(elem, isCollection, route) {
    if (!isCollection &amp;&amp; route === &quot;buildings&quot;) {
        // This will add a method called evaluate that will do a get to path evaluate with NO default
        // query params and with some default header
        // signature is (name, operation, path, params, headers, elementToPost)
        elem.addRestangularMethod('evaluate', 'get', 'evaluate', undefined, {'myHeader': 'value'});
    }
    return elem;
})

// Then, later in your code you can do the following:

//GET to /buildings/123/evaluate?myParam=param with headers myHeader: value
//Signature for this &quot;custom created&quot; methods is (params, headers, elem)
// If something is set to any of this variables, the default set in the method creation will be overrided
// If nothing is set, then the defaults are sent
building.evaluate({myParam: 'param'});

//GET to /buildings/123/evaluate?myParam=param with headers myHeader: specialHeaderCase
building.evaluate({myParam: 'param'}, {'myHeader': 'specialHeaderCase'});</code></pre></noscript>
<p><strong>4) It&#8217;s now available in a CDN.</strong></p>
<script src="https://gist.github.com/5486677.js"></script><noscript><pre><code class="language-html html">&lt;!-- Use LATEST folder to always get the latest version--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.jsdelivr.net/restangular/latest/restangular.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.jsdelivr.net/restangular/latest/restangular.min.js&quot;&gt;&lt;/script&gt;

&lt;!-- Or use TAG number for specific version --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.jsdelivr.net/restangular/0.5.3/restangular.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.jsdelivr.net/restangular/0.5.3/restangular.min.js&quot;&gt;&lt;/script&gt;</code></pre></noscript>
<p><strong>5) Now you can send your own Headers</strong></p>
<p>Every method in Restangular now accepts custom Query parameters and custom Headers as parameters.</p>
<p><strong>6) Now you can use any response format in Restangular</strong></p>
<p><strong></strong>Let&#8217;s assume that you have a Response that&#8217;s actually wrapped in some Object with some Metadata and that your List of element isn&#8217;t an array. If that&#8217;s the case, you can now use Restangular anyway thanks to the <em>responseInterceptor</em> and the <em>responseExtractor.</em></p>
<script src="https://gist.github.com/5486697.js"></script><noscript><pre><code class="language-javascript javascript">app.config(function(RestangularProvider) {
    // First let's set listTypeIsArray to false, as we have the array wrapped in some other object.
    RestangularProvider.setListTypeIsArray(false);

    // Now let's configure the response extractor for each request
    RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
      var newResponse;
      // This is a get for a list
      if (operation === &quot;getList&quot;) {
        // First the newResponse will be response.objects which is actually an array
        newResponse = response.objects;
        // Then we add to this array a special property containing the metadata for paging for example
        newResponse.metadata = response.data.meta;
      } else {
        // If it's an element, then we just return the &quot;regular&quot; response as there's no object wrapping it
        newResponse = response;
      }
      return newResponse;
    });
});</code></pre></noscript>
<p><strong>7) Restangularized promises</strong></p>
<p><strong></strong>Now all promises are enhanced as well. You can for example add a new element to the promise of an array returned by getList without calling the then. It will return a new Promise of the edited array, which you can use in your view as Angular knows how to handle promises. Take a look</p>
<script src="https://gist.github.com/5507508.js"></script><noscript><pre><code class="language-javascript javascript">var buildings = Restangular.all(&quot;buildings&quot;).getList();

// New promise after adding the new building
// Now you can show in scope this newBuildings promise and it'll show all the buildings 
// received from server plus the new one added
var newBuildings = buildings.push({name: &quot;gonto&quot;});

var newBuildingsSame = buildings.call(&quot;push&quot;, {name: &quot;gonto&quot;});

// This is a promise of a number value. You can show it in the UI
var lengthPromise = buildings.get(&quot;length&quot;);

lengthPromise.then(function(length) {
  // Here the length is the real length value of the returned collection of buildings
});</code></pre></noscript>
<p>That&#8217;s it for now!</p>
<p>If you have ANY suggestion on something to add, please create an Issue at Github or comment it here</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/">New features on Restangular: the ultimate Rest API client for Angular</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/04/26/new-features-on-restangular-the-ultimate-rest-api-client-for-angularjs/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Automatically download &amp; use FrontEnd JS dependencies with Bower + Grunt boilerplate free</title>
		<link>http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/</link>
		<comments>http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 02:14:41 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[bower]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[grunt]]></category>
		<category><![CDATA[gruntfile]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[restangular]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://gon.to/?p=300</guid>
		<description><![CDATA[<p>Hey, Today I wanted to talk a little about Bower and Grunt. Bower is a package manager for FrontEnd JS dependencies mostly. You create your bower.json (components.json before, now depracated), put all of your dependencies in that file, and then &#8230; <a href="http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/">Automatically download &#038; use FrontEnd JS dependencies with Bower + Grunt boilerplate free</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Hey,</p>
<p>Today I wanted to talk a little about Bower and Grunt.</p>
<p><em><strong>Bower</strong></em> is a package manager for FrontEnd JS dependencies mostly. You create your <em>bower.json</em> (<em>components.json</em> before, now depracated), put all of your dependencies in that file, and then just run <em>bower install</em>. That will download all of those dependencies and copy them to components/ folder inside your project. However, this will download the WHOLE git tag, which has a lot of boilerplate you won&#8217;t need like README, build files, and so on. Bower tells you to link to the file in /components/angular/angular.js but I don&#8217;t really like that. I&#8217;d rather those dependencies are copied to my &#8220;output&#8221; folder or something like that but that&#8217;s not possible with Bower out of the box.</p>
<p>That&#8217;s where <em><strong>Grunt</strong></em><strong> </strong>comes to play :). Grunt is a Javascript Task runner. It&#8217;s very similar to Rake. It lets you add tasks and execute them sequentially.</p>
<p><strong>What I want to show you guys is how to just run <em>grunt</em> and it will download bower dependencies automatically and copy only the main file to some output folder you want, without all that components boilerplate. Pretty neat right?</strong></p>
<p>So, what do you need to do</p>
<p>1) Install NODE + NPM. I recommend installing it with <a href="https://github.com/creationix/nvm">NVM</a> but it&#8217;s just a matter of choice.</p>
<p>2) Install grunt to be used everywhere in your enviroment. That can be done running <em>npm install grunt-cli -g</em></p>
<p>3) Install bower to be used everywhere in your enviroment. That can be done running <em>npm install bower -g</em></p>
<p>4) After this, we have everything configured to start working. Grunt also supports adding some plugins to run some cool tasks. Those plugins will be downloaded for this specific case. For that, we can create a <em>package.json</em> and npm will then take care of installing all of this plugins when running npm install. So, create a package.json like this:</p>
<script src="https://gist.github.com/5464644.js"></script><noscript><pre><code class="language-json json">{
  &quot;name&quot;: &quot;restangular&quot;,
  &quot;description&quot;: &quot;Restfull Resources service for AngularJS apps&quot;,
  &quot;version&quot;: &quot;0.5.3&quot;,
  &quot;filename&quot;: &quot;restangular.min.js&quot;,
  &quot;homepage&quot;: &quot;https://github.com/mgonto/restangular&quot;,
  &quot;author&quot;: &quot;Martin Gontovnikas &lt;martin@gonto.com.ar&gt;&quot;,
  &quot;dependencies&quot;: {},
  &quot;devDependencies&quot;: {
    &quot;grunt-cli&quot;: &quot;&gt;= 0.1.7&quot;,
    &quot;grunt-bower&quot;: &quot;*&quot;,
    &quot;grunt-bower-task&quot;: &quot;*&quot;,
  }
}</code></pre></noscript>
<p>Take a special look into the devDependencies. In there, we&#8217;re stating that we need 2 bower plugins that we&#8217;ll use later.</p>
<p>5) Create your <em>bower.json </em>with the dependencies you need. You can either create one similar to the next one or running <em>bower init</em> to follow some guide to create it:</p>
<script src="https://gist.github.com/5464653.js"></script><noscript><pre><code class="language-json json">{
  &quot;name&quot;: &quot;restangular&quot;,
  &quot;version&quot;: &quot;0.5.3&quot;,
  &quot;main&quot;: &quot;./dist/restangular.min.js&quot;,
  &quot;description&quot;: &quot;Restfull Resources service for AngularJS apps&quot;,
  &quot;repository&quot;: {
    &quot;type&quot;: &quot;git&quot;,
    &quot;url&quot;: &quot;git://github.com/mgonto/restangular.git&quot;
  },
  &quot;dependencies&quot;: {
    &quot;underscore&quot;: &quot;&gt;= 1.4.4&quot;,
    &quot;angular&quot;: &quot;*&quot;,
    &quot;angular-resource&quot;: &quot;*&quot;
  },
  &quot;ignore&quot;: [
    &quot;node_modules&quot;,
    &quot;components&quot;,
    &quot;lib&quot;
  ]
}</code></pre></noscript>
<p>6) Now, we have everything we need to start creating our <em>Gruntfile.js</em>. This file is the one read when running grunt in that directory. Check this Gruntfile. I&#8217;ll explain it below <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> <em><br />
</em></p>
<script src="https://gist.github.com/5464661.js"></script><noscript><pre><code class="language-javascript javascript">'use strict';

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    dirs: {
      dest: 'dist'
    },
    bower: {
      dev: {
        dest: '&lt;%= dirs.dest %&gt;/dependencies'
      }
    },
    bowerInstall: {
        install: {
        }
    },
  });

  grunt.loadNpmTasks('grunt-bower-task');

  grunt.renameTask(&quot;bower&quot;, &quot;bowerInstall&quot;);

  grunt.loadNpmTasks('grunt-bower');

  // Default task.
  grunt.registerTask('default', ['build']);

  // Build task.
  grunt.registerTask('build', ['bowerInstall', 'bower']);
};</code></pre></noscript>
<p>So, let&#8217;s explain this step by step. With <em>loadNpmTasks </em>we&#8217;re loading some plugin. As that plugin has been installed with npm install, it&#8217;ll be available through an npm task. As you can see, we import the 2 devDependencies we added in the package.json. The problem is that both of those dependencies actually define a task named bower, so by default I can&#8217;t import both as one would override the other. That&#8217;s why I first import one, then rename that one, and then I import the other. <em>grunt-bower-task</em> will take care of running bower install. <em>grunt-bower</em> will take care of retrieving the main file of each dependency and copy it somewhere.</p>
<p>As you can see above this loadNpmTasks, we call an initConfig method. In there we configure the tasks. First, we create a dirs object with a dest property that points to &#8220;dist&#8221;. That&#8217;s actually our output folder. We can change that to whatever we want. Then, we configure the bower task with the dev action. In there, we configure where to put the main dependency file that&#8217;s retrieved from components folder. There, we use the dirs.dest variable we configured and we put them in a &#8220;dependencies&#8221; folder inside there.</p>
<p>Then, I just configure that running <em>grunt</em> by default will call the build task, which first installs all dependencies and then copies them to where they&#8217;re needed.</p>
<p>That&#8217;s it! This is all we need to configure.</p>
<p>Now, you can just run:</p>
<p><em>npm install</em></p>
<p><em>grunt</em></p>
<p>And now you have all of your dependencies copied to /dist/dependencies. <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" />  Just 2 commands after the configuration has been done.</p>
<p>I actually use this approach in <a href="https://github.com/mgonto/restangular">Restangular, so you can check it out there.</a></p>
<p>I hope this helps you and that you can use this <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/">Automatically download &#038; use FrontEnd JS dependencies with Bower + Grunt boilerplate free</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/04/25/automatically-download-use-frontend-js-dependencies-with-bower-grunt-boilerplate-free/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Restangular: New AngularJS framework to handle Rest API Restful Resources properly and easily</title>
		<link>http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/</link>
		<comments>http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 00:20:04 +0000</pubDate>
		<dc:creator><![CDATA[mgonto]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[Rest]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[play!]]></category>
		<category><![CDATA[Play! Framework]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[rest api]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[underscore]]></category>

		<guid isPermaLink="false">http://gon.to/?p=284</guid>
		<description><![CDATA[<p>Hey, I&#8217;ve been working with AngularJS this past months and I&#8217;ve extracted one service that I&#8217;ve created to facilitate the usage of Restful Resources. Nowadays, we work with Rest APIs on a daily basis. We&#8217;re also starting to use AngularJS &#8230; <a href="http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/">Continued</a></p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/">Restangular: New AngularJS framework to handle Rest API Restful Resources properly and easily</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Hey,</p>
<p>I&#8217;ve been working with AngularJS this past months and I&#8217;ve extracted one service that I&#8217;ve created to facilitate the usage of Restful Resources. Nowadays, we work with Rest APIs on a daily basis. We&#8217;re also starting to use AngularJS more and more each day as it makes us be much more productive. Restangular will make it even easier to work with the Rest APIs that we&#8217;ve implemented. <strong><a style="font-size:16px" href="https://github.com/mgonto/restangular" target="_blank">You can click here to check it out on GitHub</a></strong>.</p>
<p><strong>What&#8217;s the idea of this Framework?</strong></p>
<p><strong></strong>We&#8217;re used to creating REST APIs using Resources in our BackEnd. However, when using AngularJS it&#8217;s not easy to work with them using $resource and $http. I&#8217;ve built a service that will help you get, update and delete resources following the &#8220;tree&#8221; that you&#8217;ve created. I&#8217;ve tried this out with Play! Framework and Ruby On Rails and this fits perfectly with both.</p>
<p><b>How can I add this?</b></p>
<p>In order to add this, you must download restangular.js <a href="https://raw.github.com/mgonto/restangular/master/dist/restangular.js">from here</a> and then link to it in your HTML file. <strong>Restangular depends only on angular, angular-resource and underscore.</strong> After this, you must just declare the dependency to your app.</p>
<script src="https://gist.github.com/5350606.js"></script><noscript><pre><code class="language-javascript javascript">var app = angular.module('angularjs-starter', ['restangular']);

// Using RestangularProvider we can configure properties. To check all properties go to https://github.com/mgonto/restangular
app.config(function(RestangularProvider) {
  RestangularProvider.setBaseUrl('/api/v1');
});

// Here it injects Restangular by itself
angular.module('angularjs-starter').controller('NewCtrl', function($scope, Restangular) {
  // My controller
});
</code></pre></noscript>
<p><strong>Let&#8217;s start using it!!!</strong></p>
<p>I think that the best introduction for a Framework is Code. So let&#8217;s code <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<script src="https://gist.github.com/5350615.js"></script><noscript><pre><code class="language-javascript javascript">// First way of creating a Restangular object. Just saying the base URL
var baseAccounts = Restangular.all('accounts');

// This will query /accounts and return a promise. As Angular supports setting promises to scope variables
// as soon as we get the information from the server, it will be shown in our template :)
$scope.allAccounts = baseAccounts.getList();

var newAccount = {name: &quot;Gonto's account&quot;};

// POST /accounts
baseAccounts.post(newAccount);

//Here we use Promises then 
// GET /accounts
baseAccounts.getList().then(function (accounts) {
  // Here we can continue fetching the tree :).

  var firstAccount = accounts[0];
  // This will query /accounts/123/buildings considering 123 is the id of the firstAccount
  $scope.buildings = firstAccount.getList(&quot;buildings&quot;);

  // GET /accounts/123/places?query=param with request header: x-user:mgonto
  $scope.loggedInPlaces = firstAccount.getList(&quot;places&quot;, {query: param}, {'x-user': 'mgonto'})

  // This is a regular JS object, we can change anything we want :) 
  firstAccount.name = &quot;Gonto&quot;

  // PUT /accounts/123. The name of this account will be Gonto from now on
  firstAccount.put();

  // DELETE /accounts/123 We don't have first account anymore :(
  firstAccount.remove();

  var myBuilding = {
    name: &quot;Gonto's Building&quot;,
    place: &quot;Argentina&quot;
  };

  // POST /accounts/123/buildings with MyBuilding information
  firstAccount.post(&quot;Buildings&quot;, myBuilding).then(function() {
    console.log(&quot;Object saved OK&quot;);
  }, function() {
    console.log(&quot;There was an error saving&quot;);
  });

  // GET /accounts/123/users?query=params
  firstAccount.getList(&quot;users&quot;, {query: params}).then(function(users) {
    // Instead of posting nested element, a collection can post to itself
    // POST /accounts/123/users
    users.post({userName: 'unknown'});

    // Custom methods are available now :).
    // GET /accounts/123/users/messages?param=myParam
    users.customGET(&quot;messages&quot;, {param: &quot;myParam&quot;})

    var firstUser = users[0];

    // GET /accounts/123/users/456. Just in case we want to update one user :)
    $scope.userFromServer = firstUser.get();

    // ALL http methods are available :)
    // HEAD /accounts/123/users/456
    firstUser.head()

  });

}, function errorCallback() {
  alert(&quot;Oops error from server :(&quot;);
})

// Second way of creating Restangular object. URL and ID :)
var account = Restangular.one(&quot;accounts&quot;, 123);

// GET /accounts/123?single=true
$scope.account = account.get({single: true});

// POST /accounts/123/messages?param=myParam with the body of name: &quot;My Message&quot;
account.customPOST(&quot;messages&quot;, {param: &quot;myParam&quot;}, {}, {name: &quot;My Message&quot;})</code></pre></noscript>
<p>That&#8217;s it <img src="http://gon.to/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" />  Please tell me what you guys think! If you want to read more about Restangular <a href="https://github.com/mgonto/restangular">You can click here to check it out</a>.</p>
<p>The post <a rel="nofollow" href="http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/">Restangular: New AngularJS framework to handle Rest API Restful Resources properly and easily</a> appeared first on <a rel="nofollow" href="http://gon.to">Resume | Martin Gontovnikas: Freelance Software Architect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gon.to/2013/04/09/restangular-new-angular-framework-to-handle-restful-resources-properly-and-easily/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Application Monitoring using New Relic

 Served from: gon.to @ 2014-12-11 04:16:19 by W3 Total Cache -->