mrpmorris / Morris.Moxy

Moxy - Mixins code generator for C#
MIT License
111 stars 6 forks source link

Support for include #49

Open kevinferrare opened 3 weeks ago

kevinferrare commented 3 weeks ago

I saw that moxy is based on scriban (https://github.com/scriban/scriban)

I tried to use the include function to be able to factorize stuff between my templates. Unfortunately this isnt working:

2>Grp1.mixin(8,4): Error MOXY0003 : /home/kevin/dev/Spice86/src/Spice86.Core/Emulator/CPU/CfgCpu/ParsedInstruction/Instructions/Mixins/Grp1.mixin(1,4) : error : Unable to include <Test.mixin>. No TemplateLoader registered in TemplateContext.TemplateLoader
mrpmorris commented 3 weeks ago

I'm not sure how it would be achieved unless there is a hook I can use for resolving.

kevinferrare commented 3 weeks ago

Maybe that's not what you meant but it looks like you need to hook an TemplateLoader that provides the include text https://github.com/scriban/scriban/blob/38df14946721238d2f4badc7c0b6e8a1c594e23c/doc/runtime.md#include-and-itemplateloader

I can see from my limited understanding of your code that you create a TemplateContext here https://github.com/mrpmorris/Morris.Moxy/blob/c75846112f83b2d8b5335fb25d9163d9153984ba/Source/Lib/Morris.Moxy/SourceGenerators/ClassSourceGenerator.cs#L125

Maybe a custom loader that would try to find the include file from the current directory of the compiledTemplate object would work for most cases?