-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API method for "registered extensions" #228
Comments
Public methods for already-available-template-classes and attempt-to-load-everything-that's-lazy-loadable will come it Tilt 2.1. |
@nyarly do you still need this? |
The use case is https://github.com/nyarly/valise/blob/master/lib/valise/adapters/tilt.rb#L81 I'm more than happy to make use of whatever interface is available to provide the functionality - it sounds like "load everything" followed by "iterate available template classes, mapping to their extensions" would do the job. The existing solution I knew was digging into Tilt's guts, which was what motivated the original question. |
What's a sensible API? I was thinking:
Not sure about the name of the last one. |
I'd be fine with that. By analogy to Rails, maybe |
I'd accept a pull request for this feature. Otherwise I'll queue it up for later OSS work. |
The API that is currently used for this is
The problem with this approach is that for mappings that are loaded lazily, this returns duplicate values. Take the AsciiDoc extensions for example:
I think the extensions_for method should return a uniq result. I plan to file a PR with this change. See #324. |
Would love to see this API added in a 2.1 release as it would be really useful for Sinatra. See sinatra/sinatra#1172. |
After further investigation, I think what is needed is a method that returns a Tilt class name (String) for a particular template engine without loading the file. It looks like we can do that with something like this:
|
What's the input and output here? What are you trying to solve? I can imagine multiple different APIs:
|
Input would be an engine, and output the string name of a template class. Similar to
|
Considering you can already get this via Tilt's public API (#228 (comment)), I think we should close this. However, be aware that just because there is an entry in |
Note that the Lines 16 to 19 in 686cafa
lazy_map directly.
However, I'm kinda struggling to see the use case here. This will always return the first entry in the lazy map and you have no idea if that is the actual template class which is going to be used. I'd understand if it returned all possible template classes it would attempt to load, but returning the first one doesn't seem useful. |
A tool I've been writing uses Tilt to manage it template handling, but needs to route method calls to it based on file extension. I was using the keys of Tilt::mappings before 2.0, and am looking at Tilt::default_mappings.template_map/lazy_map now.
What I'm hoping for is a stable API for accessing the registered template mappings. I only need the extensions that Tilt expects, but I imagine it might also be useful to know what template types Tilt can handle as well.
The text was updated successfully, but these errors were encountered: