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 i want to show how to develop a simple plugin for Coda with Python!
First of all you need to download the Coda Plug-in Creator that is the application that will convert your python script into a brand new plugin.
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:
Remember the milk
Build a Coda Plugin
Clean the house
Feed the cats
<ul> <li>Remember the milk</li> <li>Build a Coda Plugin</li> <li>Clean the house</li> <li>Feed the cats</li> </ul>
Simple but enough to understand the principle of making a pulgin, however it can be useful in some situations when you need a “raw list” on your page.
So, let’s get started! Fire up your text editor and enter this python code:
#!/sw/bin/python import sys text = sys.stdin.read() unorderedlist = "<ul>\n" for line in text.splitlines(): unorderedlist = unorderedlist + "\t<li>" + line + "</li>\n" unorderedlist = unorderedlist + "</ul>\n" sys.stdout.write(unorderedlist)
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 text.
Next we initialize a string called unorderedlist 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.
Finally, we pass the complete unorderedlist string to the standard output with sys.stdout.write().
Now open the Coda plug-in creator, click on Add Command button and name it textToList (or what you want) drag and drop the
textToList.py in the Script input field, choose Selection in the STDIN popup menu and Replace Selection in the STDOUT popup menu (to know how to use this settings please refear to the Coda developer documentations) and save the plugin with a nice name (like textToList for example, lol).
That’s it! Our brand new plugin is ready to be installed! Double click on it and you will find it in the plugin menu. To test it write some line of text, select the lines, and then choose textToList from the plugin menu.
If you like this article, please write a comment and share it! ThanksDonate 1 euro, buy me a coffee, I need it to write more posts! Thanks ;) Tags: Coda, mac, osx, panic, plugin, Python, tutorial, webdev