DKP Log Parser Forum Index
 Forum FAQ   Search   Register   Log in 
 About   Download   Forum   Wiki   Development
Exporter fun: templates?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DKP Log Parser Forum Index -> General

Author

Message

impishfae



Joined: 19 Jun 2006
Posts: 125
Location: Australia

PostPosted: Wed Jul 05, 2006 2:18 pm    Post subject: Exporter fun: templates?

Reply with quote


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)

Back to top

Lokorin
Site Admin


Joined: 03 Apr 2006
Posts: 697

PostPosted: Wed Jul 05, 2006 2:50 pm    Post subject:

Reply with quote


Sounds like a great idea, I'm sure that the current export formats that are meant for humans would be far better as templats, letting the user have full control. The XML exporter would probably have to stay in the code though as the importer depends on the outputted format (unless the export template can be inverted in some semi-magical way).

The hard part of this is probably finding an engine that is just enough for formatting the data, but isn't overly complex to learn, but that list seems like a good start. I'm sure that some people will take the time to write their own templates, so I wouldn't worry about that.

Back to top

Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DKP Log Parser Forum Index -> General All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
SoftGreen 1.1 phpBB theme © DaTutorials.com 2005