Middleman not parsing source file up template chain if missing ERb tags

我的梦境 提交于 2019-12-12 00:11:44

问题


I'm converting a Jekyll site to Middleman. I have named my files like filename.html.md.liquid.erb for processing with those libraries in that order: ERb, then liquid, then kramdown. What I found is that if I don't have at least one erb tag in the file, the template parsing simply stops and the whole file is rendered as plain text rather than being parsed by liquid and then kramdown. Simply adding

<% if nil %>
<% end %>

at the bottom of the source document causes the whole template chain to be rendered, but I don't want to be forced to include these. I simply want to have the option.

Edit: I just discovered this also applies if any of the templates specified via the extensions don't actually have any processing to do. So, for instance, if I have filename.html.md.liquid.erb and I have ERb tags but no liquid tags, the ERb will render fine, but Markdown will be output as static text.

I've tagged this as tilt and middleman both just because I'm not sure where the problem might lie.

Any pointers would be greatly appreciated.


回答1:


It looks like the reason for this is related to caching. When I remove the cache call, the templates render all the way up the chain. I also changed the cache key to use the template extension and that seems to work as well. By changing rendering.rb:257 to

template = cache.fetch("compiled_template_#{extension}".to_sym, options, body) do
    ::Tilt.new(path, 1, options) { body }
end

the template chain parses up the rest of the extensions even if the previous template's processing did not contain any of that templating languages tags. I opened an issue in Middleman as there may be a better way to solve it than this.



来源:https://stackoverflow.com/questions/14991807/middleman-not-parsing-source-file-up-template-chain-if-missing-erb-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!