-
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
Accessing all registered file extensions #331
Comments
There is currently no API for this. I could provide one, but I'd like to know the use case first. For instance:
In general I'd recommend to not depend on registered template classes since it can change in point releases and cause problems for end users. Instead you could:
All of these approaches are less "magic" and thus less fragile. You can also implementing the glob filtering in Ruby: Fetch all files and then check if it's possible to render it: fiiles = Dir["*"].select { |x| Tilt[x] } |
Either would be fine for my cms - only supported or all potential
extensions.
I don't mind breaking with Tilt point releases; Hardwired is really just a
Tilt wrapper with dynamic file contents indexing.
…On Fri, Aug 17, 2018, 7:07 AM Magnus Holm ***@***.***> wrote:
There is currently no API for this. I could provide one, but I'd like to
know the use case first. For instance:
- Do you want all file extensions that we *know* can be rendered?
(e.g: only explicitly loaded template classes are counted)
- Do you want all file extensions that there are template classes
(possibly lazy loaded) for?
In general I'd recommend to *not* depend on registered template classes
since it can change in point releases and cause problems for end users.
Instead you could:
- Add an extension blacklist, and otherwise pass all files to Tilt
- Require that files that are processed by Tilt are in a specific
directory
- Require that files that are processed by Tilt have a common
prefix/postfix
All of these approaches are less "magic" and thus less fragile.
You can also implementing the glob filtering in Ruby: Fetch *all* files
and then check if it's possible to render it:
fiiles = Dir["*"].select { |x| Tilt[x] }
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#331 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGlnwn8rwHCINLFO9ObkDmbrfig6bjfks5uRr_0gaJpZM4WBF17>
.
|
I don't think we should add this as a specific method. Using Using both is already possible via the public API: Tilt.default_mapping.template_map.keys
# => []
Tilt.default_mapping.lazy_map.keys[0..10].join(',')
# => "erb,rhtml,erubis,erubi,markdown,mkd,md,ad,adoc,asciidoc,es6" If you wanted to be accurate and didn't care about memory, you could do: Tilt.default_mapping.lazy_map.keys.map{|k| begin Tilt[k]; rescue LoadError; else; k end}.compact.join(',')
=> "erb,rhtml,erubi,markdown,mkd,md,ad,adoc,asciidoc,builder,rcsv,etn,etanni,haml,nokogiri,html,rdoc,sass,scss,sigil,str" |
In 1.x, I could glob for all tilt-registered file extensions like this:
"*.{#{Tilt.mappings.keys.join(',')}}"
Is there any way in 2.X to enumerate the file extensions supported by Tilt at runtime?
The text was updated successfully, but these errors were encountered: