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

Conversation

miguelerm
Copy link
Contributor

Add support to recompose the Filters and Tags dependencies in the
LiquidEngine.

Use Example

  • Create a new Class Library Project called CustomTags
  • Add a reference to the assembly Pretzel.exe.
  • Add the classes listed above.
  • Compile and put the assembly inside the _plugins folder of the pretzel site.

When you run the pretzel.exe command, this check if the _plugins folder exists and load through MEF the assemblies inside that path and recompose the dependencies.

in your post you can put this filter {{ 'hola mundo' | md5 }} that should be rendered as:

0ad066a5d29f3f2a2a1c7c17dd082a79

and this block

{% dummy %}

Texto que debe aparecer en rojo :)

{% enddummy %}

should be rendered as:

<div style="background-color:red">
<p>Texto que debe aparecer en rojo :)</p>
</div>

Md5 Liquid Filter Demo

[Export(typeof(IFilter))]
public class Md5Filter: IFilter
{
    public string Name
    {
        get { return "Md5"; }
    }

    public static string Md5(string input)
    {
        Console.WriteLine("Computing md5 hash...");

        // md5 hash algorithm taked from http://stackoverflow.com/a/13806183

        MD5 md5Hash = MD5.Create();
        // Convert the input string to a byte array and compute the hash.
        byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

        // Create a new Stringbuilder to collect the bytes
        // and create a string.
        StringBuilder sBuilder = new StringBuilder();

        // Loop through each byte of the hashed data 
        // and format each one as a hexadecimal string.
        for (int i = 0; i < data.Length; i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }

        Console.WriteLine("md5 hash computed.");

        // Return the hexadecimal string.
        return sBuilder.ToString();
    }

}

Dummy Liquid Block Demo

[Export(typeof(Tag))]
public class Dummy : Block
{
    public override void Render(Context context, System.IO.TextWriter result)
    {
        result.Write("<div style=\"background-color:red\">");
        base.Render(context, result);
        result.Write("</div>");

    }
}

I hope it can be useful.

Add support to recompose the Filters and Tags dependencies in the
LiquidEngine.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants