Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyzwezdin committed Jul 2, 2016
0 parents commit 114fab0
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 0 deletions.
194 changes: 194 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions Pretzel.Picture.sln
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions Pretzel.Picture/PictureBlock.cs
Original file line number Diff line number Diff line change
@@ -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(@"<cite>([\W+\w+]*)</cite>", 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<string> tokens)
{
base.Initialize(tagName, markup, tokens);

Params = Regex.Matches(markup, @"[\""].+?[\""]|[^ ]+")
.OfType<Match>()
.Select(_ => (_.Value ?? String.Empty).Trim(' ', '"'))
.ToArray();
}

public override void Render(Context context, TextWriter result)
{
if (Params.Any())
{
var caption = GetRenderedContent(context);

result.WriteLine("<figure class=\"image\">");

var classes = Params.Skip(1).SelectMany(p => ImageClassesRegex.Matches(p).OfType<Match>().Select(m=>m.Value)).ToArray();

result.WriteLine("<img itemprop=\"image\" src=\"{0}\" title=\"{1}\" alt=\"{1}\" {2}/>", 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("<figcaption>");
base.Render(context, result);
result.Write("</figcaption>");
result.Write("</figure>");
}
}

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());
}
}
}
}
64 changes: 64 additions & 0 deletions Pretzel.Picture/Pretzel.Picture.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{85393898-9171-4E6A-9C64-C68E2599E167}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Pretzel.Picture</RootNamespace>
<AssemblyName>Pretzel.Picture</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotLiquid">
<HintPath>..\..\..\pretzel\libs\DotLiquid.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PictureBlock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\pretzel\src\Pretzel.Logic\Pretzel.Logic.csproj">
<Project>{f2e6664d-75ac-4830-8a55-e572027df710}</Project>
<Name>Pretzel.Logic</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 114fab0

Please sign in to comment.