Proposal: abstraction layer for template loading #115

Closed
hannesg opened this Issue Nov 13, 2011 · 7 comments

Comments

Projects
None yet
4 participants
@hannesg
Contributor

hannesg commented Nov 13, 2011

Hi,

Currently templates are loaded either from source or from a fully specified file-path, which is okay but a bit inflexible.

Furthermore, some template engines support template loading inside templates ( liquid, tenjin, ... ) and most engines could easily adopt this ( erubis, ... ) . However, this feature is inconsistently implemented in the engines ( file paths? extensions? inherited methods and variables? ... ) and always relies on the file system as template source.

It would be cool, if we would have a unified template factory for all engines, which when given a template name could determine if a template exists and fetch it's source. This would allow us to load templates from a database or a hash or something else. Secondly this would allow us to query multiple paths for a file to load, which would make it easy to build a rails-style templating system, where every controller has it's own template folder but also uses system-wide templates. Furthermore this would boost template inheritance and reuse a lot since the loading could be controlled more fine grained.

To accomplish this we will have to patch the engines a bit. I have already written prototypes for liquid and tenjin and they both work great. I would be willing to write the remaining code during the next month.

What do you think about it?

@lukeholder

This comment has been minimized.

Show comment Hide comment
@lukeholder

lukeholder Dec 15, 2011

I am trying to use tilt by passing it a template string/text directly, but not having much success. Would this make my life easier?

I am trying to use tilt by passing it a template string/text directly, but not having much success. Would this make my life easier?

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Dec 15, 2011

lukeholder, Tilt::SomeEngine.new { 'some template/text' }

hannesg, regard your proposal, what do you think about this
#118

it will allow to store templates as strings in databases, hashes, files etc then easily load them.
also it offers a performance boost, as no need to compile template on each load.

ghost commented Dec 15, 2011

lukeholder, Tilt::SomeEngine.new { 'some template/text' }

hannesg, regard your proposal, what do you think about this
#118

it will allow to store templates as strings in databases, hashes, files etc then easily load them.
also it offers a performance boost, as no need to compile template on each load.

@lukeholder

This comment has been minimized.

Show comment Hide comment
@lukeholder

lukeholder Dec 15, 2011

yep! realized I can pass it a block.

yep! realized I can pass it a block.

@hannesg

This comment has been minimized.

Show comment Hide comment
@hannesg

hannesg Dec 15, 2011

Contributor

@slivu thanks for the idea. I'm currently working on extending temple. I will expand the idea later.

Contributor

hannesg commented Dec 15, 2011

@slivu thanks for the idea. I'm currently working on extending temple. I will expand the idea later.

@ep-wac

This comment has been minimized.

Show comment Hide comment
@ep-wac

ep-wac May 1, 2012

@hannesg and @slivu

I'm on RR 1.9.2/3.2.2 and using
append_view_path ViewTemplate::Resolver.instance
in my controllers, and it lets me store templates in a table (view_templates) - and render them, of cause ;)

With the number of possible templating engines to implement, I found Tilt - and I am wondering whether you have been able to advance the pull/118 anywhere?

cheers,
e

ep-wac commented May 1, 2012

@hannesg and @slivu

I'm on RR 1.9.2/3.2.2 and using
append_view_path ViewTemplate::Resolver.instance
in my controllers, and it lets me store templates in a table (view_templates) - and render them, of cause ;)

With the number of possible templating engines to implement, I found Tilt - and I am wondering whether you have been able to advance the pull/118 anywhere?

cheers,
e

This comment has been minimized.

Show comment Hide comment
@ghost

ghost May 1, 2012

@ep-wac, it is not pushed yet, not sure when it will be,
Presto Framework using this update on multiple sites without a issue.

ghost commented May 1, 2012

@ep-wac, it is not pushed yet, not sure when it will be,
Presto Framework using this update on multiple sites without a issue.

@judofyr

This comment has been minimized.

Show comment Hide comment
@judofyr

judofyr May 1, 2013

Collaborator

Closing this. As mentioned, Tilt already supports a block for abstracting away the file reading.

Collaborator

judofyr commented May 1, 2013

Closing this. As mentioned, Tilt already supports a block for abstracting away the file reading.

@judofyr judofyr closed this May 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment