/src/DotLiquid/Liquid.cs

https://github.com/debackerl/dotliquid · C# · 61 lines · 59 code · 2 blank · 0 comment · 0 complexity · f4f2dc303c3471973167b5a32c0ca118 MD5 · raw file

  1. using System.Reflection;
  2. using System.Resources;
  3. using DotLiquid.NamingConventions;
  4. using DotLiquid.Tags;
  5. using DotLiquid.Tags.Html;
  6. using DotLiquid.Util;
  7. namespace DotLiquid
  8. {
  9. internal static class Liquid
  10. {
  11. public static readonly ResourceManager ResourceManager = new ResourceManager(typeof(DotLiquid.Properties.Resources));
  12. public static readonly string FilterSeparator = R.Q(@"\|");
  13. public static readonly string ArgumentSeparator = R.Q(@",");
  14. public static readonly string FilterArgumentSeparator = R.Q(@":");
  15. public static readonly string VariableAttributeSeparator = R.Q(@".");
  16. public static readonly string TagStart = R.Q(@"\{\%");
  17. public static readonly string TagEnd = R.Q(@"\%\}");
  18. public static readonly string VariableSignature = R.Q(@"\(?[\w\-\.\[\]]\)?");
  19. public static readonly string VariableSegment = R.Q(@"[\w\-]");
  20. public static readonly string VariableStart = R.Q(@"\{\{");
  21. public static readonly string VariableEnd = R.Q(@"\}\}");
  22. public static readonly string VariableIncompleteEnd = R.Q(@"\}\}?");
  23. public static readonly string QuotedString = R.Q(@"""[^""]*""|'[^']*'");
  24. public static readonly string QuotedFragment = string.Format(R.Q(@"{0}|(?:[^\s,\|'""]|{0})+"), QuotedString);
  25. public static readonly string StrictQuotedFragment = R.Q(@"""[^""]+""|'[^']+'|[^\s\|\:\,]+");
  26. public static readonly string FirstFilterArgument = string.Format(R.Q(@"{0}(?:{1})"), FilterArgumentSeparator, StrictQuotedFragment);
  27. public static readonly string OtherFilterArgument = string.Format(R.Q(@"{0}(?:{1})"), ArgumentSeparator, StrictQuotedFragment);
  28. public static readonly string SpacelessFilter = string.Format(R.Q(@"^(?:'[^']+'|""[^""]+""|[^'""])*{0}(?:{1})(?:{2}(?:{3})*)?"), FilterSeparator, StrictQuotedFragment, FirstFilterArgument, OtherFilterArgument);
  29. public static readonly string Expression = string.Format(R.Q(@"(?:{0}(?:{1})*)"), QuotedFragment, SpacelessFilter);
  30. public static readonly string TagAttributes = string.Format(R.Q(@"(\w+)\s*\:\s*({0})"), QuotedFragment);
  31. public static readonly string AnyStartingTag = R.Q(@"\{\{|\{\%");
  32. public static readonly string PartialTemplateParser = string.Format(R.Q(@"{0}.*?{1}|{2}.*?{3}"), TagStart, TagEnd, VariableStart, VariableIncompleteEnd);
  33. public static readonly string TemplateParser = string.Format(R.Q(@"({0}|{1})"), PartialTemplateParser, AnyStartingTag);
  34. public static readonly string VariableParser = string.Format(R.Q(@"\[[^\]]+\]|{0}+\??"), VariableSegment);
  35. public static readonly string LiteralShorthand = R.Q(@"^(?:\{\{\{\s?)(.*?)(?:\s*\}\}\})$");
  36. public static readonly string CommentShorthand = R.Q(@"^(?:\{\s?\#\s?)(.*?)(?:\s*\#\s?\})$");
  37. static Liquid()
  38. {
  39. Template.RegisterTag<Tags.Assign>("assign");
  40. Template.RegisterTag<Tags.Block>("block");
  41. Template.RegisterTag<Tags.Capture>("capture");
  42. Template.RegisterTag<Tags.Case>("case");
  43. Template.RegisterTag<Tags.Comment>("comment");
  44. Template.RegisterTag<Tags.Cycle>("cycle");
  45. Template.RegisterTag<Tags.Extends>("extends");
  46. Template.RegisterTag<Tags.For>("for");
  47. Template.RegisterTag<Tags.If>("if");
  48. Template.RegisterTag<Tags.IfChanged>("ifchanged");
  49. Template.RegisterTag<Tags.Include>("include");
  50. Template.RegisterTag<Tags.Literal>("literal");
  51. Template.RegisterTag<Tags.Unless>("unless");
  52. Template.RegisterTag<Tags.Html.TableRow>("tablerow");
  53. Template.RegisterFilter(typeof(StandardFilters));
  54. }
  55. }
  56. }