2007-05-19 03:10:50 links redux
php version of links template controller:

( php )
  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 )
  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 )
  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()
Leave a comment