Rendering HAML partials from within HAML outside of Rails

前端 未结 5 610
后悔当初
后悔当初 2020-12-31 16:54

I\'m using HAML to generate some static html pages for a site, and I was wanting to split out common components into partials that I can include in multiple pages, just like

5条回答
  •  灰色年华
    2020-12-31 17:36

    Darn, you're right – there isn't a built-in way. I've used helpers with the haml command line, but always ones whose output was already HTML formatted.

    My best suggestion is to write a partial() method and require it. It looks like you have already started down this path. I would suggest anyone writing such a function consider keeping the original binding around in some way. Haml::Helpers#capture_hame looks to be the easiest way to make this happen.

    If execution speed is an issue, it might also be a good idea to cache some of the parsed template in the same way that Merb does it.

    If someone does get some code working, please put it up on GitHub and make a comment here.

提交回复
热议问题