I threw together a quick html exporter this evening, since that happens to be what our forums need to eat.
While poddling about in the code there, it occurred to me that an alternative to the current data driven output formatting (where the output is controlled explicitly by the code, based on the data), it might be groovy to go to a template based system.
The system could provide a set of templates (text, xml, wiki, html, bbcode) but the user would be free to write their own too in case they didn't like the defaults and were feeling game.
Template is just a text file, that recognises certain tags and populates it with data out of the software.
So a (completely fictitious) text template (extract) might be something like:
| Code: |
*** RAID INFO ***
Provided by DKPLP Log Parser at http://www.lokorin.com/dkplp/
Duration: [$raid.duration]
Modifier: [$raid.modifier]
[!IF $export.complete_participation]
- Complete Participation -
[!FOREACH $raid.intervals as interval]
Time Interval: [$interval.start] - [$interval.finish]
Reward DKP: [$interval.dkp]
Participants: [$interval.participants]
[!ENDFOREACH]
[!ENDIF]
|
while an html template for the same stuff might be like:
| Code: |
<html>
<head>
<!-- include reference to custom groovy stylesheet here -->
</head>
<body>
<h1>RAID INFO: [$raid.zone]</h1>
Provided by DKPLP Log Parser at http://www.lokorin.com/dkplp/<br>
<b>Duration<b>: [$raid.duration]<br>
<b>Modifier<b>: [$raid.modifier]<br>
[!IF $export.complete_participation]
<h2>Complete Participation</h2>
<h3>Intervals</h3>
<table>
<tr><td>Time Interval</td><td>Reward DKP</td><td>Participants</td></tr>
[!FOREACH $raid.intervals as interval]
<tr>
<td>[$interval.start] - [$interval.finish]</td>
<td>Reward DKP: [$interval.dkp]</td>
<td>Participants: [$interval.participants]</td>
</tr>
[!ENDFOREACH]
</table>
[!ENDIF]
|
But there's nothing to stop someone editing the template to put the complete participation at the end and the intervals up the top. Or... whatever.
I've used some nice templaters in my perl hacking days. I know Java has some floating around (list of open source templating engines ) though I don't know if they're too heavy/slow to consider. Or if people care enough about customising their output that they'd consider learning a templating language to achieve their goals.
Codewise, it simplifies all those formatters: chuck 'em all away and replace with one generic template processor (already provided by the third party library) and change the menu export option to perform some sort of dynamic template lookup to find out what template files are currently available and let the user select which one they want to use...
(Putting in Dev-General rather than Dev-Suggestions, since this doesn't provide a whole lot in the way of a feature set, I suspect, but is potentially more extensible and requires less hand-written code) |