You see sentences like this in many many blogs. I have empathy for the authors who diligently markup each word with a different URL, but it is a wonderful way to describe and hyperlink in a meaningful way.
In the above fabricated, never-before-published quote, all the links are from a Google Groups search. So I knew I’d want to auto-generate it, because the mere thought of manual labour drives me to automation.
This resulted in the new sentence_with_links gem (I like bundling small chunks of code in new gems instead of stand alone library files so that the README file and test cases are encapsulated with the library code).
> gem install sentence_with_links
String now has a
with_links method, that generates the HTML as above. What if there are more links than words in the sentence? See the “Jessica Simpson” image search example below.
Mashup with Google Groups
Mashup with Google Images using JSON API
Note how the
with_links function handles more links than sentence words? It appends a multitude of ‘here’ links. If you can think of more pleasurable alternatives, let me know. Either way, we don’t want to miss out on any important Jessica Simpson images. They are all there.
First, get the JSON Ruby parser:
gem install json
Then slap it all together…
And there you have it, sentences with links, the lazy Ruby way.
- Meta-Magic in Ruby: Dr Nic Unplugged in Stockholm Last nights’ Ruby meeting in Stockholm had a great turn...
- 53 cheat sheets and growing I said previously that errtheblog’s cheat app would have 100s+...
- [ANN] Dr Nic’s Magic Models 0.8 – Validate Anything, Anytime, Anywhere Ladies and Gentlemen, welcome one and all to the greatest...
- Exporting Netvibes bookmarks to Del.icio.us For 12 months I’ve been using Netvibes to store bookmarks....