开发者

Providing fake data to liquid to render a preview of a template

I have created the ability for users in my system to edit a liquid template that is eventually rendered and turned into a PDF. I would like some id开发者_如何学Goeas as to what the best method would be to create some mock objects to feed the template so as to create a preview for them to see what the final result of their template modifications will be.

The collection of objects passed to the template when it is rendered in real life is fairly complex so I'm thinking at this stage that I can either try and build a temporary model with dependencies in memory, or create some structs that pretend to be the models in question and pass those to the template instead.

Another way could be to instantiate all of this from a yaml file.

Any ideas welcome :)


If you trying to create objects, why dont you use a factory? Are the objects part of the database? You could always use seeds.rb to seed the database with some demo data.


I ended up using a YAML file to build up the structure I needed. It seems that liquid will take a hash of values (and other hashes) instead of the actual models with relationships no problem, so I didn't even need to instantiate the models.

Will happily post an example if anyone is interested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