<?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>mdgArt &#187; Coda</title>
	<atom:link href="http://www.mdgart.com/tag/coda/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mdgart.com</link>
	<description>Art &#38; Programming</description>
	<lastBuildDate>Thu, 08 Apr 2010 17:59:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to develop a Plug-in for Panic Coda with Python</title>
		<link>http://www.mdgart.com/2009/03/31/how-to-develop-a-plug-in-for-panic-coda-with-python/</link>
		<comments>http://www.mdgart.com/2009/03/31/how-to-develop-a-plug-in-for-panic-coda-with-python/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:09:33 +0000</pubDate>
		<dc:creator>Mauro</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Coda]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[panic]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.mdgart.com/?p=72</guid>
		<description><![CDATA[If you are (like me) a mac fan and you use the excellent Panic Coda to develop, you should know that is now possible to write plugins with every languages you want (if you have the interpreter installed on your system).
Python is bundled on every mac, and is also a beautiful and simple language, so [...]]]></description>
			<content:encoded><![CDATA[<p>If you are (like me) a mac fan and you use the excellent <a href="http://www.panic.com/coda/" target="_blank">Panic Coda</a> to develop, you should know that is now possible to write plugins with every languages you want (if you have the interpreter installed on your system).<br />
Python is bundled on every mac, and is also a beautiful and simple language, so i want to show how to develop a simple plugin for Coda with Python!<br />
First of all you need to download the <a href="http://www.panic.com/coda/developer/howto/plugins.php" target="_blank">Coda Plug-in Creator</a> that is the application that will convert your python script into a brand new plugin.<br />
<span id="more-72"></span><br />
The plugin that we are going to create is simple but useful; it will convert the selected rows in the current document into a html unordered list:</p>
<p>Remember the milk<br />
Build a Coda Plugin<br />
Clean the house<br />
Feed the cats</p>
<p>will become</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;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Remember the milk<span style="color: #009900;">&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;</span>Build a Coda Plugin<span style="color: #009900;">&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;</span>Clean the house<span style="color: #009900;">&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;</span>Feed the cats<span style="color: #009900;">&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></pre></div></div>

<p>Simple but enough to understand the principle of making a pulgin,  however it can be useful in some situations when you need a &#8220;raw list&#8221; on your page.<br />
So, let&#8217;s get started! Fire up your text editor and enter this python code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/sw/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">import</span>	<span style="color: #dc143c;">sys</span>
&nbsp;
text = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
unorderedlist = <span style="color: #483d8b;">&quot;&lt;ul&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> 
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> text.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	unorderedlist = unorderedlist + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;li&gt;&quot;</span> + line + <span style="color: #483d8b;">&quot;&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
unorderedlist = unorderedlist + <span style="color: #483d8b;">&quot;&lt;/ul&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>unorderedlist<span style="color: black;">&#41;</span></pre></div></div>

<p>Save it as textToList.py. The code is very simple: after importing the sys module, we read the standard input with sys.stdin.read() and we put it on the variable <i>text</i>.<br />
Next we initialize a string called <i>unorderedlist</i> with the first html element we need to build the structure, and then we read every single line of the selection, using splitlines() method on the text string, to create every single list entry.<br />
Finally, we pass the complete unorderedlist string to the standard output with sys.stdout.write().</p>
<p>Now open the Coda plug-in creator, click on <strong>Add Command</strong> button and name it textToList (or what you want) drag and drop the <code>textToList.py</code> in the <strong>Script</strong> input field, choose <i>Selection</i> in the <strong>STDIN</strong> popup menu and <i>Replace Selection</i> in the <strong>STDOUT</strong> popup menu (to know how to use this settings please refear to the <a href="http://www.panic.com/coda/developer/howto/plugins.php" target="_blank">Coda developer documentations</a>) and save the plugin with a nice name (like textToList for example, lol). </p>
<p>That&#8217;s it! Our brand new plugin is ready to be installed! Double click on it and you will find it in the <strong>plugin</strong> menu. To test it write some line of text, select the lines, and then choose textToList from the plugin menu.</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 160px"><a href="http://www.mdgart.com/python/CodaPlugin/textToList.py"><img src="http://www.mdgart.com/wp-content/uploads/2009/03/download.png" alt="Download the code of this article" title="download" width="48" height="48" class="size-full wp-image-66" /></a><p class="wp-caption-text">Download the code of this article</p></div>
<p>Enjoy!</p>
<p>If you like this article, please write a comment and share it! Thanks <img src='http://www.mdgart.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="mauro@ondadiluce.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy me a coffe for How to develop a Plug-in for Panic Coda with Python" /><input type="hidden" name="currency_code" value="EUR" /><input type="hidden" name="amount" value="1" /><input type="image" src="http://www.mdgart.com/wp-content/plugins/buy-me-beer/icon_cafe.gif" align="left" alt="Buy me a coffe" title="Buy me a coffe" hspace="3" style="border:0;" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=mauro@ondadiluce.com&amp;currency_code=EUR&amp;amount=1&amp;return=&amp;item_name=Buy+me+a+coffe+for+How+to+develop+a+Plug-in+for+Panic+Coda+with+Python" target="paypal">Donate 1 euro, buy me a coffee, I need it to write more posts! Thanks ;)</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mdgart.com/2009/03/31/how-to-develop-a-plug-in-for-panic-coda-with-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
