How to remove mapping
naokazuterada opened this issue · comments
Hi, I'm using tilt within middleman.
In my situation, I don't want '.rst' files in my source to path renderer, and want to remove 'rst' from mappings.
I found the good tips here like...
Tilt.mappings.delete('rst')
But this couldn't work, maybe because it's for the older version of tilt.
I'm using tilt v2.0.8.
I looked into source code, but couldn't find the way to remove the specific mapping from outside.
Any idea?
Thank you.
The default mapping-object Tilt.default_mapping
will change between point releases and it's mainly there for convenience and as a sensible default. If you need more control you should create a custom mappings object yourself (it's always better to whitelist than to blacklist):
mapping = Tilt::Mapping.new
mapping.register(Tilt::ERBTemplate, 'erb')
It's a bit unfortunate if Middleman doesn't support a custom Mapping
-object. I guess a temporary hack would be to override the Tilt.default_mapping
method to return your custom object:
Tilt.define_singleton_method(:default_mapping) { mapping }
Thank you for quick response!
I found it works fine, but unfortunately it doesn't in the middleman env. Maybe the hook timing is the problem, I think. I will ask in the middleman's forum. Thank you anyway! I'm appreciate it.
While it probably is better to use a custom mapping. It appears to be possible to modify the default mapping using the existing public API: Tilt.default_mapping.lazy_map.delete('rst')
A Mapping#unregister(*extensions)
method which both clears from lazy_map
and from template_map
does seem like a sensible addition to the API.
I submitted #376 to implement Mapping#unregister(*extensions)