<?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>Antártico Norte &#187; ruby</title>
	<atom:link href="http://antarticonorte.com/blog/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://antarticonorte.com/blog</link>
	<description>Fotografía, diseño web y de todo un poco</description>
	<lastBuildDate>Tue, 19 Jan 2010 19:20:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Usando LESS con Nanoc</title>
		<link>http://antarticonorte.com/blog/2010/01/19/usando-less-con-nanoc/</link>
		<comments>http://antarticonorte.com/blog/2010/01/19/usando-less-con-nanoc/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 19:20:20 +0000</pubDate>
		<dc:creator>Al-x</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[nanoc]]></category>

		<guid isPermaLink="false">http://antarticonorte.com/blog/?p=215</guid>
		<description><![CDATA[ En el articulo anterior vimos como crear un sitio web básico con nanoc. Ahora vamos a ver como podemos gestionar nuestras hojas de estilo en un proyecto de nanoc utilizando LESS.
LESS, o &#8220;Leaner CSS&#8221; es una gema de Ruby que extiende el lenguaje CSS con elementos propios de otros lenguajes de programación, como variables, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://antarticonorte.com/blog/wp-content/uploads/2010/01/less.png" alt="" title="less" width="214" height="114" class="alignright size-full wp-image-216" /> En el articulo anterior vimos como <a href="http://antarticonorte.com/blog/2010/01/09/empezando-con-nanoc/">crear un sitio web básico con nanoc</a>. Ahora vamos a ver como podemos gestionar nuestras hojas de estilo en un proyecto de nanoc utilizando <a href="http://lesscss.org/">LESS</a>.</p>
<p>LESS, o &#8220;Leaner CSS&#8221; es una gema de Ruby que extiende el lenguaje CSS con elementos propios de otros lenguajes de programación, como variables, herencia, operaciones aritméticas, etc. Algunas de las cosas que nos permite son:</p>
<p><strong>Variables</strong><br />
LESS te permite declarar variables y reutilizarlas dentro de tus hojas de estilo, haciendo cambios globales tan sencillos como modificar una linea.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@color_logo: #F7BD01;</span>
&nbsp;
<span style="color: #cc00cc;">#logo</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #a1a100;">@color_logo; }</span></pre></div></div>

<p><strong>Elementos anidados (herencia)</strong><br />
Con LESS, en vez de tener selectores largos podemos anidar un selector dentro de otro. De esta forma la herencia queda más clara y tus hojas de estilo más pequeñas.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* less */</span>
<span style="color: #cc00cc;">#cabecera</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
    a <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;">none</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* css */</span>
<span style="color: #cc00cc;">#cabecera</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cabecera</span> a <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;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>No voy a hablar mucho más de LESS en este articulo. Para ver más características os recomiendo que leais la <a href="http://lesscss.org/docs.html">documentación oficial</a>, donde explican cómo extiende el lenguaje CSS y todo lo que se puede hacer con la librería.</p>
<p><span id="more-215"></span></p>
<h3>Instalando LESS</h3>
<p>Instalar LESS es tan sencillo como instalar cualquier otra gema de Ruby. Basta con abrir una sesión de terminal y ejecutar:</p>
<pre class="term">
$ sudo gem install less
</pre>
<h3>Integrar LESS con Nanoc</h3>
<p>Lo primero que necesitas es un proyecto de nanoc. Si seguiste el <a href="http://antarticonorte.com/blog/2010/01/09/empezando-con-nanoc/">anterior articulo</a> ya deberías de tener un proyecto, si no es así, leetelo y empieza a usar esta maravillosa herramienta.</p>
<p>Vete al directorio donde tengas tu proyecto de nanoc y crea un nuevo item. Para mantener las cosas organizadas, los items que sean hojas de estilo los vamos a crear dentro del directorio <code>css</code>.</p>
<pre class="term">
$ cd code/mi_sitio
$ nanoc3 create_item css/estilos
      create  content/css/estilos.yaml
      create  content/css/estilos.html
</pre>
<p>Fíjate en que no he escrito la extensión del fichero, y que nanoc ha supuesto automáticamente que quiero crear una página <code>.html</code>. Bueno, no hay forma de decirle que extensión queremos usar, por lo que la única solución es renombrar a posteriori el fichero. Los las hojas de estilo de LESS llevan la extensión .less</p>
<pre class="term">
$ mv content/css/estilos.html content/css/estilos.less
</pre>
<p>Ahora tenemos que decir a nanoc como tiene que compilar nuestras hojas de estilo. Para ello tenemos que modificar el fichero <code>Rules</code> de la raíz de nuestro proyecto y añadir lo siguiente al principio del todo.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Stylesheets</span>
route <span style="color:#996600;">'/css/*'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  item.<span style="color:#9900CC;">identifier</span>.<span style="color:#CC0066; font-weight:bold;">chop</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'.css'</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
compile <span style="color:#996600;">'/css/*'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  filter <span style="color:#ff3333; font-weight:bold;">:less</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>No entraré en detalles, pero el código que hemos añadido en el fichero le dice a nanoc tres cosas: donde tiene que guardar nuestras hojas de estilo, con que nombre, y qué filtro debe utilizar para ello.</p>
<p>Para comprobar que funciona vamos a crear una hoja de estilo con LESS muy sencilla.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Georgia<span style="color: #00AA00;">,</span> Palatino<span style="color: #00AA00;">,</span> Times<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">'Times New Roman'</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
body <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a <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;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span> <span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f30</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    <span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f90</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">280px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
&nbsp;
    h1 <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    p <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    ul <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    li <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">square</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
    h2 <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">13px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    ul <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    li <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Como puedes ver estamos haciendo uso de los selectores anidados de LESS para dejar la hoja de estilo más limpia.</p>
<p>Para comprobar que los cambios han surtido efecto vamos a arrancar el autocompilador de nanoc. Para ello ejecutamos:</p>
<pre class="term">
$ nanoc3 aco
</pre>
<p>Si ahora abrimos un navegador y pedimos la URL http://localhost:3000/css/estilos.css, deberíamos de ver la hoja de estilos procesada con LESS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Georgia<span style="color: #00AA00;">,</span> Palatino<span style="color: #00AA00;">,</span> Times<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">'Times New Roman'</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
a <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;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:link </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff3300</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff3300</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff9900</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
...</pre></div></div>

<p>Utilizar la nueva hoja de estilo ya procesada es tan fácil como añadir un <code>&lt;link /&gt;</code> a tu fichero de layout. Para ello modificamos el fichero &#8220;layouts/default.html&#8221;, buscamos la siguiente linea:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/style.css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span></pre></div></div>

<p>y la cambiamos por esta otra:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/css/estilos.css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://antarticonorte.com/blog/2010/01/19/usando-less-con-nanoc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Empezando con nanoc</title>
		<link>http://antarticonorte.com/blog/2010/01/09/empezando-con-nanoc/</link>
		<comments>http://antarticonorte.com/blog/2010/01/09/empezando-con-nanoc/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 07:33:03 +0000</pubDate>
		<dc:creator>Al-x</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[nanoc]]></category>

		<guid isPermaLink="false">http://antarticonorte.com/blog/?p=161</guid>
		<description><![CDATA[
Nanoc es un generador de páginas estáticas escrito en Ruby. Nanoc crea ficheros HTML a partir de plantillas escritas en ERB, HAML u otros lenguajes.
No necesitas nada especial en el servidor para usar nanoc, ya que las plantillas se procesan en tu ordenador. Basta con subir los ficheros estáticos generados a un servidor web y [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://antarticonorte.com/blog/wp-content/uploads/2010/01/extensible.png" alt="" title="extensible" width="262" height="108" class="alignright size-full wp-image-203" /></p>
<p><a href="http://nanoc.stoneship.org/">Nanoc</a> es un generador de páginas estáticas escrito en Ruby. Nanoc crea ficheros HTML a partir de plantillas escritas en <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/">ERB</a>, <a href="http://haml-lang.com/">HAML</a> u otros lenguajes.</p>
<p>No necesitas nada especial en el servidor para usar nanoc, ya que las plantillas se procesan en tu ordenador. Basta con subir los ficheros estáticos generados a un servidor web y el sitio ya estará accesible.</p>
<p><span id="more-161"></span></p>
<h3>Creando un sitio</h3>
<p>Lo primero que tenemos que hacer es instalar nanoc y otras gemas que vamos a necesitar.</p>
<pre class="term">
$ sudo gem install nanoc3 rack mime-types
</pre>
<p>Una vez instalado todo el siguiente paso es crear nuestro primer sitio web.</p>
<pre class="term">
$ nanoc3 create_site mi_sitio
</pre>
<p>Esto nos genera la siguiente salida:</p>
<pre class="term">
      create  config.yaml
      create  Rakefile
      create  Rules
      create  content/index.yaml
      create  content/index.html
      create  layouts/default.yaml
      create  layouts/default.html
Created a blank nanoc site at 'mi_sitio'. Enjoy!
</pre>
<p>El comando anterior crea un nuevo proyecto de nanoc en la carpeta &#8216;mi_primer_sitio&#8217;, pero aún no hay ningún fichero que podamos abrir con un navegador web. Para ello debemos indicar a nanoc que compile nuestro proyecto en un sitio estático. </p>
<pre class="term">
$ nanoc3 compile
Loading site data...
Compiling site...
      create  [0.01s]  output/index.html

Site compiled in 0.01s.
</pre>
<p>Si echamos un vistazo al directorio <code>output</code> vemos que se ha creado un nuevo fichero llamado <code>index.html</code>. El contenido de este fichero se genera a partir de un contenedor o fichero de <em>layout</em> y un fichero de plantilla.</p>
<p>Los ficheros que genera nanoc no están pensados para abrirse directamente con el navegador, sino para ser servidos mediante un servidor web. Esto es importante, ya que nanoc por defecto utiliza rutas absolutas para los recursos (imágenes, hojas de estilo, etc&#8230;). Si abrimos el fichero directamente con el navegador seguramente veamos el contenido sin estilos aplicados.</p>
<p>Si a esto añadimos que con cada cambio que hagamos debemos recompilar el sitio, el proceso de desarrollo se hace muy tedioso. Para ello nanoc nos permite arrancar un servidor web local que compila automáticamente el sitio cada vez que accedemos a él. Para arrancarlo basta con escribir en el terminal.</p>
<pre class="term">
mi_sitio$ nanoc3 aco
</pre>
<p>Con esto abrimos un servidor web en el puerto 3000 de nuestra maquina en el que podremos ver el sitio web compilado. No es necesario compilar manualmente ya que nanoc lo hará por nosotros cada vez que accedamos a este servidor.</p>
<p>Podemos entrar con nuestro navegador favorito en <a href="http://localhost:3000/">http://localhost:3000/</a> y veremos el sitio web compilado:</p>
<p><a href="http://antarticonorte.com/blog/wp-content/uploads/2010/01/Imagen-1.png"><img src="http://antarticonorte.com/blog/wp-content/uploads/2010/01/Imagen-1-500x399.png" alt="" title="Imagen 1" width="500" height="399" class="alignnone size-medium wp-image-184" /></a></p>
<h3>Editando plantillas</h3>
<p>Las diferentes plantillas para generar nuestro sitio web estático se almacenan en el directorio <code>content</code>. Si entramos en él, veremos que tiene una estructura similar a esta:</p>
<pre class="term">
mi_sitio/content$ ls -l
total 16
-rw-r--r--  1 alex  _www  981  4 ene 01:21 index.html
-rw-r--r--  1 alex  _www   17  4 ene 01:21 index.yaml
</pre>
<p><code>index.html</code> es el fichero que contiene el contenido de la plantilla, e <code>index.yaml</code> es donde se almacenan los metadatos de la misma.</p>
<p>Vamos a modificar el título de la página. Para ello modificamos el fichero <code>index.html</code> y cambiamos el contenido del tag <code>&lt;h1&gt;</code> por lo siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Mi primer sitio con nanoc<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span></pre></div></div>

<p>Ahora abrimos el fichero <code>index.yaml</code> y dejamos su contenido como sigue:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">--- 
title: Mi primer sitio con nanoc</pre></div></div>

<p>Accedemos de nuevo a http://localhost:3000/ para comprobar que ha modificado el sitio con nuestros cambios.</p>
<h3>Creando una nueva página</h3>
<p>Crear una nueva página en nanoc es muy simple:</p>
<pre class="term">
$ nanoc3 create_item nombre_pagina
</pre>
<p>Por ejemplo, vamos a crear una página en la que metamos información acerca de nosotros mismos</p>
<pre class="term">
mi_sitio$ nanoc3 create_item acerca_de
      create  content/acerca_de.yaml
      create  content/acerca_de.html
An item has been created at /acerca_de/.
</pre>
<p>Si ahora apuntamos nuestro navegador a <a href="http://localhost:3000/acerca_de/">http://localhost:3000/acerca_de/</a> veremos que se ha creado una nueva página en blanco. Si modificamos el fichero <code>content/acerca_de.html</code> se actualizará el contenido de la página que acabamos de crear.</p>
<h3>Entendiendo el layout</h3>
<p>Los layouts (podemos tener varios) se almacenan en el directorio <code>layouts</code>. Si echamos un vistazo al directorio tendremos una estructura similar a esta.</p>
<pre class="term">
mi_sitio/layouts$ ls -l
total 16
-rw-r--r--  1 alex  _www  875  4 ene 23:51 default.html
-rw-r--r--  1 alex  _www    8  4 ene 23:51 default.yaml
</pre>
<p>Esta estructura nos resultará familiar del contenido del directorio <code>content</code>.</p>
<p>Por defecto el fichero <code>default.yaml</code> viene vacío, así que de momento vamos a centrarnos en el contenido de <code>default.html</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>A Brand New nanoc Site - <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> @item<span style="color: #66cc66;">&#91;</span>:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#93;</span> %&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/style.css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> yield %&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebar&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Documentation<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</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;http://nanoc.stoneship.org/tutorial/&quot;</span>&gt;</span>Tutorial<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><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</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;http://nanoc.stoneship.org/manual/&quot;</span>&gt;</span>Manual<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><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Community<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</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;http://groups.google.com/group/nanoc/&quot;</span>&gt;</span>Discussion Group<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><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</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;http://groups.google.com/group/nanoc-es/&quot;</span>&gt;</span>Spanish Discussion Group<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><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</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;http://projects.stoneship.org/trac/nanoc/&quot;</span>&gt;</span>Wiki<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><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p>Como podemos ver se trata de un fichero HTML normal y corriente, salvo por dos detalles. El primero lo encontramos en el <title></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>A Brand New nanoc Site - <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> @item<span style="color: #66cc66;">&#91;</span>:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#93;</span> %&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span></pre></td></tr></table></div>

<p>¿Recordais que antes modificamos el fichero <code>index.yaml</code>? Bien. El contenido de ese fichero se carga en las plantillas como variables del objeto <code>@item</code>. En este caso estamos cogiendo el contenido de <code>title</code> dentro de <code>index.yaml</code> y lo estamos escribiendo en el layout como parte del título de la página.</p>
<p>El segundo detalle que nos llama la atención está en la linea 9</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>8
9
10
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> yield %&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>La llamada a <code>yield</code> se sustituirá con el contenido de la página sobre la que estemos aplicando el layout. En este caso, coge el contenido de <code>content/index.html</code> y lo coloca ahí.</p>
<h3>Más información</h3>
<p>Puedes ampliar información sobre nanoc en el <a href="http://nanoc.stoneship.org/tutorial/">tutorial oficial</a>, sobre el que he basado este articulo.</p>
<p>Otro buen tutorial es <a href="http://nanoc2.jottit.com/">Maquetación ágil con nanoc 2.1</a>, de Ale Muñoz. Está escrito sobre una versión antigua, pero trata la herramienta de forma más profunda.</p>
<p>Por último y para profundizar del todo en nanoc, es de lectura obligada el <a href="http://nanoc.stoneship.org/manual/">manual oficial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://antarticonorte.com/blog/2010/01/09/empezando-con-nanoc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo usar markdown en Rails</title>
		<link>http://antarticonorte.com/blog/2010/01/04/como-usar-markdown-en-rails/</link>
		<comments>http://antarticonorte.com/blog/2010/01/04/como-usar-markdown-en-rails/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 08:30:50 +0000</pubDate>
		<dc:creator>Al-x</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[bluecloth]]></category>
		<category><![CDATA[markdown]]></category>

		<guid isPermaLink="false">http://antarticonorte.com/blog/?p=170</guid>
		<description><![CDATA[Me encanta markdown. Tiene una sintaxis fácil de aprender y convive muy bien con texto existente en HTML. Es un buen lenguaje para foros o blogs, ya que permite dar formato de forma sencilla sin necesidad de saber HTML.
Recientemente quería usar markdown para un proyecto que estoy haciendo con Rails. El framework ofrece un método [...]]]></description>
			<content:encoded><![CDATA[<p>Me encanta <a href="http://daringfireball.net/projects/markdown/">markdown</a>. Tiene una <a href="http://daringfireball.net/projects/markdown/syntax">sintaxis</a> fácil de aprender y convive muy bien con texto existente en HTML. Es un buen lenguaje para foros o blogs, ya que permite dar formato de forma sencilla sin necesidad de saber HTML.</p>
<p>Recientemente quería usar markdown para un proyecto que estoy haciendo con Rails. El framework <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M001750">ofrece un método</a> para trabajar directamente con markdown, pero es necesario tener instalada una librería externa a Rails. En mi caso opté por BlueCloth.</p>
<p><span id="more-170"></span></p>
<p>Para usar bluecloth basta con instalar la gema</p>
<pre class="term">
$ sudo gem install bluecloth
</pre>
<p>NOTA: en algunas guías he visto el comando <code>sudo gem install BlueCloth</code> en vez de <code>bluecloth</code>. RubyGems es sensible a mayúsculas y minúsculas y al usar <code>BlueCloth</code> se instala una versión antigua de la gema.</p>
<h3>Haciendo que Rails reconozca bluecloth</h3>
<p>Para que Rails permita usar el método <code>markdown</code> debemos indicarle que queremos usar bluecloth. Para ello modificamos el fichero <code>config/environment.rb</code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  ...
  <span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;bluecloth&quot;</span>
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Reiniciamos el servidor de desarrollo para que reconozca nuestros cambios y voila! Usar markdown en nuestras vistas es tan simple como llamar al helper <code>markdown</code></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- cosas... --&gt;</span>
<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> markdown variable %&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- otras cosas... --&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://antarticonorte.com/blog/2010/01/04/como-usar-markdown-en-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

