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

 
Rated 0 time(s). Average Rating: 0

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

Ryan Thompson-Jewell Ryan Thompson-Jewell added
ListSplit
2 day(s) ago

Nathan Dintenfass Nathan Dintenfass added
RowsToColumns
2 day(s) ago

Barney Boisvert Barney Boisvert added
indentXml
3 day(s) ago

Barney Boisvert Barney Boisvert added
REReplaceCallbac...
3 day(s) ago

Top Rated

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 7 time(s)

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Jeff Howden ListDeleteDuplic...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson