A ColdFusion Nerd's love for Lorem Ipsum
As a distraction from the insanity of client development, I thought it would be fun to mark off one of the ColdFusion to-do items on my list.
Like any good ColdFusion nerd, I have a list of things I want to accomplish with my favorite programming language. There are user defined functions on my list, Mango Blog plugins on my list, ColdFusion websites on the list, you name it.
The list also contains several CF-related blog post topics I would love to write about. I'm definitely no Ben Nadel or Raymond Camden, but I do have my fair share of blogability in me.
Well, not long ago I decided to try tackling two items about once: a Mango Blog plugin and a new UDF for CFlib.org. I had an idea for a simple UDF that I could easily convert into a Mango Blog plugin.
After a few hours of work, I am proud to say that effort paid off in the form of cfLipsum.
The Background
In several of the CF projects I have been a part of over the years, at some point in time there has been a need to go out and copy/paste some Lorem Ipsum filler content.
Lorem Ipsum is simply dummy text of the printing and typesetting industry that the web design and development world adapted as part of their own. It is used as a place holder to demonstrate how actual content will look in a design or site.
It dawned on me a long time ago that I should be coding a solution for that, rather than going to Lipsum.com and CTRL C'ing the filler content I needed. Then one day I noticed that Lipsum.com had a feed.
And an idea was born.
The User Defined Function
I thought to myself, if I am going to spend time and develop a simple solution involing the Lipsum.com feed, why not also make sure it is capable of being accepted to CFlib.org.
"The purpose of the Common Function Library Project (CFLib.org) is to create a set of user-defined function (UDF) libraries for ColdFusion 5.0 and higher."
Having used CFlib.org a number of times to find string functions and other handy snippets of code, I have been meaning to contribute and give back. Coming up with a UDF to handle the Lipsum.com feed seemed like a good first submission attempt.
Enter cfLipsum. This function allows for outputting lorem ipsum text on the fly. It converts a feed of lorem ipsum text from Lipsum.com into a formatted or unformatted return string for output.
The beauty of the simple feed is that it outputs a different string of lorem ipsum text every time. This is a handy function to have when creating mockups on the fly. For those of us not on ColdFusion Builder yet, this provides a way to use a function call to output random filler content.
The code is fairly self-explanatory.
<cffunction name="cfLipsum" output="no" returntype="string" displayname="cfLipsum" hint="get a lorem ipsum string from lipsum.com">
<cfargument name="isFormatted" type="numeric" required="no" default="1" />
<cfset var theXML = "" />
<cfset var theGrab = "" />
<cfset var theLipsum = "" />
<cfset var theLipsumFeed = "http://www.lipsum.com/feed/xml" />
<!--- get the xml feed --->
<cfhttp url="#theLipsumFeed#" method="get" resolveUrl="false" />
<!--- parse and search xml for lorem ipsum --->
<cfset theXML = XMLParse(cfhttp.filecontent) />
<cfset theGrab = XMLSearch(theXML, "/feed") />
<!--- only one lorem ipsum element in the feed --->
<cfset theLipsum = theGrab[1].lipsum.xmltext />
<!--- strips lorem ipsum text of punctuation and uppercase --->
<cfif arguments.isFormatted neq 1>
<cfset theLipsum = lcase(rereplacenocase(theLipsum, "[^a-z0-9 ]", "", "all")) />
</cfif>
<cfreturn theLipsum />
</cffunction>
The Mango Blog Plugin
Since I work with Mango Blog on a regular basis, I thought it would be a good idea to convert cfLipsum into a Mango plugin.
I created a plugin that converts a tag ([lipsum:<i>numWords</i>]) in a post/page into a string of lorem ipsum text. The plug communicates with a feed from Lipsum.com and outputs up to 500 words of lorem ipsum filler text.
The idea for usage of this plugin is to make it easier to fill pages and posts during the construction phase of a blog. Often times it helps clients to see the actual design of a page in action. Filler text helps to communicate the design without any actual content.
View the Laura's post on Mango Lipsum plugin here.
2 Comments
Roman Eckert wrote on 07/23/10 1:54 AM
Look at: http://www.lorem-ipsum-generator.de/
Greetz Rom




andy matthews wrote on 05/05/10 11:20 AM
Lorem Ipsum is great and all, but it gets a little dull after enough use. Why not spice things up a little? Check out this filler text app I wrote a while back.
http://andymatthews.net/code/fillertext/