CFLib.org – Common Function Library Project

Byline(names [, editors] [, extrasMode])

Last updated October 10, 2002
Download UDF

author

Gyrus                                             Gyrus

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

Description:
Generate a byline from a comma-delimited list of one or more names, in the format 'by X[, Y & Z]'. Also extensible to perform extra functions: currently included is the ability to generate links to iMDB for each name.

Return Values:
Returns a string.

Example:

<cfoutput>
Naked Lunch, #Byline("William S. Burroughs")#<br />
Boring Book, #Byline("F.P. Morden,B.J. Smith,A.B.Q. Forsythe", TRUE)#<br />
Santa Sangre, directed #Byline("Alejandro Jodorowsky", FALSE, "imdb")#<br />
</cfoutput>

Parameters:

Name Description Required
names List of Names. Yes
editors Boolean signifying that the list is a list of editors. Defaults to false. No
extrasMode String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". No

Full UDF Source:

<cfscript>
/**
* Generates a byline from a list of names.
*
* @param names      List of Names. (Required)
* @param editors      Boolean signifying that the list is a list of editors. Defaults to false. (Optional)
* @param extrasMode      String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". (Optional)
* @return Returns a string.
* @author Gyrus (gyrus@norlonto.net)
* @version 1, October 10, 2002
*/

function Byline(names) {
    // Initialise
    var i = 0;
    var name = "";
    var bylineString = "";
    var edited = FALSE;
    var extrasMode = "none";
    if (ArrayLen(Arguments) GT 1) {
        edited = Arguments[2];
    }
    if (ArrayLen(Arguments) GT 2) {
        extrasMode = Arguments[3];
    }
    // Loop through names
    if (ListLen(names)) {
        for (i=1; i LTE ListLen(names); i=i+1) {
            name = ListGetAt(names, i);
            // Edited?
            if (edited) {
                name = "#name# (ed.)";
            }
            // Perform extras
            switch (extrasMode) {
                case "imdb": {
                    name = "<a href=""http://uk.imdb.com/Name?#Replace(name,' ','+','ALL')#"" title=""check for information on this person on the Internet Movie Database"">#name#</a>";
                    break;
                }
            }
            if (i EQ 1) {
                bylineString = "
by #name#";
            } else if (i EQ ListLen(names)) {
                bylineString = "
#bylineString# &amp; #name#";
            } else {
                bylineString = "
#bylineString#, #name#";
            }
        }
    }
    return bylineString;
}
</cfscript>

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
3 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson