<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Transient Obsessions]]></title>
  <link href="http://www.martiplanellas.info/blog/atom.xml" rel="self"/>
  <link href="http://www.martiplanellas.info/blog/"/>
  <updated>2014-03-28T20:00:16+00:00</updated>
  <id>http://www.martiplanellas.info/blog/</id>
  <author>
    <name><![CDATA[Martí Planellas]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[How to Make a Web Component]]></title>
    <link href="http://www.martiplanellas.info/blog/27/03/2014/how-to-make-a-web-component/"/>
    <updated>2014-03-27T17:12:53+00:00</updated>
    <id>http://www.martiplanellas.info/blog/27/03/2014/how-to-make-a-web-component</id>
    <content type="html"><![CDATA[<p>I choose the <a href="https://github.com/beldar/display-rss">display-rss</a>  component because it&rsquo;s simple and has most of the use cases you would find in a web component.</p>

<p>What the component does basically loads any RSS feed and displays it</p>

<h2>Starting up</h2>

<p>We&rsquo;ll be using <a href="http://www.polymer-project.org/">Polymer</a> as the library for the polyfills and creation of the element, and the help of <a href="http://yeoman.io/">Yeoman</a>  the tool I told you about in <a href="http://www.martiplanellas.info/blog/24/03/2014/the-yeoman-workflow/">another post</a>, and you will need to have <a href="http://nodejs.org/">NodeJS</a> installed too.</p>

<p>We&rsquo;ll begin by stalling Yeoman:</p>

<pre><code>npm install -g yo
</code></pre>

<p>Then we&rsquo;ll install the Polymer Generator</p>

<pre><code>npm install -g generator-polymer
</code></pre>

<p>Then create a new folder <code>mkdir my-element &amp;&amp; cd $_</code></p>

<p>And start the generator <code>yo polymer</code></p>

<p>This will create the base app structure, and will also install <a href="http://gruntjs.com/">grunt</a> and <a href="http://bower.io/">bower</a>, go make a cup of tea.</p>

<p>Once all dependencies are downloaded we can create our element using:</p>

<pre><code>yo polymer:element my-element
</code></pre>

<p>This command will ask us if we want to include a constructor, we mark the check, and we also mark that we want to import to our index.html using HTML imports.</p>

<p>Then it will ask if we want to import local elements, we leave blank.</p>

<p>Then it will ask if we want to import installed Bower elements, we are going to write <code>polymer-json</code> since we&rsquo;ll be using it later.</p>

<p>Finally this will create our element in <code>app/elements/my-element.html</code>.</p>

<p>Since we said we wanted the <code>polymer-jsonp</code> element we have to install it: <code>bower install --save Polymer/polymer-jsonp</code></p>

<p>The <code>--save</code> option ensure that this gets added to your bower.json file, if you are asked to choose a suitable version for polymer, I usually choose the one that specifies a version number.</p>

<!-- more -->


<h2>Our web component</h2>

<p>So we have our element in <code>app/elements/my-element.html</code>, you should replace every ocurrence of <code>polymer-my-element</code> for simply <code>my-element</code>, this is a bug of the generator that they&rsquo;re going to fix very soon.</p>

<p>Now we have our element and it looks like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;import&quot;</span> <span class="na">href=</span><span class="s">&quot;../bower_components/polymer/polymer.html&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>
</span><span class='line'><span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;import&quot;</span> <span class="na">href=</span><span class="s">&quot;../bower_components/polymer-ajax/polymer-jsonp.html&quot;</span><span class="nt">&gt;</span>
</span><span class='line'><span class="nt">&lt;polymer</span><span class="na">-element</span> <span class="na">name=</span><span class="s">&quot;my-element&quot;</span>  <span class="na">constructor=</span><span class="s">&quot;MyElementElement&quot;</span> <span class="na">attributes=</span><span class="s">&quot;&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>  <span class="nt">&lt;template&gt;</span>
</span><span class='line'>    <span class="nt">&lt;style&gt;</span>
</span><span class='line'>      <span class="c">/* styles for the custom element itself - lowest specificity */</span>
</span><span class='line'>      <span class="nd">:host</span> <span class="p">{</span> <span class="k">display</span><span class="o">:</span> <span class="k">block</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'>      <span class="c">/* </span>
</span><span class='line'><span class="c">      style if an ancestor has the different class</span>
</span><span class='line'><span class="c">      :host(.different) { } </span>
</span><span class='line'><span class="c">      */</span>
</span><span class='line'>    <span class="nt">&lt;/style&gt;</span>
</span><span class='line'>    <span class="nt">&lt;span&gt;</span>I&#39;m <span class="nt">&lt;b&gt;</span>polymer-myElement<span class="nt">&lt;/b&gt;</span>. This is my Shadow DOM.<span class="nt">&lt;/span&gt;</span>
</span><span class='line'>        <span class="nt">&lt;polymer</span><span class="na">-ajax</span><span class="nt">&gt;</span><span class="err">&lt;</span>/polymer-ajax&gt;
</span><span class='line'>  <span class="nt">&lt;/template&gt;</span>
</span><span class='line'>  <span class="nt">&lt;script&gt;</span>
</span><span class='line'>    <span class="nx">Polymer</span><span class="p">(</span><span class="s1">&#39;my-element&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>      <span class="c1">//applyAuthorStyles: true,</span>
</span><span class='line'>      <span class="c1">//resetStyleInheritance: true,</span>
</span><span class='line'>
</span><span class='line'>      <span class="c1">// element is fully prepared</span>
</span><span class='line'>      <span class="nx">ready</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span> <span class="p">},</span>
</span><span class='line'>      <span class="c1">// instance of the element is created</span>
</span><span class='line'>      <span class="nx">created</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="p">},</span>
</span><span class='line'>      <span class="c1">// instance was inserted into the document</span>
</span><span class='line'>      <span class="nx">enteredView</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="p">},</span>
</span><span class='line'>      <span class="c1">// instance was removed from the document</span>
</span><span class='line'>      <span class="nx">leftView</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="p">},</span>
</span><span class='line'>      <span class="c1">// attribute added, removed or updated</span>
</span><span class='line'>      <span class="nx">attributeChanged</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">attrName</span><span class="p">,</span> <span class="nx">oldVal</span><span class="p">,</span> <span class="nx">newVal</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span>
</span><span class='line'>    <span class="p">});</span>
</span><span class='line'>  <span class="nt">&lt;/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>What we see here is the base structure of our web component, the <code>&lt;template&gt;</code> tag you see is what creates the shadow DOM, so everything inside should be encapsulated, we have our style rules, our html and templates and our js.</p>

