diff --git a/src/Pretzel.Logic/Templating/Jekyll/LiquidEngine.cs b/src/Pretzel.Logic/Templating/Jekyll/LiquidEngine.cs index c2a33e711..70edd3018 100644 --- a/src/Pretzel.Logic/Templating/Jekyll/LiquidEngine.cs +++ b/src/Pretzel.Logic/Templating/Jekyll/LiquidEngine.cs @@ -4,6 +4,7 @@ using Pretzel.Logic.Liquid; using Pretzel.Logic.Templating.Context; using Pretzel.Logic.Templating.Jekyll.Liquid; +using System.Collections.Generic; namespace Pretzel.Logic.Templating.Jekyll { @@ -13,6 +14,9 @@ public class LiquidEngine : JekyllEngineBase { SiteContextDrop contextDrop; + [ImportMany(AllowRecomposition = true)] + public IEnumerable Tags { get; set; } + public LiquidEngine() { DotLiquid.Liquid.UseRubyDateFormat = true; @@ -28,6 +32,16 @@ protected override void PreProcess() Template.RegisterFilter(filter.GetType()); } } + if (Tags != null) + { + var registerTagMethod = typeof(Template).GetMethod("RegisterTag", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); + + foreach (var tag in Tags) + { + var registerTagGenericMethod = registerTagMethod.MakeGenericMethod(new[] { tag.GetType() }); + registerTagGenericMethod.Invoke(null, new[] { tag.Name }); + } + } } Hash CreatePageData(PageContext pageContext) diff --git a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs index 43f6567fe..d20087113 100644 --- a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs +++ b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs @@ -18,8 +18,8 @@ public abstract class JekyllEngineBase : ISiteEngine #pragma warning disable 0649 [Import] public IFileSystem FileSystem { get; set; } #pragma warning restore 0649 - - [ImportMany] + + [ImportMany(AllowRecomposition = true)] public IEnumerable Filters { get; set; } public abstract void Initialize(); diff --git a/src/Pretzel/Program.cs b/src/Pretzel/Program.cs index 8318bfe2b..879ffd574 100644 --- a/src/Pretzel/Program.cs +++ b/src/Pretzel/Program.cs @@ -8,6 +8,7 @@ using NDesk.Options; using Pretzel.Commands; using Pretzel.Logic.Extensions; +using Pretzel.Logic.Commands; namespace Pretzel { @@ -16,6 +17,10 @@ class Program [Import] private CommandCollection Commands { get; set; } + AggregateCatalog catalog; + + CompositionContainer container; + static void Main(string[] args) { Tracing.Logger.SetWriter(Console.Out); @@ -64,6 +69,7 @@ private void Run(string[] args, OptionSet defaultSet) return; } + LoadPlugins(commandArgs); Commands[commandName].Execute(commandArgs); WaitForClose(); } @@ -82,12 +88,26 @@ public void WaitForClose() } } + private void LoadPlugins(string[] commandArgs) + { + var parameters = container.GetExport().Value; + parameters.Parse(commandArgs); + + var pluginsPath = System.IO.Path.Combine(parameters.Path, "_plugins"); + + if (System.IO.Directory.Exists(pluginsPath)) + { + catalog.Catalogs.Add(new DirectoryCatalog(pluginsPath)); + } + } + public void Compose() { try { var first = new AssemblyCatalog(Assembly.GetExecutingAssembly()); - var container = new CompositionContainer(first); + catalog = new AggregateCatalog(first); + container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue(new FileSystem());