-
Notifications
You must be signed in to change notification settings - Fork 0
/
tatus
134 lines (134 loc) · 3.8 KB
/
tatus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[1mdiff --git a/src/Models/EndpointPage.cs b/src/Models/EndpointPage.cs[m
[1mindex e289f3c..1fdfb8b 100644[m
[1m--- a/src/Models/EndpointPage.cs[m
[1m+++ b/src/Models/EndpointPage.cs[m
[36m@@ -1,5 +1,8 @@[m
[31m-using Alloy.Liquid.Liquid.Models.Blocks;[m
[32m+[m[32musing DeaneBarker.Optimizely.Endpoints.TreeQL;[m[41m[m
using EPiServer.Shell.ObjectEditing;[m
[32m+[m[32musing Fluid;[m[41m[m
[32m+[m[32musing Optimizely.CMS.Labs.LiquidTemplating.ViewEngine;[m[41m[m
[32m+[m[32musing System.ComponentModel.DataAnnotations;[m[41m[m
[m
namespace DeaneBarker.Optimizely.Endpoints.Models[m
{[m
[36m@@ -10,7 +13,7 @@[m [mnamespace DeaneBarker.Optimizely.Endpoints.Models[m
DisplayName = "Content Endpoint"[m
)[m
][m
[31m- public class EndpointPage : PageData[m
[32m+[m[32m public class EndpointPage : PageData, IEndpoint[m[41m[m
{[m
[ClientEditor(ClientEditingClass = "/js/editor.js")][m
public virtual string Query { get; set; }[m
[36m@@ -24,5 +27,55 @@[m [mnamespace DeaneBarker.Optimizely.Endpoints.Models[m
base.SetDefaultValues(contentType);[m
VisibleInMenu = false;[m
}[m
[32m+[m[41m[m
[32m+[m[32m public string QuerySource => Query;[m[41m[m
[32m+[m[32m public IQueryProcessor QueryProcessor => new TreeQlQueryProcessor();[m[41m[m
}[m
[32m+[m[41m[m
[32m+[m[32m [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)][m[41m[m
[32m+[m[32m public class ValidateLiquidParse : ValidationAttribute[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m public ValidateLiquidParse()[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m public override bool IsValid(object value)[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m return GetParseException(value.ToString()) == null;[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m protected override ValidationResult IsValid(object value, ValidationContext validationContext)[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m if (string.IsNullOrWhiteSpace(value?.ToString()))[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m return ValidationResult.Success;[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m var message = GetParseException(value?.ToString());[m[41m[m
[32m+[m[32m if (message != null)[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m return new ValidationResult($"Liquid parse error: {message}");[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m return ValidationResult.Success;[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m private string GetParseException(string liquidCode)[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m var parser = new CmsFluidViewParser(new FluidParserOptions() { AllowFunctions = true });[m[41m[m
[32m+[m[41m[m
[32m+[m[32m try[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m var template = parser.Parse(liquidCode);[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[32m catch (Exception e)[m[41m[m
[32m+[m[32m {[m[41m[m
[32m+[m[32m return e.Message;[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
[32m+[m[32m return null;[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[32m }[m[41m[m
[32m+[m[41m[m
}[m