php version of links template controller:
( php ) ✂
<?php
include( '.Controller.php' );
class Control extends Controller {
function __construct() {
parent::__construct();
$page = new WebPage( 'HyperJeff Blog Lynks of Olde' );
$links = new Table( 'links', 'blog' );
foreach( $links->each( 'created', 'desc', $page->fieldFromTemplate( 'linksToShow' ) ) as $link ) {
$dateParts = split( ' ', $link['created'] );
$year = $dateParts[0];
$page->setMultipleFieldsForTemplate( 'links', array(
'linkDate' => $year,
'linkTitle' => $link['title'],
'linkURL' => $link['url'],
'linkComment' => $link['comment'],
'linkCommentSpot' => ($link['comment'] ? '' : ' '),
));
}
print $page->fullPage();
}
}
new Control();
?>
1 <?php
2 include( '.Controller.php' );
3
4 class Control extends Controller {
5
6 function __construct() {
7 parent::__construct();
8 $page = new WebPage( 'HyperJeff Blog Lynks of Olde' );
9 $links = new Table( 'links', 'blog' );
10
11 foreach( $links->each( 'created', 'desc', $page->fieldFromTemplate( 'linksToShow' ) ) as $link ) {
12 $dateParts = split( ' ', $link['created'] );
13 $year = $dateParts[0];
14 $page->setMultipleFieldsForTemplate( 'links', array(
15 'linkDate' => $year,
16 'linkTitle' => $link['title'],
17 'linkURL' => $link['url'],
18 'linkComment' => $link['comment'],
19 'linkCommentSpot' => ($link['comment'] ? '' : ' '),
20 ));
21 }
22 print $page->fullPage();
23 }
24 }
25 new Control();
26 ?>
f-script version:
( fscript ) ✂
#!/usr/bin/fscript
(NSBundle bundleWithPath:'_obj/Core.bundle') load.
page := Page alloc initWithTitle:'HyperJeff Blog Lynks of Olde'.
links := Table alloc initWithTable:'links' inDatabase:'blog'.
links nullEquals:''.
allLinks := links allRecordsSortedBy:'created' ascending:false.
keys := { 'linkDate', 'linkTitle', 'linkURL', 'linkComment', 'linkCommentSpot' }.
linksToFields := [ :link |
url := link valueForKey:'url'.
date := ((link valueForKey:'created') description split:' ') at:0.
title := link valueForKey:'title'.
comment := link valueForKey:'comment'.
commentSpot := (comment description='' ifTrue:[' '] ifFalse:['']).
{ date, title, url, comment, commentSpot }
].
page setField:'links' withValues:(linksToFields value:@allLinks) forKeys:keys.
page displayFullPage.
1 #!/usr/bin/fscript
2 (NSBundle bundleWithPath:'_obj/Core.bundle') load.
3
4 page := Page alloc initWithTitle:'HyperJeff Blog Lynks of Olde'.
5 links := Table alloc initWithTable:'links' inDatabase:'blog'.
6 links nullEquals:''.
7
8 allLinks := links allRecordsSortedBy:'created' ascending:false.
9 keys := { 'linkDate', 'linkTitle', 'linkURL', 'linkComment', 'linkCommentSpot' }.
10
11 linksToFields := [ :link |
12 url := link valueForKey:'url'.
13 date := ((link valueForKey:'created') description split:' ') at:0.
14 title := link valueForKey:'title'.
15 comment := link valueForKey:'comment'.
16 commentSpot := (comment description='' ifTrue:[' '] ifFalse:['']).
17
18 { date, title, url, comment, commentSpot }
19 ].
20 page setField:'links' withValues:(linksToFields value:@allLinks) forKeys:keys.
21 page displayFullPage.
And now, some Python (via PyObjC):
( python ) ✂
#!/usr/local/bin/python
import objc
from Foundation import *
NSBundle.bundleWithPath_( 'Core.bundle' ).load()
page = objc.lookUpClass( 'Page' ).pageWithTitle_( 'HyperJeff Blog Lynks of Olde' )
links = objc.lookUpClass( 'Table' ).alloc().initWithTable_inDatabase_( 'links', 'blog' )
allLinks = links.allRecordsSortedBy_ascending_( 'created', False )
keys = [ 'linkDate', 'linkTitle', 'linkURL', 'linkComment', 'linkCommentSpot' ]
linksToFields = []
for link in allLinks:
comment = link['comment']
if str(comment)=='None':
comment = ''
commentSpot = ' '*(comment=='')
date = str( link['created'] ).split(' ')[0]
linksToFields.append( [ date, link['title'], link['url'], comment, commentSpot ] )
page.setField_withValues_forKeys_( 'links', linksToFields, keys )
page.display()
1 #!/usr/local/bin/python
2 import objc
3 from Foundation import *
4 NSBundle.bundleWithPath_( 'Core.bundle' ).load()
5
6 page = objc.lookUpClass( 'Page' ).pageWithTitle_( 'HyperJeff Blog Lynks of Olde' )
7 links = objc.lookUpClass( 'Table' ).alloc().initWithTable_inDatabase_( 'links', 'blog' )
8
9 allLinks = links.allRecordsSortedBy_ascending_( 'created', False )
10 keys = [ 'linkDate', 'linkTitle', 'linkURL', 'linkComment', 'linkCommentSpot' ]
11
12 linksToFields = []
13 for link in allLinks:
14 comment = link['comment']
15 if str(comment)=='None':
16 comment = ''
17 commentSpot = ' '*(comment=='')
18 date = str( link['created'] ).split(' ')[0]
19 linksToFields.append( [ date, link['title'], link['url'], comment, commentSpot ] )
20
21 page.setField_withValues_forKeys_( 'links', linksToFields, keys )
22 page.display()