Skip to content

Commit 1a571d4

Browse files
authored
Merge pull request #163 from IoTSharp/HandlebarsNet_2_1_6
upgrade Handlebars.Net to 2.1.6
2 parents d5d6315 + 5b77c2d commit 1a571d4

File tree

9 files changed

+56
-94
lines changed

9 files changed

+56
-94
lines changed

sample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public void ConfigureServices(IServiceCollection services)
4242
authenticationOptions.AuthScheme = CookieAuthenticationDefaults.AuthenticationScheme;
4343
authenticationOptions.SilkierQuartzClaim = "Silkier";
4444
authenticationOptions.SilkierQuartzClaimValue = "Quartz";
45-
authenticationOptions.UserName = "admin";
46-
authenticationOptions.UserPassword = "password";
45+
4746
authenticationOptions.AccessRequirement = SilkierQuartzAuthenticationOptions.SimpleAccessRequirement.AllowOnlyUsersWithClaim;
4847
}
4948
#else

src/SilkierQuartz/Helpers/HandlebarsHelpers.cs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HandlebarsDotNet;
2+
using Newtonsoft.Json;
23
using SilkierQuartz.Models;
34
using SilkierQuartz.TypeHandlers;
45
using System;
@@ -51,11 +52,11 @@ void RegisterInternal()
5152
h.RegisterHelper("Upper", (o, c, a) => o.Write(a[0].ToString().ToUpper()));
5253
h.RegisterHelper("Lower", (o, c, a) => o.Write(a[0].ToString().ToLower()));
5354
h.RegisterHelper("LocalTimeZoneInfoId", (o, c, a) => o.Write(TimeZoneInfo.Local.Id));
54-
h.RegisterHelper("SystemTimeZonesJson", (o, c, a) => Json(o, c, TimeZoneInfo.GetSystemTimeZones().ToDictionary()));
55+
h.RegisterHelper("SystemTimeZonesJson", (o, c, a) => Json(o, c, a,TimeZoneInfo.GetSystemTimeZones().ToDictionary()));
5556
h.RegisterHelper("DefaultDateFormat", (o, c, a) => o.Write(DateTimeSettings.DefaultDateFormat));
5657
h.RegisterHelper("DefaultTimeFormat", (o, c, a) => o.Write(DateTimeSettings.DefaultTimeFormat));
57-
h.RegisterHelper("DoLayout", (o, c, a) => c.Layout());
58-
h.RegisterHelper("SerializeTypeHandler", (o, c, a) => o.WriteSafeString(((Services)a[0]).TypeHandlers.Serialize((TypeHandlerBase)c)));
58+
h.RegisterHelper("DoLayout", (o, c, a) => (c.Value as Histogram)?.Layout());
59+
h.RegisterHelper("SerializeTypeHandler", (o, c, a) => o.WriteSafeString(_services.TypeHandlers.Serialize((TypeHandlerBase)c.Value)));
5960
h.RegisterHelper("Disabled", (o, c, a) => { if (IsTrue(a[0])) o.Write("disabled"); });
6061
h.RegisterHelper("Checked", (o, c, a) => { if (IsTrue(a[0])) o.Write("checked"); });
6162
h.RegisterHelper("nvl", (o, c, a) => o.Write(a[a[0] == null ? 1 : 0]));
@@ -66,7 +67,7 @@ void RegisterInternal()
6667
h.RegisterHelper(nameof(RenderJobDataMapValue), RenderJobDataMapValue);
6768
h.RegisterHelper(nameof(ViewBag), ViewBag);
6869
h.RegisterHelper(nameof(ActionUrl), ActionUrl);
69-
h.RegisterHelper(nameof(Json), Json);
70+
h.RegisterHelper(nameof(Json), (o, c, a) => Json(o, c, a));
7071
h.RegisterHelper(nameof(Selected), Selected);
7172
h.RegisterHelper(nameof(isType), isType);
7273
h.RegisterHelper(nameof(eachPair), eachPair);
@@ -120,18 +121,18 @@ private string AddQueryString(string uri, IEnumerable<KeyValuePair<string, objec
120121
return sb.ToString();
121122
}
122123

123-
void ViewBag(TextWriter output, dynamic context, params object[] arguments)
124+
void ViewBag(EncodedTextWriter output, Context context, Arguments arguments)
124125
{
125126
var dict = (IDictionary<string, object>)arguments[0];
126-
var viewBag = (IDictionary<string, object>)context.ViewBag;
127+
var viewBag = (IDictionary<string, object>)context["ViewBag"];
127128

128129
foreach (var pair in dict)
129130
{
130131
viewBag[pair.Key] = pair.Value;
131132
}
132133
}
133134

134-
void MenuItemActionLink(TextWriter output, dynamic context, params object[] arguments)
135+
void MenuItemActionLink(EncodedTextWriter output, Context context, Arguments arguments)
135136
{
136137
var dict = arguments[0] as IDictionary<string, object> ?? new Dictionary<string, object>() { ["controller"] = arguments[0] };
137138

@@ -141,7 +142,7 @@ void MenuItemActionLink(TextWriter output, dynamic context, params object[] argu
141142
}
142143

143144
var classes = "item";
144-
if (dict["controller"].Equals(context.ControllerName))
145+
if (dict["controller"].Equals(context.GetValue<string>("ControllerName")))
145146
classes += " active";
146147

147148
var url = BaseUrl + dict["controller"];
@@ -150,7 +151,7 @@ void MenuItemActionLink(TextWriter output, dynamic context, params object[] argu
150151
output.WriteSafeString($@"<a href=""{url}"" class=""{classes}"">{title}</a>");
151152
}
152153

153-
void ActionUrl(TextWriter output, dynamic context, params object[] arguments)
154+
void ActionUrl(EncodedTextWriter output, Context context, Arguments arguments)
154155
{
155156
if (arguments.Length < 1 || arguments.Length > 3)
156157
throw new ArgumentOutOfRangeException(nameof(arguments));
@@ -173,8 +174,7 @@ void ActionUrl(TextWriter output, dynamic context, params object[] arguments)
173174
if (arguments.Length == 3) // [actionName, controllerName, routeValues]
174175
routeValues = (IDictionary<string, object>)arguments[2];
175176

176-
if (controller == null)
177-
controller = context.ControllerName;
177+
controller ??= context.GetValue<string>("ControllerName");
178178

179179
var url = BaseUrl + controller;
180180

@@ -184,7 +184,7 @@ void ActionUrl(TextWriter output, dynamic context, params object[] arguments)
184184
output.WriteSafeString(AddQueryString(url, routeValues));
185185
}
186186

187-
void Selected(TextWriter output, dynamic context, params object[] arguments)
187+
void Selected(EncodedTextWriter output, Context context, Arguments arguments)
188188
{
189189
string selected;
190190
if (arguments.Length >= 2)
@@ -196,18 +196,27 @@ void Selected(TextWriter output, dynamic context, params object[] arguments)
196196
output.Write("selected");
197197
}
198198

199-
void Json(TextWriter output, dynamic context, params object[] arguments)
199+
void Json(EncodedTextWriter output, Context context, Arguments arguments, params object[] args)
200200
{
201-
output.WriteSafeString(Newtonsoft.Json.JsonConvert.SerializeObject(arguments[0]));
201+
if (arguments.Length > 0)
202+
{
203+
output.WriteSafeString(JsonConvert.SerializeObject(arguments[0]));
204+
}
205+
206+
if (args.Length <= 0)
207+
{
208+
return;
209+
}
210+
211+
output.WriteSafeString(JsonConvert.SerializeObject(args[0]));
202212
}
203213

204-
void RenderJobDataMapValue(TextWriter output, dynamic context, params object[] arguments)
214+
void RenderJobDataMapValue(EncodedTextWriter output, Context context, Arguments arguments)
205215
{
206-
var item = (JobDataMapItem)arguments[1];
207-
output.WriteSafeString(item.SelectedType.RenderView((Services)arguments[0], item.Value));
216+
var item = (JobDataMapItem)arguments[0];
217+
output.WriteSafeString(item.SelectedType.RenderView(_services, item.Value));
208218
}
209-
210-
void isType(TextWriter writer, HelperOptions options, dynamic context, params object[] arguments)
219+
void isType(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments)
211220
{
212221
Type[] expectedType;
213222

@@ -228,12 +237,12 @@ void isType(TextWriter writer, HelperOptions options, dynamic context, params ob
228237
var t = arguments[0]?.GetType();
229238

230239
if (expectedType.Any(x => x.IsAssignableFrom(t)))
231-
options.Template(writer, (object)context);
240+
options.Template(writer, context.Value);
232241
else
233-
options.Inverse(writer, (object)context);
242+
options.Inverse(writer, context.Value);
234243
}
235244

236-
void eachPair(TextWriter writer, HelperOptions options, dynamic context, params object[] arguments)
245+
void eachPair(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments)
237246
{
238247
void OutputElements<T>()
239248
{
@@ -248,39 +257,39 @@ void OutputElements<T>()
248257
OutputElements<KeyValuePair<string, object>>();
249258
}
250259

251-
void eachItems(TextWriter writer, HelperOptions options, dynamic context, params object[] arguments)
260+
void eachItems(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments)
252261
{
253262
eachPair(writer, options, context, ((dynamic)arguments[0]).GetItems());
254263
}
255264

256-
void ToBase64(TextWriter output, dynamic context, params object[] arguments)
265+
void ToBase64(EncodedTextWriter output, Context context, Arguments arguments)
257266
{
258267
var bytes = (byte[])arguments[0];
259268

260269
if (bytes != null)
261270
output.Write(Convert.ToBase64String(bytes));
262271
}
263272

264-
void footer(TextWriter writer, HelperOptions options, dynamic context, params object[] arguments)
273+
void footer(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments)
265274
{
266-
IDictionary<string, object> viewBag = context.ViewBag;
275+
var viewBag = (IDictionary<string, object>)context["ViewBag"];
267276

268277
if (viewBag.TryGetValue("ShowFooter", out var show) && (bool)show == true)
269278
{
270279
options.Template(writer, (object)context);
271280
}
272281
}
273-
void SilkierQuartzVersion(TextWriter output, dynamic context, params object[] arguments)
282+
void SilkierQuartzVersion(EncodedTextWriter output, Context context, Arguments arguments)
274283
{
275284
var v = GetType().Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().FirstOrDefault();
276285
output.Write(v.InformationalVersion);
277286
}
278287

279-
void Logo(TextWriter output, dynamic context, params object[] arguments)
288+
void Logo(EncodedTextWriter output, Context context, Arguments arguments)
280289
{
281290
output.Write(_services.Options.Logo);
282291
}
283-
void ProductName(TextWriter output, dynamic context, params object[] arguments)
292+
void ProductName(EncodedTextWriter output, Context context, Arguments arguments)
284293
{
285294
output.Write(_services.Options.ProductName);
286295
}

src/SilkierQuartz/SilkierQuartz.csproj

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,65 +30,17 @@
3030
</PropertyGroup>
3131
<PropertyGroup>
3232
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
33-
</PropertyGroup>
34-
<PropertyGroup>
35-
<DefineConstants></DefineConstants>
3633
<OutputType>Library</OutputType>
37-
<DebugType>full</DebugType>
38-
</PropertyGroup>
39-
40-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
41-
<Optimize>True</Optimize>
42-
</PropertyGroup>
43-
44-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net5.0|AnyCPU'">
45-
<Optimize>True</Optimize>
46-
</PropertyGroup>
47-
48-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0|AnyCPU'">
49-
<Optimize>True</Optimize>
50-
</PropertyGroup>
51-
52-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0|AnyCPU'">
53-
<Optimize>True</Optimize>
54-
</PropertyGroup>
55-
56-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
57-
<Optimize>True</Optimize>
58-
</PropertyGroup>
59-
60-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp3.1|AnyCPU'">
61-
<Optimize>False</Optimize>
62-
</PropertyGroup>
63-
64-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0|AnyCPU'">
65-
<Optimize>False</Optimize>
66-
</PropertyGroup>
67-
68-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
69-
<Optimize>False</Optimize>
70-
</PropertyGroup>
71-
72-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0|AnyCPU'">
73-
<Optimize>False</Optimize>
74-
</PropertyGroup>
75-
76-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
77-
<Optimize>False</Optimize>
78-
</PropertyGroup>
79-
80-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0|AnyCPU'">
81-
<Optimize>False</Optimize>
8234
</PropertyGroup>
8335

8436
<ItemGroup>
8537
<ProjectReference Include="..\Quartz.Plugins.RecentHistory\Quartz.Plugins.RecentHistory.csproj" />
8638
</ItemGroup>
8739

8840
<ItemGroup>
89-
<PackageReference Include="Handlebars.Net" Version="1.11.5" />
41+
<PackageReference Include="Handlebars.Net" Version="2.1.6" />
9042
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
91-
<PackageReference Include="Quartz" Version="3.13.0" />
43+
<PackageReference Include="Quartz" Version="3.14.0" />
9244
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
9345
</ItemGroup>
9446
<ItemGroup Condition="'$(TargetFramework)' == 'net9'">

src/SilkierQuartz/TypeHandlerService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using JsonSubTypes;
1+
using HandlebarsDotNet;
2+
using JsonSubTypes;
23
using Newtonsoft.Json;
34
using SilkierQuartz.TypeHandlers;
45
using System;
@@ -46,7 +47,7 @@ class TypeHandlerDescriptor
4647

4748
public string TypeId { get; set; }
4849

49-
public Func<object, string> Render { get; set; }
50+
public HandlebarsTemplate<object, string> Render { get; set; }
5051

5152
public TypeHandlerResourcesAttribute Resources { get; set; }
5253
}

src/SilkierQuartz/ViewEngine.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using HandlebarsDotNet;
2+
using System;
23
using System.Collections.Generic;
34
using System.Globalization;
45

@@ -7,7 +8,7 @@ namespace SilkierQuartz
78
public class ViewEngine
89
{
910
readonly Services _services;
10-
readonly Dictionary<string, Func<object, string>> _compiledViews = new Dictionary<string, Func<object, string>>(StringComparer.OrdinalIgnoreCase);
11+
readonly Dictionary<string, HandlebarsTemplate<object, string>> _compiledViews = new Dictionary<string, HandlebarsTemplate<object, string>>(StringComparer.OrdinalIgnoreCase);
1112

1213
public bool UseCache { get; set; }
1314

@@ -17,7 +18,7 @@ public ViewEngine(Services services)
1718
UseCache = string.IsNullOrEmpty(services.Options.ViewsRootDirectory);
1819
}
1920

20-
Func<object, string> GetRenderDelegate(string templatePath)
21+
HandlebarsTemplate<object, string> GetRenderDelegate(string templatePath)
2122
{
2223
if (UseCache)
2324
{
@@ -44,7 +45,7 @@ public string Render(string templatePath, object model)
4445

4546
public string Encode(object value)
4647
{
47-
return _services.Handlebars.Configuration.TextEncoder.Encode(string.Format(CultureInfo.InvariantCulture, "{0}", value));
48+
return string.Format(CultureInfo.InvariantCulture, "{0}", value);
4849
}
4950

5051
public string ErrorPage(Exception ex)

src/SilkierQuartz/Views/Calendars/Index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<tbody>
2424
{{#each Model}}
2525
<tr>
26-
<td class="cal-name"><a href="{{ActionUrl 'Edit' @ControllerName name=Name}}">{{Name}}</a></td>
26+
<td class="cal-name"><a href="{{ActionUrl 'Edit' 'Calendars' name=Name}}">{{Name}}</a></td>
2727
<td class="cal-desc">{{Description}}</td>
2828
<td class="cal-type">
2929
<img class="ui inline image" src="Content/Images/type.png">&nbsp;{{Type.FullName}}

src/SilkierQuartz/Views/Jobs/Index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{{#each Model}}
4343
<tr>
4444
<td class="job-name">
45-
<a href="{{ActionUrl 'Edit' @ControllerName group=Group name=JobName}}" title="{{Description}}">{{JobName}}</a>
45+
<a href="{{ActionUrl 'Edit' 'Jobs' group=Group name=JobName}}" title="{{Description}}">{{JobName}}</a>
4646
</td>
4747
<td class="job-group">{{Group}}</td>
4848
<td class="job-type">{{Type}}</td>

src/SilkierQuartz/Views/Partials/JobDataMapRow.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<tr class="{{#if template}}template{{/if}}">
22
<td class="name-col field accept-error"><input type="text" name="data-map[name]" placeholder="Parameter Name" value="{{item.Name}}" autocomplete="off"></td>
33
<td class="value-col field accept-error">
4-
{{RenderJobDataMapValue @Services item}}
4+
{{RenderJobDataMapValue item}}
55
</td>
66
<td class="type-col">
77
<input type="hidden" class="type-handler" name="data-map[handler]" />
@@ -11,7 +11,7 @@
1111
<div class="default text">Select Type</div>
1212
<div class="menu">
1313
{{#each item.SupportedTypes}}
14-
<div class="item" data-value="{{Name}}" data-type-handler="{{SerializeTypeHandler @Services}}" data-type-handler-id="{{TypeId}}">
14+
<div class="item" data-value="{{Name}}" data-type-handler="{{SerializeTypeHandler }}" data-type-handler-id="{{TypeId}}">
1515
<img class="ui mini image" src="Content/Images/type.png">{{DisplayName}}
1616
</div>
1717
{{/each}}

src/SilkierQuartz/Views/Triggers/Index.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@
4949
</td>
5050
<td class="job-group">{{JobGroup}}</td>
5151
<td colspan="6" style="text-align: right">
52-
<a href="{{ActionUrl 'PauseJob' @ControllerName}}" class="ui super tiny button btn-pause-all"><i class="pause icon"></i>Pause All</a>
53-
<a href="{{ActionUrl 'ResumeJob' @ControllerName}}" class="ui super tiny button btn-resume-all"><i class="play icon"></i>Resume All</a>
52+
<a href="{{ActionUrl 'PauseJob' 'Triggers'}}" class="ui super tiny button btn-pause-all"><i class="pause icon"></i>Pause All</a>
53+
<a href="{{ActionUrl 'ResumeJob' 'Triggers'}}" class="ui super tiny button btn-resume-all"><i class="play icon"></i>Resume All</a>
5454
</td>
5555
</tr>
5656
{{/if}}
5757

5858
<tr>
5959
<td class="trigger-name">
6060
{{#if IsPaused}}<i class="small pause icon" title="Paused"></i>{{/if}}
61-
<a href="{{ActionUrl 'Edit' @ControllerName group=TriggerGroup name=TriggerName}}" title="{{Description}}">{{TriggerName}}</a>
61+
<a href="{{ActionUrl 'Edit' 'Triggers' group=TriggerGroup name=TriggerName}}" title="{{Description}}">{{TriggerName}}</a>
6262
</td>
6363
<td class="trigger-group">{{TriggerGroup}}</td>
6464
<td class="schedule-desc" data-content="{{ScheduleDescription}}">

0 commit comments

Comments
 (0)