<h2>Creating the display-rss component</h2>

<p>The first thing we need to do is learn how the <code>&lt;polymer-jsonp&gt;</code> element works, it behaves like the <code>&lt;polymer-ajax&gt;</code> one, you can find the documentation <a href="http://www.polymer-project.org/docs/elements/polymer-elements.html">here</a>.</p>

<p>To be able to get a cross domain feed we can use Google Feed url, which takes a feed url, transforms it to json and give us the result using jsonp.</p>

<p>The idea is that you can make it all work with declarative sintax, so we&rsquo;ll configure it like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;polymer</span><span class="na">-jsonp</span>  <span class="na">id=</span><span class="s">&quot;feed_data&quot;</span>
</span><span class='line'>                    <span class="na">url=</span><span class="s">&quot;http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;num={{entries}}&amp;q={{url}}&amp;callback=&quot;</span>
</span><span class='line'>                    <span class="na">auto=</span><span class="s">&quot;true&quot;</span>
</span><span class='line'>                    <span class="na">response=</span><span class="s">&quot;{{data}}&quot;</span>
</span><span class='line'>                    <span class="na">on-polymer-response=</span><span class="s">&quot;{{responseHandler}}&quot;</span><span class="nt">&gt;</span><span class="err">&lt;</span>/polymer-jsonp&gt;
</span></code></pre></td></tr></table></div></figure>


<p>To understand this code we need some notions of how data-binding works in Polymer, take a quick read at <a href="http://www.polymer-project.org/docs/polymer/databinding.html">this article</a>.</p>

<p>In the code we are saying that this element has the id <em>feed_data</em> the <code>{{url}}</code> means its data-binded to the variable <em>data</em>  and <code>{{entries}}</code> with the <em>entries</em> variable, fires up automatically, puts the response on the <em>data</em> variable, and on-response calls the <em>responseHandler</em> function.</p>

<p>We also going to define the <em>url</em> and <em>entries</em> variables in the attributes so can be changed from outside: <code>attributes="url entries"</code></p>

<p>Then we modify the Polymer function to reflect those variables and functions:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">Polymer</span><span class="p">(</span><span class="s1">&#39;my-element&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">url</span><span class="o">:</span> <span class="s1">&#39;http://feeds.bbci.co.uk/news/england/rss.xml&#39;</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">entries</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">data</span><span class="o">:</span> <span class="kc">null</span><span class="p">,</span>
</span><span class='line'>  <span class="c1">// element is fully prepared</span>
</span><span class='line'>  <span class="nx">ready</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span> <span class="p">},</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">responseHandler</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>Ok lets try if this works, before go to the <code>app/index.html</code> and change <code>&lt;polymer-my-element&gt;&lt;/polymer-my-element&gt;</code> for <code>&lt;my-element&gt;&lt;/my-element&gt;</code>, and lets fire up the server, run this in the root of your project:</p>

<pre><code>grunt serve
</code></pre>

<p>This command should prepare everything, and pop up a browser with the website running, if we take at the console in our dev tools we should see an object containing our feed.</p>

<p>Now is the time to display this data, we&rsquo;ll show the feed title, the last time it was updated and we&rsquo;ll loop through the entries using templates:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;container&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>    <span class="nt">&lt;h1</span> <span class="na">class=</span><span class="s">&quot;feed_title&quot;</span><span class="nt">&gt;</span>{{feed.title}}<span class="nt">&lt;/h1&gt;</span>
</span><span class='line'>    <span class="nt">&lt;small&gt;</span>Last updated: {{lastUpdated}}<span class="nt">&lt;/small&gt;</span>
</span><span class='line'>    <span class="nt">&lt;ul</span> <span class="na">class=</span><span class="s">&quot;entries&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>    <span class="nt">&lt;template</span> <span class="na">repeat=</span><span class="s">&quot;{{entry in feed.entries}}&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>        <span class="nt">&lt;li&gt;</span>
</span><span class='line'>            <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;{{entry.link}}&quot;</span> <span class="na">target=</span><span class="s">&quot;_blank&quot;</span> <span class="na">class=</span><span class="s">&quot;entry_title&quot;</span><span class="nt">&gt;</span>{{entry.title}}<span class="nt">&lt;/a&gt;</span>
</span><span class='line'>            <span class="nt">&lt;small</span> <span class="na">class=</span><span class="s">&quot;entry_published&quot;</span><span class="nt">&gt;</span>{{entry.publishedDate}}<span class="nt">&lt;/small&gt;</span>
</span><span class='line'>            <span class="nt">&lt;p&gt;</span>{{entry.contentSnippet}}<span class="nt">&lt;/p&gt;</span>
</span><span class='line'>        <span class="nt">&lt;/li&gt;</span>
</span><span class='line'>    <span class="nt">&lt;/template&gt;</span>
</span><span class='line'>    <span class="nt">&lt;/ul&gt;</span>
</span><span class='line'><span class="nt">&lt;/div&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>We also can refresh the feed every X milliseconds, the whole thing looks like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">Polymer</span><span class="p">(</span><span class="s1">&#39;my-element&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>  <span class="c1">//applyAuthorStyles: true,</span>
</span><span class='line'>  <span class="c1">//resetStyleInheritance: true,</span>
</span><span class='line'>  <span class="nx">url</span><span class="o">:</span> <span class="s1">&#39;http://feeds.bbci.co.uk/news/england/rss.xml&#39;</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">entries</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">refresh</span><span class="o">:</span> <span class="mi">1000</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">lastUpdated</span><span class="o">:</span> <span class="s1">&#39;Not updated yet&#39;</span><span class="p">,</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">ready</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>      <span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
</span><span class='line'>      <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">refresh</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
</span><span class='line'>              <span class="nx">that</span><span class="p">.</span><span class="nx">$</span><span class="p">.</span><span class="nx">feed_data</span><span class="p">.</span><span class="nx">go</span><span class="p">();</span>
</span><span class='line'>          <span class="p">},</span> <span class="k">this</span><span class="p">.</span><span class="nx">refresh</span><span class="p">);</span>
</span><span class='line'>      <span class="p">}</span>
</span><span class='line'>  <span class="p">},</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">responseHandler</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">responseStatus</span> <span class="o">===</span> <span class="mi">200</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">this</span><span class="p">.</span><span class="nx">lastUpdated</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">()</span>
</span><span class='line'>        <span class="k">this</span><span class="p">.</span><span class="nx">feed</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">responseData</span><span class="p">.</span><span class="nx">feed</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>The code is pretty self explanatory, the only curious line is perhaps line 13 where we select by id directly using <code>this.$.feed_data</code>  <em>feed_data</em> is the id of our <em>polymer-jsonp</em> element that has a js API called <code>go()</code> to fire up the ajax call.</p>

