diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0934c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,194 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studo 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.[Cc]ache +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt \ No newline at end of file diff --git a/Pretzel.Picture.sln b/Pretzel.Picture.sln new file mode 100644 index 0000000..8f02adb --- /dev/null +++ b/Pretzel.Picture.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pretzel.Picture", "Pretzel.Picture\Pretzel.Picture.csproj", "{85393898-9171-4E6A-9C64-C68E2599E167}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pretzel.Logic", "..\..\pretzel\src\Pretzel.Logic\Pretzel.Logic.csproj", "{F2E6664D-75AC-4830-8A55-E572027DF710}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85393898-9171-4E6A-9C64-C68E2599E167}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85393898-9171-4E6A-9C64-C68E2599E167}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85393898-9171-4E6A-9C64-C68E2599E167}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85393898-9171-4E6A-9C64-C68E2599E167}.Release|Any CPU.Build.0 = Release|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Pretzel.Picture/PictureBlock.cs b/Pretzel.Picture/PictureBlock.cs new file mode 100644 index 0000000..4226f17 --- /dev/null +++ b/Pretzel.Picture/PictureBlock.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using Pretzel.Logic.Extensibility; +using DotLiquid; + + +namespace Pretzel.Picture +{ + [Export(typeof(ITag))] + public class PictureBlock : Block, ITag + { + private static readonly Regex CiteRegex = new Regex(@"([\W+\w+]*)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline); + private static readonly Regex HtmlTagRegex = new Regex(@"", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline); + private static readonly Regex ImageClassesRegex = new Regex(@"[\w\-]+", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline); + + protected string Src; + + protected string[] Params; + + public new string Name => "Picture"; + + public override void Initialize(string tagName, string markup, List tokens) + { + base.Initialize(tagName, markup, tokens); + + Params = Regex.Matches(markup, @"[\""].+?[\""]|[^ ]+") + .OfType() + .Select(_ => (_.Value ?? String.Empty).Trim(' ', '"')) + .ToArray(); + } + + public override void Render(Context context, TextWriter result) + { + if (Params.Any()) + { + var caption = GetRenderedContent(context); + + result.WriteLine("
"); + + var classes = Params.Skip(1).SelectMany(p => ImageClassesRegex.Matches(p).OfType().Select(m=>m.Value)).ToArray(); + + result.WriteLine("\"{1}\"", Uri.EscapeUriString(Params[0]), + HtmlTagRegex.Replace(CiteRegex.Replace(caption, String.Empty), String.Empty) + .Replace("\r", String.Empty).Replace("\n", String.Empty).Replace("\t", String.Empty), + classes.Any() ? $"class=\"{String.Join(" ", classes)}\"" : String.Empty); + + result.Write("
"); + base.Render(context, result); + result.Write("
"); + result.Write("
"); + } + } + + protected string GetRenderedContent(Context context) + { + using (var stream = new MemoryStream()) + { + using (var writer = new StreamWriter(stream)) + { + base.Render(context, writer); + } + + return Encoding.UTF8.GetString(stream.ToArray()); + } + } + } +} \ No newline at end of file diff --git a/Pretzel.Picture/Pretzel.Picture.csproj b/Pretzel.Picture/Pretzel.Picture.csproj new file mode 100644 index 0000000..ad7c2e2 --- /dev/null +++ b/Pretzel.Picture/Pretzel.Picture.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {85393898-9171-4E6A-9C64-C68E2599E167} + Library + Properties + Pretzel.Picture + Pretzel.Picture + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\pretzel\libs\DotLiquid.dll + + + + + + + + + + + + + + + + + + {f2e6664d-75ac-4830-8a55-e572027df710} + Pretzel.Logic + + + + + \ No newline at end of file diff --git a/Pretzel.Picture/Properties/AssemblyInfo.cs b/Pretzel.Picture/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1e15811 --- /dev/null +++ b/Pretzel.Picture/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Pretzel.Picture")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Pretzel.Picture")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("85393898-9171-4e6a-9c64-c68e2599e167")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..3a2e94f --- /dev/null +++ b/readme.md @@ -0,0 +1,36 @@ +# Pretzel.Picture + +Allows you to wrap you `` tags with `
` and add `
`. + +This is a plugin for the static site generation tool [Pretzel](https://github.com/Code52/pretzel). + +### Usage + +To add properly formatted `` tag to the page: + +```html +{% picture "/assets/images/darkside.jpg" %} +Image of dark side +— Photo by +{% endpicture %} +``` + +You can also customize it by adding some CSS-classes: + +```html +{% picture "/assets/images/darkside.jpg" "bordered" %} +Image of dark side +— Photo by +{% endpicture %} +``` + +You can skip any descriptions for image. In this case `
` won't be added. + +```html +{% picture "/assets/images/darkside.jpg" %} +{% endpicture %} +``` + +### Installation + +Download the [latest release](https://github.com/sergeyzwezdin/Pretzel.Picture/releases/latest) and copy `Pretzel.Picture.dll` to the `_plugins` folder at the root of your site folder. \ No newline at end of file