<?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>Jetpack Flight Log &#187; sparkup</title>
	<atom:link href="http://jetpackweb.com/blog/tags/sparkup/feed/" rel="self" type="application/rss+xml" />
	<link>http://jetpackweb.com/blog</link>
	<description>Rock{et}ing the interweb</description>
	<lastBuildDate>Wed, 19 May 2010 22:21:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Write HTML Faster with Sparkup (Vim and Textmate)</title>
		<link>http://jetpackweb.com/blog/2010/03/04/write-html-faster-with-sparkup-vim-and-textmate/</link>
		<comments>http://jetpackweb.com/blog/2010/03/04/write-html-faster-with-sparkup-vim-and-textmate/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 18:58:31 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[textmate]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[sparkup]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=770</guid>
		<description><![CDATA[I recently came across a really great Vim(and Textmate) plug-in called sparkup.vim that &#8220;lets you write HTML code faster&#8221;. It&#8217;s actually a small python script, but has editor plug-ins to work with Vim and Textmate. It allows us to write HTML faster by leveraging the terse css selector syntax and converting it the much more [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a really great Vim(and Textmate) plug-in called <a href="http://github.com/rstacruz/sparkup" target="_blank">sparkup.vim</a> that &#8220;lets you write HTML code faster&#8221;. It&#8217;s actually a small python script, but has editor plug-ins to work with Vim and Textmate. It allows us to write HTML faster by leveraging the terse css selector syntax and converting it the much more verbose HTML.</p>
<h2>Selector Expansion</h2>
<p>Selector expansion is the plug-in&#8217;s primary purpose. It lets you write in a CSS selector syntax that get expanded to full HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family: Monaco, monospace;"><span class="re0">#album</span>.photo</pre></div></div>

<p>If you type that into vim and then press <strong>Ctrl-e</strong> on that line it will be expanded to:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family: Monaco, monospace;"><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;album&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;photo&quot;</span><span class="re2">&gt;</span></span>|<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></pre></div></div>

<p>This next one is a bit more complicated, I&#8217;ll explain what&#8217;s going on:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family: Monaco, monospace;"><span class="re0">#container</span> <span class="sy0">&gt;</span> <span class="re0">#nav</span> <span class="sy0">&gt;</span> ul <span class="sy0">&gt;</span> li<span class="re1">.first</span> <span class="br0">&#123;</span>Home<span class="br0">&#125;</span> <span class="sy0">+</span> li<span class="sy0">*</span><span class="nu0">2</span> <span class="sy0">+</span> li<span class="re1">.last</span> <span class="br0">&#123;</span>About Us<span class="br0">&#125;</span> &lt; &lt;  <span class="re0">#content</span> <span class="sy0">&gt;</span> p<span class="sy0">*</span><span class="nu0">2</span> &lt; <span class="re0">#footer</span> <span class="sy0">&gt;</span> span<span class="re1">.copyright</span> <span class="br0">&#123;</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span> <span class="nu0">2010</span> Jetpack LLC<span class="br0">&#125;</span></pre></div></div>

<blockquote>
<ol>
<li>Creating a div with the id of &#8220;container&#8221;</li>
<li>Creating a div with an id of &#8220;<i>nav</i>&#8221; that is a child of the &#8220;<i>container</i>&#8221; div. The > specifies we are creating a child element in the DOM tree.</li>
<li>Creating a ul tag that is a child of &#8220;<i>nav</i>&#8220;</li>
<li>Creating an li tag with the class name &#8220;<i>first</i>&#8220;. Text in brackets will be plain text placed in-between the tag we are creating.</li>
<li>Creating two sibling li elements. The <strong>+</strong> denotes what comes next will be a sibling. The <strong>*</strong> is a multiplier to create any number of similar elements.</li>
<li>Creating an li tag with the class name &#8220;<i>last</i>&#8221; as a sibling to the previous li elements we have created. It will contain the text &#8216;<i>About Us</i>&#8216;.</li>
<li>Next now use the <strong><</strong> symbol to go up two levels of the DOM tree.</li>
<li>Next we create a div with the id of &#8220;<i>content</i>&#8221; that will contain two paragraph tags.</li>
<li>We go back up a level and add a footer div that will have a span with the class of &#8220;<i>copyright</i>&#8221; that contains some boilerplate copyright text.</li>
</ol>
</blockquote>
<p>If we press <strong>Ctrl-e</strong> on that line, it will be expanded to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family: Monaco, monospace;">  <span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;container&quot;</span><span class="re2">&gt;</span></span>
    <span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;nav&quot;</span><span class="re2">&gt;</span></span>
      <span class="sc3"><span class="re1">&lt;ul<span class="re2">&gt;</span></span></span>
        <span class="sc3"><span class="re1">&lt;li</span> <span class="re0">class</span>=<span class="st0">&quot;first&quot;</span><span class="re2">&gt;</span></span>Home<span class="sc3"><span class="re1">&lt;/li<span class="re2">&gt;</span></span></span>
        <span class="sc3"><span class="re1">&lt;li<span class="re2">&gt;</span></span></span>|<span class="sc3"><span class="re1">&lt;/li<span class="re2">&gt;</span></span></span>
        <span class="sc3"><span class="re1">&lt;li<span class="re2">&gt;</span></span><span class="re1">&lt;/li<span class="re2">&gt;</span></span></span>
        <span class="sc3"><span class="re1">&lt;li</span> <span class="re0">class</span>=<span class="st0">&quot;last&quot;</span><span class="re2">&gt;</span></span>About Us<span class="sc3"><span class="re1">&lt;/li<span class="re2">&gt;</span></span></span>
      <span class="sc3"><span class="re1">&lt;/ul<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;content&quot;</span><span class="re2">&gt;</span></span>
      <span class="sc3"><span class="re1">&lt;p<span class="re2">&gt;</span></span><span class="re1">&lt;/p<span class="re2">&gt;</span></span></span>
      <span class="sc3"><span class="re1">&lt;p<span class="re2">&gt;</span></span><span class="re1">&lt;/p<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;footer&quot;</span><span class="re2">&gt;</span></span>
      <span class="sc3"><span class="re1">&lt;span</span> <span class="re0">class</span>=<span class="st0">&quot;copyright&quot;</span><span class="re2">&gt;</span></span>(c) 2010 Jetpack LLC<span class="sc3"><span class="re1">&lt;/span<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></pre></div></div>

<p>It will also place your cursor in the first empty tag denoted by the <strong>|</strong>. You can jump around to other empty tags with <strong>Ctrl-n</strong> (I change this mapping, more on that in a second).</p>
<p>If you are a fan of <a href="http://haml-lang.com/" target="_blank">HAML</a> but forced to use standard HTML in your projects this plug-in might make you a bit happier.</p>
<h2>Shortcuts</h2>
<p>The other piece of functionality this plug-in provides is a <a href="http://www.vim.org/scripts/script.php?script_id=2540" target="_blank">snipMate</a> like shortcuts feature. These act much like snipMate snippets except they are hard-coded into the python script. However most are still quite useful and you can view the <a href="http://github.com/rstacruz/sparkup/blob/master/sparkup" target="_bank">python script</a> to review them.</p>
<h2>Issues</h2>
<p>After installing this plugin I was having tabbing/tab-expansion issues. I believe it&#8217;s <strong>Ctrl-n</strong> mapping which allows you to jump around to empty tags was conflicting with some other plug-in I had installed, possibly <a href="http://www.vim.org/scripts/script.php?script_id=1643" target="_blank">SuperTab</a>. I remapped it by putting the following in my .vimrc:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family: Monaco, monospace;"><span class="kw1">let</span> g<span class="sy0">:</span>sparkupNextMapping = <span class="st0">'&lt;c-x&gt;'</span></pre></div></div>

<p>That doesn&#8217;t seem to conflict with anything for me, and since it only gets used in normal mode it doesn&#8217;t conflict with Tim Pope&#8217;s excellent <a href="http://github.com/tpope/vim-ragtag" target="_blank">ragtag</a> plug-in (<a href="http://www.catonmat.net/blog/vim-plugins-ragtag-allml-vim/" target="_blank">read more on that here</a>).</p>
<h2>Video Demonstration</h2>
<p>Some of this might make more sense when you see it in action, so watch the following YouTube video(make sure to switch it to 720p for crisper text):</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/Jw3jipcenKc&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Jw3jipcenKc&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<h2>Conclusion</h2>
<p>Have fun writing faster HTML! You can see more examples on <a href="http://github.com/rstacruz/sparkup" target="_blank">sparkup&#8217;s Github page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2010/03/04/write-html-faster-with-sparkup-vim-and-textmate/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
