Did you guys view that screencast I sent you (http://railscasts.com/episodes/153-pdfs-with-prawn) and if so what did you think/what can we apply to recess?
Jamie
Jamie Rumbelow Designer / Developer / Writer / Speaker
http://www.jamierumbelow.net | +44 (0)7956 363875 | jamie (at) jamierumbelow (dot) net
Kris,
Yeah, using three extensions does seem excessive, but I reckon it wouldn’t be a problem, or even necessary. I don’t think that the provider should be chosen solely on the extension – I think it’d be a better idea for a provider to accept different mime-types and parse it through that.
For instance, if we had a provider called TemplateProviderPhp (which would map to *.php, as TemplateProviderPrawn would map to *.prawn), the code could look something like so:
class TemplateProviderPhp extends TemplateProvider implements ITemplateProvider {
public function __construct() {
$this->registerHandler(‘html’, ‘text/html’);
$this->registerHandler(‘pdf’, ‘application/pdf’);
}
public function html($file) {
//Buffer...
Ob_start();
//Load and evaluate the file
include($file);
//Catch the output
$output = ob_get_contents();
Ob_clear_end();
//Pass back to recess
$this->render($output);
}
Public function pdf($file) {
//Create new PDFRender object
$pdf = new PDFRender();
//Buffer...
Ob_start();
//Load and evaluate the file
include($file);
//Catch the output
$output = ob_get_contents();
Ob_clear_end();
//Pass back to recess
$this->render($output);
}
}
This is just a simple example code, but as you can see, each template handler (noted by the second extension, in this example .php) can hold multiple mime-types, which it can then output in different ways (in this example, both .html and .pdf are recognized, so you could load .html.php and .pdf.php into the provider).
The method would be in the same scope as the view, so you could include variables, such as a $pdf object, shown in the above example. It is then the provider’s job to register the extension with a specific mime-type, as we did above. When Recess is looking for the right provider to use, it looks through TemplateProvider’s array of all registered formats and chooses based on that.
Jamie Rumbelow Designer / Developer / Writer / Speaker
http://www.jamierumbelow.net | +44 (0)7956 363875 | jamie (at) jamierumbelow (dot) net