Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Add support to load dlls in "_plugins" path #157

Merged
merged 1 commit into from
Feb 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Pretzel.Logic/Templating/Jekyll/LiquidEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -13,6 +14,9 @@ public class LiquidEngine : JekyllEngineBase
{
SiteContextDrop contextDrop;

[ImportMany(AllowRecomposition = true)]
public IEnumerable<DotLiquid.Tag> Tags { get; set; }

public LiquidEngine()
{
DotLiquid.Liquid.UseRubyDateFormat = true;
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Pretzel.Logic/Templating/JekyllEngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFilter> Filters { get; set; }

public abstract void Initialize();
Expand Down
22 changes: 21 additions & 1 deletion src/Pretzel/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NDesk.Options;
using Pretzel.Commands;
using Pretzel.Logic.Extensions;
using Pretzel.Logic.Commands;

namespace Pretzel
{
Expand All @@ -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);
Expand Down Expand Up @@ -64,6 +69,7 @@ private void Run(string[] args, OptionSet defaultSet)
return;
}

LoadPlugins(commandArgs);
Commands[commandName].Execute(commandArgs);
WaitForClose();
}
Expand All @@ -82,12 +88,26 @@ public void WaitForClose()
}
}

private void LoadPlugins(string[] commandArgs)
{
var parameters = container.GetExport<CommandParameters>().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<IFileSystem>(new FileSystem());
Expand Down