<p>And that&rsquo;s it! Is <strong>that</strong> easy!We now have a functional custom element that we can configure via attributes like this:</p>

<pre><code>&lt;my-element url="http://rss.news.yahoo.com/rss/topstories" entries="20" refresh="10000"&gt;&lt;/my-element&gt;
</code></pre>

<p>Fire up your <code>grunt serve</code> and you should see a news feed.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Web Components]]></title>
    <link href="http://www.martiplanellas.info/blog/25/03/2014/web-components/"/>
    <updated>2014-03-25T16:56:32+00:00</updated>
    <id>http://www.martiplanellas.info/blog/25/03/2014/web-components</id>
    <content type="html"><![CDATA[<p>Web Components had become my latest obsession, I read about them a long time ago, but it wasn&rsquo;t until the major players on the web arena embraced them that I really saw them as something I could use today.</p>

<p>When I say major players I mean Mozilla and Google, both of them started writing javascript libraries that provide <a href="http://en.wikipedia.org/wiki/Polyfill">polyfills</a> for the features needed to make web components work today.</p>

<!-- more -->


<p>Ok, but what are web components? In words of Zeno Rocha, project lead of <a href="http://customelements.io/">customelements.io</a>:</p>

<blockquote><p>Web Components are a collection of standards which are working their way through the W3C. They enable truly encapsulated and reusable components for the web. And if you think HTML5 changed the web, wait to see what Web Components will do.</p></blockquote>

<p>Those standards working their way through the future are:</p>

<ul>
<li><strong>Custom Elements</strong>: Enables authors to define and use new types of DOM elements in a document.</li>
<li><strong>Shadow DOM</strong>: Shadow DOM is designed to provide encapsulation by hiding DOM subtrees under shadow roots. It provides a method of establishing and maintaining functional boundaries between DOM trees and how these trees interact with each other within a document, thus enabling better functional encapsulation within the DOM.</li>
<li><strong>HTML Imports</strong>: HTML Imports are a way to include and reuse HTML documents in other HTML documents.</li>
</ul>


<p>These are the foundation of web components.</p>

<p>Mozilla is developing <a href="http://www.x-tags.org/">x-tags</a> library and Google is developing the <a href="http://www.polymer-project.org/">Polymer</a> library, both of them have their own way of declaring the component and the interface, but the end result is the same:</p>

<pre><code>&lt;some-component&gt;&lt;/some-component&gt;
</code></pre>

<p>A new element that has an encapsulated structure, style and functionality; it&rsquo;s highly reusable, and customisable through attributes and maybe a javascript API.</p>

<p>In <a href="http://customelements.io/">customelements.io</a> you can find a directory of web components ready to use, most of them also can be installed via bower, and they&rsquo;re really fun to use.</p>

<p>I&rsquo;ve created three web components so far:</p>

<ul>
<li><a href="https://github.com/beldar/boris-bikes">boris-bikes</a>: It provides a component that fetches the <a href="http://www.tfl.gov.uk/modes/cycling/barclays-cycle-hire">Boris Bike</a> data (free bikes, free docks, etc) and provides and interface for it, getting your location and showing the bikes location on a map (which is another web component).</li>
<li><a href="https://github.com/beldar/tfl-status">tfl-status</a>: It provides a component that fetches the Tube Status updates and shows the line status in real time.</li>
<li><a href="https://github.com/beldar/display-rss">display-rss</a>: Displays any RSS feed that you put on the <em>url</em> attribute</li>
</ul>


<p>In a future post I&rsquo;ll explain how I did it, what challenges did I face and some advises too.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Yeoman Workflow]]></title>
    <link href="http://www.martiplanellas.info/blog/24/03/2014/the-yeoman-workflow/"/>
    <updated>2014-03-24T14:39:04+00:00</updated>
    <id>http://www.martiplanellas.info/blog/24/03/2014/the-yeoman-workflow</id>
    <content type="html"><![CDATA[<h2>Searching for tools</h2>

<p>I&rsquo;ve been searching and trying new workflows when starting a front end project/project phase, there are a lot of interesting open source projects for rapid prototyping &lsquo;static&rsquo; websites in a reusable, collaborative, optimised and intelligent way.</p>

<p>I&rsquo;ve been trying tools like:</p>

<ul>
<li><a href="http://gruntjs.com/">Grunt</a> for automating build tasks like optimising images, minifying and uglifying javascript, css and html.</li>
<li><a href="http://bower.io/">Bower</a> a package manager for the web (meaning front end).</li>
<li><a href="http://compass-style.org/">Compass</a> I know it can do a lot of things but I&rsquo;m using it only to compile <a href="http://sass-lang.com/">Sass</a> files.</li>
</ul>


<p>But it wasn&rsquo;t until I found <a href="http://yeoman.io/">Yeoman</a> that everything came toghether.</p>

<p>It&rsquo;s a tool that scaffolds, downloads and prepares all these tools for you doing the tedious configuration part and using best practices approach in all parts.</p>

<!-- more -->


<h2>Instalation</h2>

<p> If you have node already you just have to run:</p>

<pre><code>npm install -g yo
</code></pre>

<p>Yeoman has lots of generators which basically are different scaffold variations using different libraries and components depending on which tools you need for the project.</p>

<p>The basic one is called <a href="https://github.com/yeoman/generator-webapp">generator-webapp</a> you can install it running:</p>

<pre><code>npm install -g generator-webapp
</code></pre>

<p>An then create a new project like this:</p>

<pre><code>yo webapp
</code></pre>

<p>It will ask you if you if you want some additional things:</p>

<p><img src="https://camo.githubusercontent.com/5f126a73cb4f0a16ca7b9e9c7b748a099458089b/687474703a2f2f692e696d6775722e636f6d2f754b545432486a2e706e67" alt="webapp-generator" /></p>

<p>And BOOM, you have a project structure ready to build using grunt, you can create a web server on the fly running <code>grunt serve</code> or build the project into the <code>/dist</code> folder running <code>grunt build</code>.</p>

<p>Then you can use bower to install other js libraries you need like:</p>

<pre><code>bower install --save underscore
</code></pre>

<p>The <code>--save</code> parameter ensures that the new library is saved on the <code>bower.json</code> file.</p>

<p>All your bower dependencies will end up in the <code>bower_components</code> folder which is not version controlled, when you want to install it somewhere else you&rsquo;ll run <code>bower install</code> inside and it will download all the libraries you need, just as <a href="https://getcomposer.org/">Composer</a> does for the back end.</p>

<h2>Using other generators</h2>

<p>That&rsquo;s one way of doing it, another way is to use other generators that are more specific to what you&rsquo;ll use in your project, for example I usually use <a href="http://backbonejs.org/">Backbone.js</a> in my projects, I could install it via bower, or I could use the <a href="https://github.com/yeoman/generator-backbone">generator-backbone</a>, which also gives me other interesting tools when building my app like generate models, collections, routers or views:</p>

<pre><code>yo backbone # generates your application base and build workflow
yo backbone:model blog
yo backbone:collection blog
yo backbone:router blog
yo backbone:view blog
</code></pre>

<p>There&rsquo;s a very thorough and extensive post about how to use it in <a href="http://code.tutsplus.com/tutorials/building-apps-with-the-yeoman-workflow--net-33254">NetTuts</a></p>

<p>There&rsquo;re quite a few <a href="http://yeoman.io/official-generators.html">official generators</a> and tons of <a href="http://yeoman.io/community-generators.html">community generators</a>, you can even <a href="http://yeoman.io/generators.html#writing-your-first-generator">write your own</a> with your own specifications.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Yet Another Blog]]></title>
    <link href="http://www.martiplanellas.info/blog/24/03/2014/yet-another-blog/"/>
    <updated>2014-03-24T11:26:30+00:00</updated>
    <id>http://www.martiplanellas.info/blog/24/03/2014/yet-another-blog</id>
    <content type="html"><![CDATA[<h2>Hello World!</h2>

<p>I&rsquo;ve lost the count on how many blogs I started and abandoned, and I always tell myself,
&ldquo;this is going to be the one, I&rsquo;m gonna crush it with this one&rdquo;, and the farthest I get is 10 posts or less.
This is because I normaly enjoy more setting up, designing, customizing the blog than actually writing on it.</p>

<p>But hey, <strong>this one is going to be different</strong>, I&rsquo;m gonna crush it with this one!</p>

<p>I will honestly try to put in here the things I learn and use in a daily basis, new technologies, techniques and
stuff that obsesses me for a briefly amount of time.</p>

<p>This blog is being served from Github using Jekyll and Octopress.</p>
]]></content>
  </entry>
  
</feed>
