<?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>GreWeb</title>
	<atom:link href="http://blog.greweb.fr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.greweb.fr</link>
	<description>Web technologies, open source and standards.</description>
	<lastBuildDate>Mon, 06 Feb 2012 12:02:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS-selector-based templating system for scalable JavaScript applications</title>
		<link>http://blog.greweb.fr/2012/02/css-selector-based-templating-example-with-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=css-selector-based-templating-example-with-javascript</link>
		<comments>http://blog.greweb.fr/2012/02/css-selector-based-templating-example-with-javascript/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 13:30:45 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[scalable]]></category>
		<category><![CDATA[templating]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=987</guid>
		<description><![CDATA[In this article, we will focus on the power of CSS as a descriptive language, current template system approach and their problems with modularity and extensibility, and try to mix both features from the concept to a concrete implementation. What is CSS ? CSS is an extremely powerful descriptive language. It helps to define how <a href='http://blog.greweb.fr/2012/02/css-selector-based-templating-example-with-javascript/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p><img alt="" src="http://blog.greweb.fr/wp-content/uploads/2012/02/218px-Mir_diagram-fr.svg_.png" title="Mir station modularity" class="alignleft" width="218" height="240" /> In this article, we will focus on the power of <strong>CSS as a descriptive language</strong>, current template system approach and their problems with <strong>modularity</strong> and <strong>extensibility</strong>, and try to mix both features from the <strong>concept</strong> to a <strong>concrete implementation</strong>.</p>
<p><br style="clear: both" /><br />
<span id="more-987"></span></p>
<h2>What is <abbr title="Cascading Style Sheets">CSS</abbr> ?</h2>
<p><abbr title="Cascading Style Sheets">CSS</abbr> is an extremely powerful descriptive language.<br />
It helps to define <strong>how to display a document</strong> (e.g. a web page).</p>
<p>A style sheet contains a set of <strong>CSS rules</strong>.<br />
Each CSS rule has a <strong>CSS selector</strong> associated with a set of <strong>declarations</strong>.<br />
You can see a CSS selector as a selection filter applied on every HTML element. A few element can match a CSS selector if they fit the structure describes in this selector.<br />
Each <strong>declaration</strong> is composed of a couple (<strong>property</strong> : <strong>value</strong>).<br />
The <strong>CSS property</strong> is a predefined property related to a display or layout behavior.<br />
The <strong>value</strong> will apply a custom value for the property on all elements matching the CSS selector.</p>
<p>Let&#8217;s focus on some advantages of this descriptive language:</p>
<h3>A CSS rule is independant from others.</h3>
<p>The order of CSS rules <em>(selector + declarations)</em> <strong>really</strong> does not matter.<br />
The priority between CSS rules is based on the selector itself and not on their arrangement.</p>
<h3>You can &#8220;mix&#8221; CSS rule</h4>
<p>2 CSS rules can have the same CSS selector. An element can be matched with multiple CSS rules. CSS rules are merged, it&#8217;s called the cascading.<br />
This is the most important feature of CSS.<br />
It implies a very modular and extensible language.</p>
<h4>Example</h4>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a <span style="color: #00AA00;">&#123;</span> <br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#33CC00</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#articles</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#articles</span> a <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* overriding the generic color of a */</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<h2>Some limitations of today&#8217;s template system</h2>
<p>Most of template system are based on inherence between templates.</p>
<ul>
<li>You have usually an &#8220;inclusion&#8221; approach: a template will &#8220;include&#8221; multiple external template. <em>(Many template into Many template)</em></li>
<li>And an &#8220;extension&#8221; approach: You define in a main template an area where you can append a template. Others templates &#8220;extend&#8221; your main template. <em>(One main template for Many template)</em></li>
</ul>
<p>These approaches aims to factorize template codes and that&#8217;s great.</p>
<p>But it doesn&#8217;t fit my needs:</p>
<ul>
<li>It brings <strong>dependencies between templates</strong>. </li>
<li>If you add a new template, you have to modify existing templates.<br />
If your application tend to go modules based, this is going to be unmaintainable.
</li>
</ul>
<blockquote><p>
<strong>web application module (n)</strong><br />
1 : an independent unit of functionality that is part of the total structure of a web application
</p></blockquote>
<h3>A solution for scalable applications and libraries</h3>
<p>I&#8217;ve recently started to rewrite my <a href="http://sliderjs.org/">SliderJS</a> library and I needed to split it into very modular features and having loose coupling between each component.</p>
<p>I followed this <a href="http://www.ubelly.com/2011/11/scalablejs/">Scalable JavaScript Application Architecture</a> article.</p>
<p>So, <strong>how to bring loose coupling in templating?</strong>.<br />
Each module have its own template and know where to append. Bringing this logic in a main template would break the independency and if I need to add new modules soon, it will not working without modifiyng it.<br />
How to keep the scalability of the main template without modifying it?</p>
<p><!--<br />
A first solution I found was to use some "dom created" events triggered each time a module has templated its HTML and appended into the DOM. This solution was bad and bring 2 issues:<br />
You can't easily define the position of your node, for instance if 3 modules need to append in a same container, you don't know what will result about their appending order.<br />
It brings more dependency between modules, it's not so loosely-coupled.<br />
--></p>
<p>The best solution I found is to combine <strong>CSS selectors</strong> concepts with <strong>template system</strong> approaches.</p>
<h2>CSS concepts applied on templating</h2>
<p>I&#8217;ve decided to inspire from CSS: <strong>attaching a CSS selector with a template</strong>.<br />
It benefits from some CSS advantages explained before.</p>
<h3>Simple twitter widget example</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitter&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitts&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitt&quot;</span>&gt;</span>Hello world!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;footer&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://twitter.com/greweb&quot;</span>&gt;</span>Follow me on twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span>footer&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<h4>Classical approach</h4>
<p>The way to template it with the classical approach would be:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitter&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitts&quot;</span>&gt;</span><br />
&nbsp; &nbsp; {for twitt in twitts}<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitt&quot;</span>&gt;</span>{twitt}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; {/for}<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;footer&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://twitter.com/{me}&quot;</span>&gt;</span>Follow me on twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span>footer&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<h4>CSS selector based approach</h4>
<p>But we can also split the original &#8220;template&#8221; in small fragments and mix all of them.<br />
It helps to define each templates independently.</p>
<p><strong>We can identify:</strong></p>
<p>- A <strong>root template fragment</strong>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitter&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<p>- A <strong>header fragment</strong> appended with <code class="codecolorer css default"><span class="css">.twitter</span></code> selector and with an <strong>high priority</strong>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span></div></div>
<p>- A <strong>twitts list fragment</strong> appended with <code class="codecolorer css default"><span class="css">.twitter</span></code> selector:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitts&quot;</span>&gt;</span><br />
&nbsp; {for twitt in twitts}<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitt&quot;</span>&gt;</span>{twitt}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; {/for}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></div></div>
<p>with <strong>parameters</strong> <code class="codecolorer javascript default"><span class="javascript">twitts <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;Hello world!&quot;</span> <span style="color: #009900;">&#93;</span></span></code></p>
<p>- An empty <strong>footer fragment</strong> appended with <code class="codecolorer css default"><span class="css">.twitter</span></code> selector and with a <strong>low</strong> priority:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;footer&gt;&lt;<span style="color: #66cc66;">/</span>footer&gt;</span></div></div>
<p>- A &#8220;follow me&#8221; <strong>link fragment</strong> appended with <code class="codecolorer css default"><span class="css"><span style="color: #6666ff;">.twitter</span> footer</span></code> selector:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://twitter.com/{me}&quot;</span>&gt;</span>Follow me on twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></div>
<p>with <strong>parameters</strong> <code class="codecolorer javascript default"><span class="javascript">me <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;greweb&quot;</span></span></code></p>
<h3>Advanced example</h3>
<p>This is another example with a slider. </p>
<p>Let&#8217;s conceptually imagine the following template language:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:350px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@root { html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slider&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> }<br />
<br />
.slider {<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slides&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
}<br />
<br />
.slider div.slides {<br />
&nbsp; html: <span style="color: #009900;">&lt;canvas <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slides&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
}<br />
<br />
.slider div.slides {<br />
&nbsp; html:<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;%= link %&gt;</span></span>&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;%= img %&gt;</span></span>&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;caption&quot;</span>&gt;&lt;%<span style="color: #66cc66;">=</span> <span style="color: #000066;">title</span> %&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
}<br />
<br />
.slider {<br />
&nbsp; priority: -10<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
}<br />
<br />
.slider div.pager {<br />
&nbsp; priority: 10<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prevSlide&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span>&gt;</span>prev<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
}<br />
<br />
.slider div.pager {<br />
&nbsp; priority: -10<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nextSlide&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span>&gt;</span>next<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
}<br />
<br />
.slider div.pager {<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pages&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><br />
}<br />
<br />
.slider div.pager {<br />
&nbsp; html: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pages&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;% <span style="color: #000066;">for</span> <span style="color: #66cc66;">&#40;</span>var i<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; i&lt;slides.length; ++i<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> %&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span>&gt;&lt;%<span style="color: #66cc66;">=</span> i+<span style="color: #cc66cc;">1</span> %&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;% <span style="color: #66cc66;">&#125;</span> %&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><br />
}</div></div>
<p>combined with some parameters, it will result</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slider&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slides&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;..&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;..&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;caption&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;canvas <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slides&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prevSlide&quot;</span>&gt;</span>prev<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pages&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span>&gt;</span>1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span>&gt;</span>2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span>&gt;</span>3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nextSlide&quot;</span>&gt;</span>next<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<p>Of-course we could also do this programmatically with DOM. But see the benefit of such a descriptive way to define things?</p>
<p>You should keep in mind that <strong>the order of rules definition does not matter</strong>. In that&#8217;s sense, it is <strong>a mixable, extensible, modular and loosely-coupled template system</strong>.</p>
<h3>More about this <abbr title="Proof Of Concept">POC</abbr></h3>
<p>Unlike CSS, <strong>two same rules aren&#8217;t merged but are appended</strong>.</p>
<p>The <em><strong>priority</strong></em> governs the order of append. The higher the value is, the sooner it is appended to the containers selected by the CSS selector.</p>
<p>As you can see, there is a <strong>micro-templating</strong> inside each rule. For this example, it looks like the John Resig &#8216;s Micro Templating.</p>
<p>Note also that a rule must be aware of its <strong>parameters</strong> to work properly. But this only concerns the implementation: You have to find a way to give a dynamic reference of these parameters when you add a rule.</p>
<h3>Concrete implementation</h3>
<p>The code above was a conceptual proof of concept, but I implement a subset of these features in Javascript and made &#8220;SelectorTemplating.js&#8221; available here : <a href="https://gist.github.com/1731611">https://gist.github.com/1731611</a></p>
<p>This is how it can be used for (almost) the same example. You will see different style of usage:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:350px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slider&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> SelectorTemplating<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> tmpl<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// defined somewhere, the John Resig 's Micro Templating.</span><br />
<br />
<span style="color: #006600; font-style: italic;">// root module</span><br />
<span style="color: #003366; font-weight: bold;">function</span> root <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;div class=&quot;slider&quot;&gt;&lt;/div&gt;'</span> <span style="color: #009900;">&#125;</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> root<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// slides module</span><br />
<span style="color: #003366; font-weight: bold;">var</span> slidesTmpl <span style="color: #339933;">=</span> tmpl<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;slides&quot;&gt; &lt;% if(obj.slides) { for(var i=0; i&lt;slides.length; ++i) { var s = slides[i]; %&gt; &lt;div class=&quot;slide&quot;&gt; &lt;a href=&quot;&lt;%= s.link %&gt;&quot;&gt; &lt;img src=&quot;&lt;%= s.img %&gt;&quot; /&gt; &lt;span class=&quot;caption&quot;&gt;&lt;%= s.title %&gt;&lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;% }} %&gt; &lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> slides <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> ... <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// mutable</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.slider&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> slidesTmpl<span style="color: #009900;">&#40;</span>slides<span style="color: #339933;">:</span> slides<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// canvas module</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.slider div.slides&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;canvas class=&quot;slides&quot;&gt;&lt;/canvas&gt;'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// pager module</span><br />
<span style="color: #003366; font-weight: bold;">var</span> pagesTmpl <span style="color: #339933;">=</span> tmpl<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;pager&quot;&gt; &lt;span class=&quot;pages&quot;&gt; &lt;% if(obj.slides) { for(var i=0; i&lt;slides.length; ++i) { %&gt; &lt;a href=&quot;javascript:;&quot; class=&quot;page&quot;&gt;&lt;%= i+1 %&gt;&lt;/a&gt; &lt;% }} %&gt; &lt;/span&gt; &lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> slides <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// synchronised with the slides module</span><br />
<span style="color: #003366; font-weight: bold;">var</span> prevButton<span style="color: #339933;">,</span> nextButton<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// DOM element init when templated</span><br />
<span style="color: #003366; font-weight: bold;">var</span> pages <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> pagesTmpl<span style="color: #009900;">&#40;</span>slides<span style="color: #339933;">:</span> slides<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.sliderjs&quot;</span><span style="color: #339933;">,</span> pages<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.sliderjs .options&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;a class=&quot;prevSlide&quot; href=&quot;javascript:;&quot;&gt;prev&lt;/a&gt;'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> prevButton <span style="color: #339933;">=</span> n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// prepend first in options</span><br />
t.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.sliderjs .options&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;a class=&quot;nextSlide&quot; href=&quot;javascript:;&quot;&gt;next&lt;/a&gt;'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> nextButton <span style="color: #339933;">=</span> n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">10</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// append at the end of options</span><br />
<br />
<span style="color: #006600; font-style: italic;">// when all modules are init :</span><br />
t.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<pre>
t.add (selector, templateFunction, callback, priority)
 * selector is the selector function. if null, append to root.
 * a template function is an identifier in the template.
 * the callback is called at the end of the templating with 2 arguments : the appended nodes and the global container.
</pre>
<h4>Algorithm of the template process</h4>
<pre>
container := the container element
rules := an array containing all rules.
sort rules by priority.
(1) take one rule from rules
  - elements := []
  - if the selector is @root, elements := [container]
  - otherwise, elements := all elements which matches the selector
  - if the elements is empty, back to (1) by taking the next rule.
  - (2) if not, templatize the html and append it into all of these elements. remove the rule from rules. back to (1) by starting from the first rules. 

the loop (1) must end when :
  - there is no rules anymore
  - you have covered all the rules array without finding a match (without passing by (2) for this loop). In that case, it means some rules are not used.
</pre>
<p>There is a known limitation of the algorithm I intend to fix soon:<br />
Once we found matching elements for a rule, we append the template in these elements once, and we remove the rule. It&#8217;s a simple way to avoid recursion. But this approach doesn&#8217;t work if a selector can potentially matches elements defined in different rules. <em>I know how to fix this but it&#8217;s not yet implemented.</em></p>
<h2>What&#8217;s next?</h2>
<p>We are working hard for the next version (v2) of <a href="http://sliderjs.org/">SliderJS</a> by trying to make a revolutionary IDE platform for SliderJS. It requires a modulification of every components of SliderJS, we try to keep things simple (no external library required, the core system is only 4k sized). You will have more information soon!</p>
<p>This templating system should benefits of this work.</p>
<p>Keep in touch!</p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=987&amp;md5=41a80597dea5f92e824bf48ee150473d" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2012/02/css-selector-based-templating-example-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=987&amp;md5=41a80597dea5f92e824bf48ee150473d" type="text/html" />
	</item>
		<item>
		<title>How to deploy your play applications on ArchLinux with daemons</title>
		<link>http://blog.greweb.fr/2011/10/how-to-deploy-your-play-applications-on-archlinux-with-daemons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-deploy-your-play-applications-on-archlinux-with-daemons</link>
		<comments>http://blog.greweb.fr/2011/10/how-to-deploy-your-play-applications-on-archlinux-with-daemons/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 21:52:19 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Tutoriels Vidéos]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[archlinux]]></category>
		<category><![CDATA[playframework]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=957</guid>
		<description><![CDATA[This video shows how to run different instances of Play framework server in the most Linux friendly way: using daemons. Example with ArchLinux, using yaourt, the playframework AUR package and nginx. Some links Play framework website Play framework Archlinux documentation Play framework AUR package Abstract summary Introduction Existing Platform as a Service: Playapps.net, Heroku.com. Our <a href='http://blog.greweb.fr/2011/10/how-to-deploy-your-play-applications-on-archlinux-with-daemons/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>This video shows how to run different instances of <a target="_blank" href="http://playframework.org">Play framework</a> server in the most Linux friendly way: using daemons. Example with <a target=_blank href="http://archlinux.org">ArchLinux</a>, using <a target=_blank href="http://archlinux.fr/yaourt-en">yaourt</a>, the <a href="http://aur.archlinux.org/packages.php?ID=45541" target="_blank">playframework <abbr title="ArchLinux User Repository">AUR</abbr> package</a> and <a href="http://nginx.org" target="_blank">nginx</a>.</p>
<p><iframe src="http://player.vimeo.com/video/30603225?title=0&amp;byline=0&amp;portrait=0" width="500" height="375" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe></p>
<h1>Some links</h1>
<ul>
<li><a target="_blank" href="http://playframework.org">Play framework website</a></li>
<li><a target="_blank" href="https://wiki.archlinux.org/index.php/Play_framework">Play framework Archlinux documentation</a></li>
<li><a target="_blank" href="http://aur.archlinux.org/packages.php?ID=45541">Play framework <abbr title="ArchLinux User Repository">AUR</abbr> package</a></li>
</ul>
<p><span id="more-957"></span></p>
<h1>Abstract summary</h1>
<h2>Introduction</h2>
<p>Existing Platform as a Service: <a href="http://playapps.net">Playapps.net</a>, <a href="http://heroku.com">Heroku.com</a>.</p>
<p>Our needs are quite different: you sometimes need to have your own server on your own infrastructure and not depending on third party web services.</p>
<p>Let&#8217;s see how to deploy some play applications from scratch with ArchLinux.</p>
<h2>Requirement</h2>
<p><a href="http://archlinux.org">Install ArchLinux on your server</a></p>
<p><a href="http://archlinux.fr/yaourt-en">Install yaourt</a></p>
<h2>Installation</h2>
<p><div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yaourt <span style="color: #660033;">-S</span> playframework</div></div>
</p>
<h2>Creating 2 play framework applications</h2>
<p><div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> sites <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> sites<br />
play new app1<br />
play new app2 <span style="color: #666666; font-style: italic;"># + editing app/views/</span></div></div>
</p>
<h2>Configuring daemons</h2>
<p><div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> skeleton_playapp app1<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> skeleton_playapp app2<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>conf.d<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> playapp_sample app1<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> playapp_sample app2<br />
<span style="color: #c20cb9; font-weight: bold;">vim</span> app1 <span style="color: #666666; font-style: italic;"># configure variables</span><br />
<span style="color: #c20cb9; font-weight: bold;">vim</span> app2 <span style="color: #666666; font-style: italic;"># configure variables</span></div></div>
</p>
<p>
For app1 :</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">PLAY_APP</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>gre<span style="color: #000000; font-weight: bold;">/</span>sites<span style="color: #000000; font-weight: bold;">/</span>app1<br />
<span style="color: #007800;">PLAY_USER</span>=gre<br />
<span style="color: #007800;">PLAY_ARGS</span>=<span style="color: #ff0000;">&quot;--%prod --http.port=9001&quot;</span></div></div>
</p>
<p>
For app2 :</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">PLAY_APP</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>gre<span style="color: #000000; font-weight: bold;">/</span>sites<span style="color: #000000; font-weight: bold;">/</span>app2<br />
<span style="color: #007800;">PLAY_USER</span>=gre<br />
<span style="color: #007800;">PLAY_ARGS</span>=<span style="color: #ff0000;">&quot;--%prod --http.port=9002&quot;</span></div></div>
</p>
<h2>Starting daemons</h2>
<p><div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rc.d start app1<br />
rc.d start app2</div></div>
</p>
<p>
Make it permanent in /etc/rc.conf by adding them in the DAEMONS variable.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color: #007800;">DAEMONS</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>... app1 app2<span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>
</p>
<h2>Nginx, as a front end proxy server</h2>
<p>Install nginx using pacman.</p>
<p>Edit /etc/nginx/conf/nginx.conf</p>
<p><div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:350px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
&nbsp; &nbsp; server {<br />
&nbsp; &nbsp; &nbsp; &nbsp; listen 80;<br />
&nbsp; &nbsp; &nbsp; &nbsp; server_name app2.archdemo;<br />
&nbsp; &nbsp; &nbsp; &nbsp; location / {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://127.0.0.1:9002;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Host $host;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Host $host;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Port $server_port;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Proto https;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; server {<br />
&nbsp; &nbsp; &nbsp; &nbsp; listen 80;<br />
&nbsp; &nbsp; &nbsp; &nbsp; server_name app1.archdemo;<br />
&nbsp; &nbsp; &nbsp; &nbsp; location / {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://127.0.0.1:9001;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Host $host;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Host $host;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Port $server_port;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-Proto https;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
...</div></div></p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=957&amp;md5=a3b17a18ec0d4cc49593c4b771f4bc27" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/10/how-to-deploy-your-play-applications-on-archlinux-with-daemons/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=957&amp;md5=a3b17a18ec0d4cc49593c4b771f4bc27" type="text/html" />
	</item>
		<item>
		<title>Improve your web navigation experience &#8211; Flexible Nav jQuery library</title>
		<link>http://blog.greweb.fr/2011/07/improve-your-web-navigation-experience-flexible-nav-jquery-library/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=improve-your-web-navigation-experience-flexible-nav-jquery-library</link>
		<comments>http://blog.greweb.fr/2011/07/improve-your-web-navigation-experience-flexible-nav-jquery-library/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 10:36:37 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[navigation]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=931</guid>
		<description><![CDATA[Demo Flexible Nav is a small jQuery library which add a smart navigation bar on the right of the page. It improves a web page navigation and helps to visualize different sections of a document, an article,.. any web page. Nav links are distributed proportionally to the page sections. See how your scrollbar &#8220;weds&#8221; these <a href='http://blog.greweb.fr/2011/07/improve-your-web-navigation-experience-flexible-nav-jquery-library/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<h2><a href="http://demo.greweb.fr/flexible-nav/">Demo</a></h2>
<blockquote><p>
Flexible Nav is a small jQuery library which add a smart navigation bar on the right of the page. It improves a web page navigation and helps to visualize different sections of a document, an article,.. any web page.</p>
<p>Nav links are distributed proportionally to the page sections. See how your scrollbar &#8220;weds&#8221; these links <img src='http://blog.greweb.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></blockquote>
<p>Flexible Nav is both a <strong>library</strong> and a <strong>bookmarklet</strong> which can be used easily in any website.</p>
<p>The bookmarklet demonstrate the <strong>hackability of the web</strong> by using the semantic of web headings (<em>h1, h2, h3, ..</em>).</p>
<h3>Links</h3>
<ul>
<li><a href="http://demo.greweb.fr/flexible-nav/">Documentation and Demos</a></li>
<li><a href="https://github.com/gre/flexible-nav">fork me on Github</a></li>
<li><a href="javascript:(function(){window.flexibleNavBase='http://lib.greweb.fr/flexible-nav/';var%20a=document.getElementsByTagName('head')[0],b=document.createElement('script');b.type='text/javascript';b.src=flexibleNavBase+'bookmarklet.min.js';a.appendChild(b);})();%20void%200">FlexibleNav bookmarklet</a> (drag me in your bookmarks bar)</li>
</ul>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=931&amp;md5=a8c0bcccce74c8a99d9ff3a5d0b910a0" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/07/improve-your-web-navigation-experience-flexible-nav-jquery-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=931&amp;md5=a8c0bcccce74c8a99d9ff3a5d0b910a0" type="text/html" />
	</item>
		<item>
		<title>Same Game Gravity for iPad, iPhone, Android, Facebook, Chrome, and Web!</title>
		<link>http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web</link>
		<comments>http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 12:24:34 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=893</guid>
		<description><![CDATA[see also Same Game Gravity Technical Notes. same.greweb.fr Same Game Gravity is today available on iPad, iPhone, Android, Web, Facebook Apps and Chrome Web Store. Un principe simple remis au goût du jour. Trés bon!! (bobylito) Great twist (excuse the pun) on the &#8220;same&#8221; game! (mrspeaker) A fresh spin on Same Game the use of <a href='http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>see also <a href="http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/">Same Game Gravity Technical Notes</a>.</p>
<p><a target="_blank" href="http://same.greweb.fr/"></p>
<h1>same.greweb.fr</h1>
<p>  <img src="http://blog.greweb.fr/wp-content/uploads/2011/07/promo.png" alt="" /><br />
</a></p>
<p><a target="_blank" href="http://same.greweb.fr/">Same Game Gravity</a> is today available on <strong><a target="_blank" href="http://itunes.apple.com/us/app/same-game-gravity-for-ipad/id446790701">iPad</a>, <a target="_blank" href="http://itunes.apple.com/us/app/same-game-gravity/id445606743">iPhone</a>, <a target="_blank" href="http://market.android.com/details?id=fr.gaetanrenaudeau.samegame.free">Android</a>, <a target="_blank" href="http://same.greweb.fr/game">Web</a>, <a target="_blank" href="http://apps.facebook.com/samegamegravity/">Facebook Apps</a> and <a target="_blank" href="https://chrome.google.com/webstore/detail/eibjpmiiheipmgfhffjpdmojoagccijb">Chrome Web Store</a></strong>.</p>
<p><a target="_blank" href="http://same.greweb.fr/"><img alt="" src="http://blog.greweb.fr/wp-content/uploads/2011/07/same_platform.png" /></a></p>
<blockquote><p>Un principe simple remis au goût du jour. Trés bon!! <em>(bobylito)</em></p></blockquote>
<blockquote><p>Great twist (excuse the pun) on the &#8220;same&#8221; game! <em>(mrspeaker)</em></p></blockquote>
<blockquote><p>A fresh spin on Same Game the use of gravity is pretty clever. <em>(erwan)</em></p></blockquote>
<p>Same Game Gravity is a mind-bending ball removal puzzle game where you try to remove all of the balls from the board. Balls can only be removed when they are grouped with more balls of the same color. The balls are influenced by gravity. On mobile, you change gravity by rotating your mobile, on desktop you have arrows.</p>
<p><span id="more-893"></span></p>
<h2 id="the_game">The game gravity</h2>
<p>Rotate your device to apply gravity and change balls arrangement!</p>
<p><img src="http://blog.greweb.fr/wp-content/uploads/2011/07/gravity_exemple.png" alt="gravity example" /></p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Qyd69g9hmIY?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Qyd69g9hmIY?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<h3>A pioneering scores system based on social networks</h3>
<div style="float: left;">
<script type="text/javascript" src="http://same.greweb.fr/public/javascripts/same.scores.js"></script><br />
<script type="text/javascript">
  new same.Scores({
    width: '250px',
    height: '400px',
    items: 3,
    period: 'all',
    platform: ['web', 'mobile', 'tablet'],
    type: ['hs_hard', 'hs_normal', 'hs_easy'],
    title: 'Best highscores ever',
    theme: {
      bg: 'rgb(218, 236, 244)',
      color: '#000',
      scores_bg: 'rgba(255, 255, 255, 0.5)',
      scores_color: 'rgba(0, 0, 0, 0.8)',
      link: '#1F98C7'
    }
  }).init().fetch();
</script>
</div>
<div style="float: right; margin-top: 20px; width: 50%;">
Players share their scores through <strong>Twitter</strong> or directly <strong>from the game</strong> (for the Facebook version). The <strong>user name</strong> and the <strong>avatar</strong> are directly taken from these social networks.</p>
<p>You can easily compare your scores and contact other players with social networks!
</p></div>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=893&amp;md5=1ceec8e8729cdf4d1d7e9797754bbde7" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=893&amp;md5=1ceec8e8729cdf4d1d7e9797754bbde7" type="text/html" />
	</item>
		<item>
		<title>Same Game Gravity: 6 platforms, 1 codebase</title>
		<link>http://blog.greweb.fr/2011/07/same-game-gravity-technical-notes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=same-game-gravity-technical-notes</link>
		<comments>http://blog.greweb.fr/2011/07/same-game-gravity-technical-notes/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 09:15:43 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=727</guid>
		<description><![CDATA[see also Same Game Gravity presentation. 2 years ago, I started to developed the Same Game as an HTML Canvas experiment. I&#8217;ve enjoyed developing this game, mostly because playing with HTML5 Canvas is so easy. Recently I&#8217;ve seen a nice increase in the user base (now around 250 visitors a day) &#8211; despite it being <a href='http://blog.greweb.fr/2011/07/same-game-gravity-technical-notes/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>see also <a href="http://blog.greweb.fr/2011/07/same-game-gravity-for-ipad-iphone-android-facebook-chrome-and-web/">Same Game Gravity presentation</a>.</p>
<p>2 years ago, I started to developed the <a href="http://same.greweb.fr/">Same Game</a> as an HTML Canvas experiment. I&#8217;ve enjoyed developing this game, mostly because playing with HTML5 Canvas is so easy. Recently I&#8217;ve seen a nice increase in the user base (now around 250 visitors a day) &#8211; despite it being perhaps the simplest games I&#8217;ve ever developed. Simplicity is good, but my increase in users is thanks to the power of HTML5: The Same Game is available for 6 different platforms. And I can pump out new builds for them all in around 15 minutes. Here&#8217;s how&#8230;</p>
<p><strong>It&#8217;s often the simplest games which work. Too much complexity is not good.</strong></p>
<p style="text-align: center;">
<a href="http://same.greweb.fr/"><br />
<img width="200px" alt="" src="http://blog.greweb.fr/wp-content/uploads/2011/07/gravity_exemple.png" /><br />
</a>
</p>
<p><span id="more-727"></span></p>
<p>In 2010, I learned how to make mobile web applications. It was also the year of the iPad. Out of interest I tried my same game canvas experiment on the iPad, and was surprised to find that it worked pretty well out of the box! Seeing it run on multiple devices was exciting &#8211; and the touch screens offered a new dimension for creating highly intuitive interactions. I mean, today, <strong>even my mum can play Same Game Gravity without any help!</strong> (That’s unfortunately not the case for her desktop)</p>
<p>That&#8217;s why I wanted to make Same Game for mobile. I started out developing and testing it as an Android application – because I have an Android phone. I created my own micro framework with some MVC concept (views, controllers, a router, etc.). The goal was to create <strong>a simple and light web app that look like a native application</strong>. For views? Portions of HTML. For transitions between views? CSS transitions. Supporting the “back” button of Android devices as a native application? I played with the hash (onhashchange event). </p>
<p>In short, the web is wide and worldly enough to do pretty much everything you want with&#8230;</p>
<p>So I implemented the Same Game on Android. But (naturally) the game already existed on Android! I had to find something new! I was itching to fully exploit the possibilities of a new technology. Mobile has great potential &#8211; so it would be bad not to make use of new APIs. I discovered <strong>the Accelerometer</strong>. My idea was gravity: change the balls position by rotating the device.</p>
<p>But, many of my friends don&#8217;t have Android phones!</p>
<p>The Same Game Gravity is now available for iPad, iPhone, Android, Facebook, Chrome Store and desktop browsers. That&#8217;s a lot of platforms, with a lot of APIs to learn &#8211; and potentially a LOT of work in maintenance. But thankfully I didn&#8217;t have to go off learning Objective-C and Java Android, or keep track of arm-fulls of repositories! All the platforms are supported from <strong>a single codebase</strong>: thanks to the power and awesomeness of JavaScript, HTML, and CSS &#8211; combined with a nifty tool I developed <a href="http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/">WebAppBuilder</a> to easily build each instance.</p>
<p><strong>I added a cool scoring system that spreads via multiple social networks simultaneously and easily &#8211; and now I have a truly cross-platform game!</strong></p>
<h3>The code</h3>
<p>Desktop version source code is available on <a target="_blank" href="https://github.com/gre/same-game-gravity">Github</a>.</p>
<h4>The HTML</h4>
<p>(see <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.html">game.html</a>)</p>
<p>The HTML code is pretty simple.<br />
Basically, there is a <strong>&lt;div id=&#8221;main&#8221;&gt;</strong> container which contains different <strong>&lt;section&gt;</strong>. Each section is a view of the game.</p>
<p>For instance here is the game view :<br />
<script src="https://gist.github.com/1074440.js?file=game_game.html"></script></p>
<p>In the desktop version, <strong>game.html</strong> is wrapped into <strong>index.html</strong> in an iframe to keep the game independent of the context.</p>
<h4>The CSS</h4>
<p>(see <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.css">game.css</a>)</p>
<p>CSS 3 is very rich.</p>
<p>CSS Transitions and CSS Transforms has been used to do view change.<br />
<script src="https://gist.github.com/1074440.js?file=transitions.css"></script></p>
<h4>The game core</h4>
<p>(see <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.js">game.js</a>)</p>
<p>Code is organized in different javascript &#8220;classes&#8221;.</p>
<p>The main components are :</p>
<ul>
<li><a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.js#L324">game.Grid</a> contains all the algorithm of the game.</li>
<li><a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.js#L687">game.GameCanvasRenderer</a> is a game renderer (graphic part of the game) based on HTML Canvas element. It contains different functions called by <strong>game.Game</strong>.</li>
<li><a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.js#L850">game.Game</a> contains all the game logic, the game loop and bind DOM events (touch, click, &#8230;).</li>
</ul>
<h4>game.desktop.js: a game instance for the desktop</h4>
<p>(see <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.desktop.js">game.desktop.js</a>)</p>
<p>This file contains all the specific code for the desktop version (it overrides existing classes). But it mainly contains the <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.desktop.js#L137">game controller</a> handling different views and using all game classes.</p>
<h5>Some significant code</h5>
<p><script src="https://gist.github.com/1074440.js?file=game_instance.js"></script></p>
<h3>The gravity</h3>
<p>The game gravity was maybe the hardest part of the game development. </p>
<h4>Using device Accelerometer for mobile/tablet version</h4>
<p>I needed to find ways to access to the device accelerometer. For Android I used <a target="_blank" href="http://docs.phonegap.com/phonegap_accelerometer_accelerometer.md.html">PhoneGap Accelerometer</a>. But on iPhone I wasn&#8217;t able to get PhoneGap&#8217;s accelerometer.getCurrentAcceleration to work properly, so I used DeviceMotion event supported by iOS 4.2+. (see <a target="_blank" href="http://dev.w3.org/geo/api/spec-source-orientation.html">DeviceOrientation spec</a>).</p>
<p>(A big thanks to <a href="http://twitter.com/42loops">@42loops</a> for that: <a href="https://github.com/peutetre/test-mobile-safari/blob/master/devicemotionevent.html">devicemotionevent.html</a>)</p>
<p><img src="http://blog.greweb.fr/wp-content/uploads/2011/07/c-rotation.png" alt="Device orientation schema" /></p>
<h4>CSS Transforms and Transitions for the desktop version</h4>
<p>Computers don&#8217;t have an Accelerometer. <em>Except maybe some macbook but I&#8217;m not sure people would like to turn macbook in 360°!</em> but the gravity concept is crucial to the game. I ended up implementing &#8220;gravity&#8221; via the arrow keys.<br />
The game is entirely rotated with <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/game.desktop.js#L31">CSS Transforms</a> and animated with <a target="_blank" href="https://github.com/gre/same-game-gravity/blob/master/index.css#L35">CSS Transitions</a>.</p>
<h3>The score system</h3>
<p>I&#8217;ve written a web service with <a target="_blank" href="http://playframework.org/">Play! framework</a> to receive scores or retrieve them from Twitter, validate them and spread them with a json API and widgets.</p>
<p><img alt="tweet example" src="http://blog.greweb.fr/wp-content/uploads/2011/07/same_game_gravity_schema.jpg" /></p>
<p><strong>This web service will be available soon for game developers.</strong></p>
<p>The power of this web service is the usage of <strong>social networks</strong>. It will retrieve peoples names, avatars, and their social links without needing to prompt the user.<br />
For game developers, social scores sharing is a nice way of <strong>advertising your game</strong>: someone shares his scores to his friends: so your game can spread virally.</p>
<p>See that little hash &#8220;$4f005&#8243;? That&#8217;s a way to check if sent scores are valid.<br />
In fact the web service allows you to handle your own security, via your own “twitter to scores” transformer. You can add a small Javascript function that is executed by the server when transforming a twit to scores &#8211; to ensure there hasn&#8217;t been any cheating.</p>
<p>The web service also provides <strong>generic widgets</strong> to easily embed game scores in websites.<br />
If a player has played a few different games using this web scores service, we can provide a &#8220;transversal&#8221; widget contains all scores of a player.</p>
<h4>The Same Game Gravity Widget</h4>
<p>Same Game Gravity use its own widget (<a target="_blank" href="http://same.greweb.fr/public/javascripts/same.scores.js">source code here</a>).</p>
<p>This widget is very customizable. Here&#8217;s an example of the code used to embed the widget anywhere (like in this blog post) :</p>
<p><script src="https://gist.github.com/1074440.js?file=game_widget.html"></script></p>
<h3>Conclusion</h3>
<p>And here we are! 6 months to develop a game and release it on different platforms! I learn a lot about mobile development and I&#8217;m now more capable to develop other games.<br />
I learned that you should avoid using Canvas if you can use DOM instead because performance are bad on some mobile device whereas CSS Transitions / Animations are hardware accelerated.</p>
<p>Finally, I learned that game development is not only about programming! The marketing and the graphical parts are so important too.</p>
<p>Want to checkout the code or contribute to the game i18n? Just fork the <a href="https://github.com/gre/same-game-gravity">game repository</a>.</p>
<p><a href="http://same.greweb.fr/">http://same.greweb.fr/</a></p>
<h4>Thanks</h4>
<p>Big thanks to all game testers. Friends and colleagues, thank you very much!<br />
Special thanks to @mrspeaker for English help <img src='http://blog.greweb.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=727&amp;md5=7a6b9c40d94885b658e6c56dcf29fd7d" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/07/same-game-gravity-technical-notes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=727&amp;md5=7a6b9c40d94885b658e6c56dcf29fd7d" type="text/html" />
	</item>
		<item>
		<title>Automating Web App development for multiple platforms</title>
		<link>http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automating-web-app-development-for-multiple-platforms</link>
		<comments>http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 14:00:35 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[maintainability]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://blog.greweb.fr/?p=586</guid>
		<description><![CDATA[In this article, we will explain why we&#8217;d choose web technologies to make applications and introduce WebAppBuilder, a tool to easily build different instances of an application. We&#8217;ll examine the Same Game Gravity as an example. Using web to develop mobile applications is very productive and web technologies are rich. Fork WebAppBuilder on Github. Rich? <a href='http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>In this article, we will explain why we&#8217;d choose web technologies to make applications and introduce <a href="http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/#webappbuilder"><strong>WebAppBuilder</strong></a>, a tool to easily build different instances of an application. We&#8217;ll examine the <a href="http://same.greweb.fr/">Same Game Gravity</a> as an example.</p>
<p>Using web to develop mobile applications is very <strong>productive</strong> and web technologies are <strong>rich</strong>.</p>
<p><a href="https://github.com/gre/WebAppBuilder">Fork WebAppBuilder on Github.</a></p>
<p><span id="more-586"></span></p>
<h2>Rich?</h2>
<p>New web technologies have become rich with CSS3, HTML5 and new Javascript APIs are now being supported on most of smartphones. CSS3 animations, Web Service usage, local storage, Geolocation, drawing shapes (Canvas),.. are some example of new web features.</p>
<p>I won&#8217;t expand more on this topic but invite you to <a target="_blank" href="http://diveintohtml5.org/">visit this link</a> for more details.</p>
<h2>Productive?</h2>
<p>Compared to a native application, the web application <strong>paradigm is reversed</strong>.<br />
The Web provide a common way to make applications.<br />
To develop a native application, you must adapt yourself for each device, each new API, or each new language,&#8230; but with Web, the device fits to you by proving bridges (accessible via JavaScript) to access device features!<br />
I mean, you don&#8217;t need to dive into the Java Android API or Objective-C language (for iPhone/iPad), or any other API for other devices&#8230; You just have to learn <strong>web technologies</strong>.</p>
<p>We are in 2011, the &#8220;only desktop application&#8221; model is over now, and mobile and tablet are two new platforms you should be aware of. So it changes everything about the technology to use.</p>
<h3>Having a common language for all instances</h3>
<p>Instances of a single application can be numerous.<br />
In fact, an application can be projected in at least 3 axis of instance : The <strong>platform</strong> (mobile, tablet, desktop, &#8230;), the <strong>Operating System</strong> (Android, iPhone, webOS) and the <strong>application version</strong> (free version, full version, &#8230;).</p>
<p><img src="http://data.greweb.fr/blog/image/webapp/application-axis3.png" alt="" /></p>
<p>That&#8217;s pretty expensive to develop X instances of an application. This is a problem for developing the first version and mainly for maintainability : You want to fix bugs and add features once, and only once.</p>
<p><strong>So, the point is we need a common language to describe an application with multiple instances.</strong></p>
<h3>Web is great for that!</h3>
<p>Computers have browsers, mobiles and tablets device have recent browsers.</p>
<p>To make your application development fully independent from the device, firstly you need a great <strong>framework</strong> to bridge your application and the device (like <a target="_blank" href="http://www.phonegap.com/">PhoneGap</a>), secondly you need a great tool to easily <strong>build</strong> all applications from your common source code.</p>
<p>First of all, let&#8217;s see how to organize a web project.</p>
<h3>Good practice</h3>
<p>This is how I&#8217;ve organize my project :</p>
<h4>The source code directory</h4>
<p>This directory contains all your web app source code. You should keep your application source code (with HTML, CSS, Javascripts, images, sounds, &#8230;) in one directory (like <em>/src</em> ).<br />
You should <strong>avoid specific code</strong>, but sometimes you still need some specific behaviors for different devices. If so, I recommend you to put these differences inside different files (for exemple: <em>mobile.html</em>, <em>tablet.html</em>, <em>computer.html</em>,&#8230;).</p>
<h4>Project skeletons</h4>
<p>Keep one skeleton directory for each instance of your application.<br />
A skeleton directory will contains all the specific code related to the platform/device/version.<br />
<strong>Frameworks like PhoneGap bring you these skeletons.</strong></p>
<hr id="webappbuilder"/>
<h2>WebAppBuilder</h2>
<p><img src="http://data.greweb.fr/blog/image/webapp/webappmaker.png" alt="" /></p>
<p>I created <strong>WebAppBuilder : a lightweight Makefile to build your project</strong>. This is a mashup of existing cool stuff like : a small template system (Mustache), SASS with Compass, Javascript minimizer, &#8230;</p>
<h3>Features of WebAppBuilder</h3>
<ul>
<li>Template easily your HTML files with <a target="_blank" href="http://mustache.github.com/">Mustache</a>.</li>
<li>Copy, concatenate, minimize Javascripts however you want.</li>
<li>Retrieve Javascript files from URLs (useful for libraries).</li>
<li>Compile SASS files into CSS files (if you use <a target="_blank" href="http://sass-lang.com">this awesome stylesheets language</a>)</li>
<li>Support <a target="_blank" href="http://compass-style.org">Compass</a> if installed (you don&#8217;t need to provide it in your source, only an import works)</li>
<li>Merge your CSS files.</li>
<li>Copy and optionally rename resources you want to include (images, fonts, sounds,&#8230;).</li>
<li>Error handling and atomicity : if one operation fail, the make fail (javascript syntax error, sass syntax error, &#8230;)</li>
</ul>
<p>You must have one Makefile per project skeleton, so you can easily define what to do with the <em>/src</em> for the related platform/device/OS.</p>
<h3>Download or Contribute</h3>
<p><a href="https://github.com/gre/WebAppBuilder">Fork me on Github</a></p>
<h3>Example with my Same Game Gravity game</h3>
<p>I developed these tools during the <a target="_blank" href="http://same.greweb.fr/">Same Game Gravity</a> game development. </p>
<p>A <strong>make</strong> inside my android/ skeleton gives me :</p>
<p><img src="http://data.greweb.fr/blog/image/webapp/webappmaker-term.png" alt="" /></p>
<p>And here is the Makefile I use :</p>
<h4>Android Makefile</h4>
<p><script src="https://gist.github.com/995971.js?file=Makefile"></script></p>
<h3>Configuring your IDE</h3>
<p>I use mainly komodo and geany as an IDE. They both have a build system. I recommand you to configure your IDE to make &#038;&#038; open the page just by pressing a shortcut key.</p>
<h3>Features planned</h3>
<ul>
<li>make should build the .apk for Android app</li>
</ul>
<h2>Special thanks</h2>
<ul>
<li>to <a target="_blank" href="http://mrspeaker.net/">mrspeaker</a> for English review.</li>
<li>to <a target="_blank" href="https://github.com/jquery/jquery/tree/master/build">jQuery build system</a> (js minifier)</li>
</ul>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=586&amp;md5=5a1607a4da2e169405c6fbda2a19572d" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/06/automating-web-app-development-for-multiple-platforms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=586&amp;md5=5a1607a4da2e169405c6fbda2a19572d" type="text/html" />
	</item>
		<item>
		<title>Releasing Same Game Gravity (Android)</title>
		<link>http://blog.greweb.fr/2011/04/releasing-same-game-gravity-android/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=releasing-same-game-gravity-android</link>
		<comments>http://blog.greweb.fr/2011/04/releasing-same-game-gravity-android/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 21:36:38 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[market]]></category>

		<guid isPermaLink="false">http://blog.grenlibre.fr/?p=580</guid>
		<description><![CDATA[Following on from the success of my Same game made in HTML5 Canvas, I&#8217;ve decided to extend it to a (web) mobile game. It&#8217;s now available on Android market. More infos on http://same.greweb.fr/. This ball removal puzzle game is made with HTML5 technologies and PhoneGap. Source code will be published within a few months.]]></description>
			<content:encoded><![CDATA[
<p>Following on from the success of my Same game made in HTML5 Canvas, I&#8217;ve decided to extend it to a (web) mobile game.</p>
<p>It&#8217;s now available on Android market.</p>
<p>More infos on <a href="http://same.greweb.fr/">http://same.greweb.fr/</a>.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Qyd69g9hmIY?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Qyd69g9hmIY?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>This ball removal puzzle game is made with HTML5 technologies and PhoneGap. Source code will be published within a few months.</p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=580&amp;md5=9c983b2244a29ce616da0e3814619b57" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/04/releasing-same-game-gravity-android/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=580&amp;md5=9c983b2244a29ce616da0e3814619b57" type="text/html" />
	</item>
		<item>
		<title>HTML Canvas pour les néophytes</title>
		<link>http://blog.greweb.fr/2011/03/html-canvas-pour-les-neophytes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=html-canvas-pour-les-neophytes</link>
		<comments>http://blog.greweb.fr/2011/03/html-canvas-pour-les-neophytes/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 17:16:51 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Tutoriels Vidéos]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.grenlibre.fr/?p=564</guid>
		<description><![CDATA[Cette vidéo de 20 minutes présente les possibilités du Canvas à travers quelques démos et l&#8217;implémentation pas à pas d&#8217;un exemple basique. Elle est destinée à des développeurs débutant dans l&#8217;utilisation de Canvas. Dans la suite de l&#8217;article : les liens et codes de la vidéo &#8230; Liens Specs whatwg.org/html Canvas Exemples parcycle Visualisation des <a href='http://blog.greweb.fr/2011/03/html-canvas-pour-les-neophytes/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>Cette vidéo de 20 minutes présente les possibilités du Canvas à travers quelques démos et l&#8217;implémentation pas à pas d&#8217;un exemple basique.<br />
Elle est destinée à des développeurs débutant dans l&#8217;utilisation de Canvas.</p>
<p><iframe src="http://player.vimeo.com/video/20957255?portrait=0" width="500" height="375" frameborder="0"></iframe></p>
<p><em>Dans la suite de l&#8217;article : les liens et codes de la vidéo &#8230;</em></p>
<p><span id="more-564"></span></p>
<h2>Liens</h2>
<h3>Specs</h3>
<ul>
<li><a href="http://whatwg.org/html">whatwg.org/html</a></li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html">Canvas</a></li>
</ul>
<h3>Exemples</h3>
<li><a href="http://www.mrspeaker.net/dev/parcycle/">parcycle</a></li>
<li><a href="http://en.inforapid.org/">Visualisation des relations entre sujets (wikipédia)</a></li>
<li><a href="http://greweb.fr/demo/same/">Same Game</a></li>
<li><a href="http://fizz.bloom.io/">fizz : visualisation des tweets</a></li>
</ul>
<h3>Bibliothèques graphiques</h3>
<li><a href="http://easeljs.com/">EaselJS</a></li>
<li><a href="http://processingjs.org/">Processing JS</a></li>
</ul>
<h2>Exemple de l&#8217;implémentation</h2>
<p><script src="https://gist.github.com/868168.js?file=canvas_exemple.html"></script></p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=564&amp;md5=300609d8b5c9140b935a0ece8961419f" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/03/html-canvas-pour-les-neophytes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=564&amp;md5=300609d8b5c9140b935a0ece8961419f" type="text/html" />
	</item>
		<item>
		<title>Vote for my next blog tutorial video</title>
		<link>http://blog.greweb.fr/2011/01/vote-for-my-next-blog-tutorial-video/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vote-for-my-next-blog-tutorial-video</link>
		<comments>http://blog.greweb.fr/2011/01/vote-for-my-next-blog-tutorial-video/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 20:25:52 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[Tutoriels Vidéos]]></category>
		<category><![CDATA[vote]]></category>

		<guid isPermaLink="false">http://blog.grenlibre.fr/?p=552</guid>
		<description><![CDATA[Hi readers. Like in the past, I have decided to restart to do some video tutorials and podcasts, but this time to share my new experience in web architecture and programming. I have lot of ideas of video podcast around new web technologies but I don&#8217;t have much time to do all of them. So <a href='http://blog.greweb.fr/2011/01/vote-for-my-next-blog-tutorial-video/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>Hi readers.</p>
<p>Like in the past, I have decided to restart to do some video tutorials and podcasts, but this time to share my new experience in web architecture and programming.</p>
<p>I have lot of ideas of video podcast around <strong>new web technologies</strong> but I don&#8217;t have much time to do all of them.<br />
So I&#8217;m going back to the real goal, I mean <strong>YOU</strong>, readers ! I will ask you through a vote <strong>what do you expect the next video podcast?</strong> This is a new concept I&#8217;m experimenting.</p>
<p><strong>I&#8217;m expecting lot of votes before closing them, so feel free to share the news.</strong><br />
I intend to release a video every 2 or 3 months about.</p>
<p><span id="more-552"></span></p>
<p>Pick one choice among these various topics :</p>
<p>[poll id="2"]</p>
<p>(I don&#8217;t know if I&#8217;ll do it in English but if it&#8217;s in French, I&#8217;ll probably put subtitles)</p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=552&amp;md5=7d7d7722cf82e8b5e520a3acef2a28d9" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/01/vote-for-my-next-blog-tutorial-video/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=552&amp;md5=7d7d7722cf82e8b5e520a3acef2a28d9" type="text/html" />
	</item>
		<item>
		<title>How to make DLink DWA-140 B2 perfectly work on Linux</title>
		<link>http://blog.greweb.fr/2011/01/how-to-make-dlink-dwa-140-perfectly-work-on-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-make-dlink-dwa-140-perfectly-work-on-linux</link>
		<comments>http://blog.greweb.fr/2011/01/how-to-make-dlink-dwa-140-perfectly-work-on-linux/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 18:50:38 +0000</pubDate>
		<dc:creator>Gaetan</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[ndiswrapper]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[wifi]]></category>

		<guid isPermaLink="false">http://blog.grenlibre.fr/?p=520</guid>
		<description><![CDATA[I&#8217;m using ArchLinux and I finally make my DWA-140 B2 Wifi USB adaptor work If you have the same problem, you can read this article to fix it My conf : Linux Kernel: 2.6.36 Architecture: x64 Device: ID 07d1:3c0a D-Link System DWA-140 RangeBooster N Adapter(rev.B2) [Ralink RT2870] What to use ? So the only way <a href='http://blog.greweb.fr/2011/01/how-to-make-dlink-dwa-140-perfectly-work-on-linux/'>[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>I&#8217;m using ArchLinux and I finally make my DWA-140 B2 Wifi USB adaptor work <img src='http://blog.greweb.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you have the same problem, you can read this article to fix it <img src='http://blog.greweb.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>My conf</strong> :<br />
Linux Kernel: <em>2.6.36</em><br />
Architecture: <em>x64</em><br />
Device: <em>ID 07d1:3c0a D-Link System DWA-140 RangeBooster N Adapter(rev.B2) [Ralink RT2870]</em></p>
<p><span id="more-520"></span></p>
<h2>What to use ?</h2>
<p>So the only way I found to make it work nicely is to use <strong>ndiswrapper</strong>, a windows XP driver wrapper, and <strong>wpa_supplicant</strong>, a WLAN tool.</p>
<p>First, I&#8217;ve tried some RaLink drivers but this was not really great, I&#8217;ve succeed to make ra2870 work only one time but there was some lags each 20 seconds (like 1000ms ping frequently).</p>
<p>Moreover, I recommend not using NetworkManager with this method, it seems ndiswrapper and networkmanager produced awful results for this bundle (like waiting 30s for wifi to connect (or not connecting!), or freezing my Linux, &#8230;). Use wpa_supplicant + utils like netcfg instead of <img src='http://blog.greweb.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Procedure</h2>
<p>Alternatives rejected, here is the solution step by step :</p>
<h3>Pre-conditions</h3>
<p>With a wired connection, install these packages (with your package manager) : <strong>ndiswrapper</strong> ,<strong> wpa_supplicant</strong> and (optional) <strong>netcfg</strong>.</p>
<p>Unfortunately, I had some freeze issues with the current ndiswrapper repository version so I checkout ndiswrapper SVN source code on <a href="http://sourceforge.net/scm/?type=svn&#038;group_id=93482">http://sourceforge.net/scm/?type=svn&#038;group_id=93482</a> and recompile it. <strong>Maybe you have to do the same.</strong></p>
<ol>
<li>Don&#8217;t plug your bundle yet. Insert the CD of the product. It contains the driver we need for ndiswrapper. You need to find the /Drivers/WinXPx64/ (it may depend on your arch) <strong>.inf</strong> file. You can also download the last driver on the <a href="http://www.dlink.com/products/?tab=3&#038;pid=DWA-140&#038;rev=DWA-140_revB">D-Link website</a>.</li>
<li>Go on commandline in root mode and type :
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ndiswrapper -i {path of the .inf file}</div></div>
<p>Example:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ndiswrapper -i /media/cdrom0/Drivers/WinXPx64/Drt2870.inf</div></div>
<p>)</li>
<li>Plug your bundle and check if the command &#8220;ndiswrapper -l&#8221; say something like :
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">drt2870 : driver installed<br />
&nbsp; device (07D1:3C0A) present</div></div>
<p>If not you maybe need to &#8220;ndiswrapper -r drt2870 &#8221; to remove the driver and return to the second step trying another /Drivers/*/*.inf file.</li>
<li>Next, you need to configure your wpa_supplicant.conf configuration file for your wifi access point. Refer to the <a href="https://wiki.archlinux.org/index.php/WPA_supplicant">documentation</a>.</li>
<li>Try to run wpa_supplicant :
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf</div></div>
<p>Once this working, you maybe need to run dhcpd :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dhcpd wlan0</div></div>
</li>
<li>Now you can try your internet connection, by pinging google.com or try to browse the web.</li>
<li>If it works, you can save your configuration, refer to the <a href="https://wiki.archlinux.org/index.php/WPA_supplicant">documentation</a>.</li>
</ol>
<p><strong>For any problem, feel free to comment this article.</strong></p>

 <p><a href="http://blog.greweb.fr/?flattrss_redirect&amp;id=520&amp;md5=8236977f9829c5f474889aab5ed94d1b" title="Flattr" target="_blank"><img src="http://blog.greweb.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.greweb.fr/2011/01/how-to-make-dlink-dwa-140-perfectly-work-on-linux/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<atom:link rel="payment" href="http://blog.greweb.fr/?flattrss_redirect&amp;id=520&amp;md5=8236977f9829c5f474889aab5ed94d1b" type="text/html" />
	</item>
	</channel>
</rss>

