Created
January 28, 2022 11:43
-
-
Save mcnemesis/33fa0c4313d2f44cdcfcbe88a3e28a38 to your computer and use it in GitHub Desktop.
Tale of The Table Maker --- a code poem by JWL (nemesisfixx)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************** Tale of The Table Maker ********************** | |
*********************************************************************** | |
* CODE POET: nemesisfixx | |
*********************************************************************** | |
* | |
* Once, when presented with a box of obscure things, | |
* and a style of table desired, | |
* the craftsman had to do his magic on them, then | |
* hand back a brand-new table, ready to be used! | |
* | |
* It was such an arcane, exhilirating art, | |
* known to none, but the hell-bent, stone-hearted | |
* initiates of TOOTA, The Order of Thing-Alchemy. | |
* | |
* However, Nixx the Poet came across their secret recipe, | |
* Which he only reffered to as "the just code", | |
* With which he performed these wonders for himself, using | |
* just guts and arcane spells known to initiates as "procedure calls". | |
* | |
* In utter secrecy, he preserved the most important of their spells, | |
* in outlandish prose stashed inside a vase labelled | |
* "This Tool Shall Make Tables of Anything". | |
* | |
**********************************************************************/ | |
this.thisToolShallMakeTablesOfAnything = | |
function(box_of_things, tableStyleWanted) { | |
// in the begining, there was no table, | |
// but, there was... | |
var first_samples_from_box_of_things = box_of_things[0]; | |
// and an empty idea of what the table shall look like from above.. | |
var the_table_top_stuff = []; | |
// then, voila! | |
for (something in first_samples_from_box_of_things) { | |
the_table_top_stuff.push(something); | |
} | |
// we can make a table rite won! | |
var theTable = $('<table/>') | |
, partTableTop = $('<thead/>') | |
, partTableBase = $('<tbody/>') | |
, partTableTopSection = $('<tr/>'); | |
// in the style desired, yes! | |
if (tableStyleWanted) | |
theTable.addClass(tableStyleWanted); | |
// starting with the top? Anha.. | |
for (part in the_table_top_stuff) { | |
partTableTopSection.append($('<th/>', { | |
'class': the_table_top_stuff[part] | |
}).text(the_table_top_stuff[part])); | |
} | |
// Ready the table's top already. | |
partTableTop.append(partTableTopSection) | |
/******************************************** | |
* WAIT: welcome to table craftsmanship 101 | |
* *****************************************/ | |
// However, the devil is in the guts of it... | |
for (element in box_of_things) { | |
// Make several conjurations on things and hold breath... | |
var thing = box_of_things[element]; | |
var partTableBaseSection = $('<tr/>'); | |
for (part in the_table_top_stuff) { | |
var thing_inside_thing = thing[the_table_top_stuff[part]]; | |
if( | |
(thing_inside_thing != undefined) | |
&& isBEAN(thing_inside_thing) | |
){ | |
// give special attention bean-like-stuff... gooey! | |
partTableBaseSection.append($('<td/>', { | |
'class': the_table_top_stuff[part] | |
}).append( | |
$('<iframe/>', | |
{ | |
'src': thing_inside_thing, | |
'frameborder': 0, | |
'style': 'width:100%; height:321px' | |
}))); | |
}else { | |
partTableBaseSection.append($('<td/>', { | |
'class': the_table_top_stuff[part] | |
}).text(thing_inside_thing)); | |
} | |
} | |
partTableBase.append(partTableBaseSection) | |
} | |
// Yippie! We've conjurred the table's base! | |
// Already all ready! | |
// Heck, like pizza, just add the top to the base and... | |
theTable.append(partTableTop).append(partTableBase) | |
// Guessed right, | |
// theTable is a perfectly finished Table! | |
// So, let's hand it over... | |
return theTable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment