From b606066fd0152a7569e4a82a1130c9a9135b54be Mon Sep 17 00:00:00 2001 From: Skial Bainn Date: Tue, 6 May 2014 15:22:18 +0100 Subject: [PATCH] minor --- src/uhx/sys/Tuli.hx | 22 ++++------- src/uhx/tuli/plugins/Atom.hx | 67 +++++++++++++++++--------------- src/uhx/tuli/plugins/RSS.hx | 74 +++++++++++++++++++----------------- 3 files changed, 84 insertions(+), 79 deletions(-) diff --git a/src/uhx/sys/Tuli.hx b/src/uhx/sys/Tuli.hx index 79f3246..9b70e94 100644 --- a/src/uhx/sys/Tuli.hx +++ b/src/uhx/sys/Tuli.hx @@ -117,21 +117,22 @@ class Tuli { // This is currently not saved, so the data has to be recreated on each call. // Call via your `hxml` file `--macro uhx.macro.Tuli.onData(pack.age.Class.callback)` public static function onData(callback:Dynamic->Dynamic, ?when:TuliState):Void { - //initialize(); - (when == null || when == Before) ? dataPluginsBefore.push( callback ) : dataPluginsAfter.push( callback ); + if (when == null) when = Before; + switch (when) { + case Before: dataPluginsBefore.push( callback ); + case After: dataPluginsAfter.push( callback ); + } } private static var finishCallbacksBefore:ArrayVoid> = []; private static var finishCallbacksAfter:ArrayVoid> = []; public static function onFinish(callback:Void->Void, ?when:TuliState):Void { - //initialize(); if (when == null) when = After; switch (when) { case After: finishCallbacksAfter.push( callback ); case Before: finishCallbacksBefore.push( callback ); } - //(when == null || when == After) ? finishCallbacksAfter.push( callback ) : finishCallbacksBefore.push( callback ); } private static var classes:Map> = new Map(); @@ -198,9 +199,6 @@ class Tuli { var item = allItems[index].normalize(); var location = '$path/$item'.normalize(); - /*if (!location.isDirectory()) { - files.push( item ); - } else {*/ if (location.isDirectory()) { allItems = allItems.concat( location.readDirectory().map( function(d) return '$item/$d'.normalize() ) ); } @@ -219,13 +217,9 @@ class Tuli { for (file in config.files) { var stats = '$path/${file.path}'.stat(); - //if (asISO8601( stats.mtime ) != file.modified) { - file.size = stats.size; - file.modified = asISO8601(stats.mtime); - file.stats = stats; - /*} else { - - }*/ + file.size = stats.size; + file.modified = asISO8601(stats.mtime); + file.stats = stats; } config.files = config.files.concat( [for (newItem in newItems) if (!'$path/$newItem'.isDirectory()) { diff --git a/src/uhx/tuli/plugins/Atom.hx b/src/uhx/tuli/plugins/Atom.hx index d4fa114..c84f4ce 100644 --- a/src/uhx/tuli/plugins/Atom.hx +++ b/src/uhx/tuli/plugins/Atom.hx @@ -70,40 +70,45 @@ class Atom { } - domEntry = entry.parse(); + var title = dom.find('h1').first().text().trim(); - domEntry.find('id').setText( id ); - domEntry.find('title').setText( dom.find('h1').first().text() ); - domEntry.find('summary').setText( dom.find('p').first().text() ); - domEntry.find('content').setAttr('src', id).setAttr('type','text/html'); - domEntry.find('published').setText( Tuli.asISO8601( file.stats.ctime ) ); - - domFeed.find('updated').setText( Tuli.asISO8601( file.stats.mtime ) ); - domEntry.find('updated').setText( Tuli.asISO8601( file.stats.mtime ) ); - - domFeed.find('link').setAttr('href', 'http://haxe.io/$path'); - domFeed.first().next().append( null, domEntry ); - // The following line causes a memory leak. - //domFeed.find('author').afterThisInsert( domEntry ); - - xmlCache.set( path, domFeed ); - - if (!xmlCache.exists( html + 'index.html' )) { - xmlCache.set( html + 'index.html', dom ); - } - - var result = domFeed.html(); - - while (result.indexOf('&') > -1) { - result = result.replace('&', '&'); - } - - for (key in Markdown.characters.keys()) { - result = result.replace(Markdown.characters.get( key ), key ); + if (title != '') { + domEntry = entry.parse(); + + domEntry.find('id').setText( id ); + domEntry.find('title').setText( title ); + domEntry.find('summary').setText( dom.find('p').first().text() ); + domEntry.find('content').setAttr('src', id).setAttr('type','text/html'); + domEntry.find('published').setText( Tuli.asISO8601( file.stats.ctime ) ); + + domFeed.find('updated').setText( Tuli.asISO8601( file.stats.mtime ) ); + domEntry.find('updated').setText( Tuli.asISO8601( file.stats.mtime ) ); + + domFeed.find('link').setAttr('href', 'http://haxe.io/$path'); + domFeed.first().next().append( null, domEntry ); + // The following line causes a memory leak. + //domFeed.find('author').afterThisInsert( domEntry ); + + xmlCache.set( path, domFeed ); + + if (!xmlCache.exists( html + 'index.html' )) { + xmlCache.set( html + 'index.html', dom ); + } + + var result = domFeed.html(); + + while (result.indexOf('&') > -1) { + result = result.replace('&', '&'); + } + + for (key in Markdown.characters.keys()) { + result = result.replace(Markdown.characters.get( key ), key ); + } + + Tuli.fileCache.set( path, result ); + } - Tuli.fileCache.set( path, result ); - dom = null; domFeed = null; domEntry = null; diff --git a/src/uhx/tuli/plugins/RSS.hx b/src/uhx/tuli/plugins/RSS.hx index 1b847f4..20ea606 100644 --- a/src/uhx/tuli/plugins/RSS.hx +++ b/src/uhx/tuli/plugins/RSS.hx @@ -70,43 +70,49 @@ class RSS { } - domEntry = entry.parse(); + var title = dom.find('h1').first().text(); - domEntry.find('guid').setText( id ); - domEntry.find('link').setText( id ); - domEntry.find('title').setText( dom.find('h1').first().text() ); - domEntry.find('description').setText( dom.find('p').first().text() ); - domEntry.find('pubDate').setText( DateTools.format( file.stats.ctime, '%a, %d %b %Y %H:%M:%S GMT' ) ); - - domFeed.find('pubDate').setText( DateTools.format( file.stats.ctime, '%a, %d %b %Y %H:%M:%S GMT' ) ); - domFeed.find('lastBuildDate').setText( DateTools.format( file.stats.mtime, '%a, %d %b %Y %H:%M:%S GMT' ) ); - domFeed.find('ttl').next().setAttr('href', 'http://haxe.io/$path'); - - domFeed.find('channel').append( null, domEntry ); - - xmlCache.set( path, domFeed ); - - if (!xmlCache.exists( html + 'index.html' )) { - xmlCache.set( html + 'index.html', dom ); - } - - var result = domFeed.html(); - var lowered = ['pubdate>' => 'pubDate>', 'lastbuilddate>' => 'lastBuildDate>']; - - for (key in lowered.keys()) { - result = result.replace(key, lowered.get( key )); - } - - while (result.indexOf('&') > -1) { - result = result.replace('&', '&'); - } - - for (key in Markdown.characters.keys()) { - result = result.replace(Markdown.characters.get( key ), key ); + if (title != '') { + + domEntry = entry.parse(); + + domEntry.find('guid').setText( id ); + domEntry.find('link').setText( id ); + domEntry.find('title').setText( title ); + domEntry.find('description').setText( dom.find('p').first().text() ); + domEntry.find('pubDate').setText( DateTools.format( file.stats.ctime, '%a, %d %b %Y %H:%M:%S GMT' ) ); + + domFeed.find('pubDate').setText( DateTools.format( file.stats.ctime, '%a, %d %b %Y %H:%M:%S GMT' ) ); + domFeed.find('lastBuildDate').setText( DateTools.format( file.stats.mtime, '%a, %d %b %Y %H:%M:%S GMT' ) ); + domFeed.find('ttl').next().setAttr('href', 'http://haxe.io/$path'); + + domFeed.find('channel').append( null, domEntry ); + + xmlCache.set( path, domFeed ); + + if (!xmlCache.exists( html + 'index.html' )) { + xmlCache.set( html + 'index.html', dom ); + } + + var result = domFeed.html(); + var lowered = ['pubdate>' => 'pubDate>', 'lastbuilddate>' => 'lastBuildDate>']; + + for (key in lowered.keys()) { + result = result.replace(key, lowered.get( key )); + } + + while (result.indexOf('&') > -1) { + result = result.replace('&', '&'); + } + + for (key in Markdown.characters.keys()) { + result = result.replace(Markdown.characters.get( key ), key ); + } + + Tuli.fileCache.set( path, result ); + } - Tuli.fileCache.set( path, result ); - dom = null; domFeed = null; domEntry = null;