Quantcast
Channel: Niko » Downloads
Viewing all articles
Browse latest Browse all 3

QuickNav Coda Plugin: Makes Navs On The Fly

$
0
0

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:

[html]Home
About Us
Portfolio
Contact[/html]

And turns it into this:

[html]
<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>
[/html]

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.

[ruby]
#!/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
[/ruby]

Download

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

Download QuickNav.zip (8kb)


Viewing all articles
Browse latest Browse all 3

Trending Articles