Oct
14
QuickNav Coda Plugin: Makes Navs On The Fly

It’s no secret that I have a bit of a thing for Coda and for good reason. The one-widow text editor is light, fast and looks good too. One thing that I have found especially awesome is the ridiculous easiness of creating plug-ins. The Coda Plug-in creator lets you write your scripts in any programming language your little heart desires (assuming a compiler for said language is installed on your machine). I thought I’d give plug-in creation a try and whipped up something real quick.

The Plug-in

Basically, the plug-in speeds up coding pages by replacing an unstructured list like this:

Home
About Us
Portfolio
Contact

And turns it into this:

<ul id="nav">
	<li><a href="index.php">Home</a></li>
	<li><a href="about-us.php">About Us</a></li>
	<li><a href="portfolio.php">Portfolio</a></li>
	<li><a href="contact.php">Contact</a></li>
</ul>

All you need to do is highlight the text and run the plug-in and you get a nice little unordered-list navigation.

The Source

The plug-in is written in Ruby and is very simple. You could easily go in and modify how the list items are made and what the links should look like if my format doesn’t work for you. You’ll also notice that it replaces the word “Home” with index for the link.

#!/usr/bin/ruby

nav = "<ul id='$$IP$$'>\n"
$stdin.each_line do |line|
	line.rstrip!
	url = line.gsub(" ", "-").gsub("Home", "index").gsub("\t", "")
	nav = nav + "\t<li><a href=\""+ url.downcase + ".php\">" + line.split(" ").each{|word| word.capitalize!}.join(" ") + "</a></li>\n"
end

nav = nav + "</ul>\n"

puts nav

Download

Download the plug-in and drag it into the Plug-ins folder located in Library > Application Resources > Coda.

Download QuickNav.zip (8kb)

October 14, 2010 0 Replies Tags: ,

Share on: Facebook | Twitter

0 Comments

Jump Down To Comment

No comments yet

Got Something To Say?

Get your own global avatar at Gravatar