Code52 / pretzel

A site generation tool (and then some) for .NET platforms
http://code52.org/pretzel/
Microsoft Public License
596 stars 163 forks source link

Render a page with a layout in a Pretzel plugin. #270

Closed k94ll13nn3 closed 8 years ago

k94ll13nn3 commented 9 years ago

I am currently trying to create a category generator plugin for Pretzel and I am facing some problems. I understood that in order to generate files, I had to create a class that inherits ITransform. I am able to recover all the categories in my site with siteContext.Categories and create empty files according to each category.

Next to that I have a category_index.html file in the _layouts folder that will be the layout for all my category pages. Thanks to that layout, i can manually create a category page by having a file with only the following content :


---
layout: category_index
category: some_category

---

The problem is that I want my plugin to generate and render those files and I don't know how to do it. I tried to use some functions from DotLiquid.Template and I took a look at JekyllEngineBase.cs in order to understand the process but none of my attempts worked.

Is there a way to render a page with a layout in a Pretzel plugin ?

laedit commented 9 years ago

Thanks a lot for your interest in pretzel, I see that you already have a nice collection of Pretzel plugins! :smiley:

Sadly the ITransform is out of the generation process and have neither Liquid or Razor engines. I haven't got the time to test but I think you have 2 short term solutions:

  var template = Template.Parse(templateContents);
  var output = template.Render(data);

where templateContents is the content of your category page and data a Hash with your data (here layout and category).

But it could be interesting to have access to the current ISiteEngine in the ITransform, by example by passing it in the Transform method. If you are interested by making a PR we can discuss how to do it and what methods of ISiteEngine should be made public.

laedit commented 9 years ago

Another solution could be to add some extensibility points to SiteContextGenerator, before and after the posts/pages/tags/categories generation. This would allow to add some pages/posts to the site context.

k94ll13nn3 commented 9 years ago

I have not been able to make the Template solution worked on a global level (I have something working but only for my setup).

I will try to take a look at the ISiteEngine solution when I manage to have some free time.

laedit commented 8 years ago

Fixed by #288