Skip to content

Commit a536099

Browse files
committed
MAJOR REFACTOR re-branding SS.Templates to SS.Script
All Template pages are unaffected and most user-facing classes are backward source-compatible.
1 parent 93ad4ab commit a536099

103 files changed

Lines changed: 3582 additions & 2606 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ServiceStack.Common/JSON.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using ServiceStack.Templates;
3+
using ServiceStack.Script;
44
using ServiceStack.Text;
55
using ServiceStack.Text.Json;
66

@@ -68,18 +68,18 @@ public static void Configure()
6868

6969
public static void UnConfigure() => JsonTypeSerializer.Instance.ObjectDeserializer = null;
7070

71-
public static TemplateScopeContext CreateScope(Dictionary<string, object> args = null, TemplateFilter functions = null)
71+
public static ScriptScopeContext CreateScope(Dictionary<string, object> args = null, ScriptMethods functions = null)
7272
{
73-
var context = new TemplateContext();
73+
var context = new ScriptContext();
7474
if (functions != null)
75-
context.TemplateFilters.Insert(0, functions);
75+
context.ScriptMethods.Insert(0, functions);
7676

7777
context.Init();
78-
return new TemplateScopeContext(new PageResult(context.OneTimePage("")), null, args);
78+
return new ScriptScopeContext(new PageResult(context.OneTimePage("")), null, args);
7979
}
8080

8181
public static object eval(string js) => eval(js, CreateScope());
82-
public static object eval(string js, TemplateScopeContext scope)
82+
public static object eval(string js, ScriptScopeContext scope)
8383
{
8484
js.ParseJsExpression(out var token);
8585
var result = token.Evaluate(scope);

src/ServiceStack.Common/Templates/Blocks/TemplateCaptureBlock.cs renamed to src/ServiceStack.Common/Script/Blocks/CaptureScriptBlock.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading;
54
using System.Threading.Tasks;
65
using ServiceStack.Text;
76

8-
namespace ServiceStack.Templates
7+
namespace ServiceStack.Script
98
{
109
/// <summary>
1110
/// Captures the output and assigns it to the specified variable.
@@ -15,11 +14,11 @@ namespace ServiceStack.Templates
1514
/// {{#capture output {nums:[1,2,3]} }} {{#each nums}} {{it}} {{/each}} {{/capture}}
1615
/// {{#capture appendTo output {nums:[1,2,3]} }} {{#each nums}} {{it}} {{/each}} {{/capture}}
1716
/// </summary>
18-
public class TemplateCaptureBlock : TemplateBlock
17+
public class CaptureScriptBlock : ScriptBlock
1918
{
2019
public override string Name => "capture";
2120

22-
public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragment block, CancellationToken token)
21+
public override async Task WriteAsync(ScriptScopeContext scope, PageBlockFragment block, CancellationToken token)
2322
{
2423
var (name, scopeArgs, appendTo) = Parse(scope, block);
2524

@@ -43,7 +42,7 @@ public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragm
4342
}
4443

4544
//Extract usages of Span outside of async method
46-
private (string name, Dictionary<string, object> scopeArgs, bool appendTo) Parse(TemplateScopeContext scope, PageBlockFragment block)
45+
private (string name, Dictionary<string, object> scopeArgs, bool appendTo) Parse(ScriptScopeContext scope, PageBlockFragment block)
4746
{
4847
if (block.Argument.IsNullOrWhiteSpace())
4948
throw new NotSupportedException("'capture' block is missing name of variable to assign captured output to");

src/ServiceStack.Common/Templates/Blocks/TemplateEachBlock.cs renamed to src/ServiceStack.Common/Script/Blocks/EachScriptBlock.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Threading.Tasks;
77
using ServiceStack.Text;
88

9-
namespace ServiceStack.Templates
9+
namespace ServiceStack.Script
1010
{
1111
/// <summary>
1212
/// Handlebars.js like each block
@@ -19,11 +19,11 @@ namespace ServiceStack.Templates
1919
/// {{#each n in numbers where n > 5}} {{it}} {{else}} no numbers > 5 {{/each}}
2020
/// {{#each n in numbers where n > 5 orderby n skip 1 take 2}} {{it}} {{else}} no numbers > 5 {{/each}}
2121
/// </summary>
22-
public class TemplateEachBlock : TemplateBlock
22+
public class EachScriptBlock : ScriptBlock
2323
{
2424
public override string Name => "each";
2525

26-
public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragment block, CancellationToken token)
26+
public override async Task WriteAsync(ScriptScopeContext scope, PageBlockFragment block, CancellationToken token)
2727
{
2828
if (block.Argument.IsNullOrEmpty())
2929
throw new NotSupportedException("'each' block requires the collection to iterate");
@@ -128,7 +128,7 @@ public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragm
128128
}
129129
}
130130

131-
EachArg ParseArgument(TemplateScopeContext scope, PageBlockFragment fragment)
131+
EachArg ParseArgument(ScriptScopeContext scope, PageBlockFragment fragment)
132132
{
133133
var literal = fragment.Argument.Span.ParseJsExpression(out var token);
134134
if (token == null)

src/ServiceStack.Common/Templates/Blocks/TemplateEvalBlock.cs renamed to src/ServiceStack.Common/Script/Blocks/EvalScriptBlock.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
1+
using System.Collections.Generic;
42
using System.Linq;
53
using System.Threading;
64
using System.Threading.Tasks;
7-
using ServiceStack.IO;
85
using ServiceStack.Text;
96

10-
namespace ServiceStack.Templates
7+
namespace ServiceStack.Script
118
{
129
/// <summary>
1310
/// Special block which evaluates the rendered body as a ServiceStack Template
@@ -19,20 +16,20 @@ namespace ServiceStack.Templates
1916
/// emit {{evaluateBodyOfArg}} at {{now}} in new context
2017
/// {{/eval}}
2118
/// </summary>
22-
public class TemplateEvalBlock : TemplateBlock
19+
public class EvalScriptBlock : ScriptBlock
2320
{
2421
public override string Name => "eval";
2522

26-
public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragment block, CancellationToken token)
23+
public override async Task WriteAsync(ScriptScopeContext scope, PageBlockFragment block, CancellationToken token)
2724
{
2825
var argValue = block.Argument.GetJsExpressionAndEvaluate(scope);
2926
var args = argValue as Dictionary<string, object> ?? new Dictionary<string, object>();
3027

3128
var format = scope.Context.PageFormats.First().Extension;
32-
if (args.TryGetValue(TemplateConstants.Format, out var oFormat))
29+
if (args.TryGetValue(ScriptConstants.Format, out var oFormat))
3330
{
3431
format = oFormat.ToString();
35-
args.Remove(TemplateConstants.Format);
32+
args.Remove(ScriptConstants.Format);
3633
}
3734

3835
var htmlDecode = false;
@@ -44,7 +41,7 @@ public override async Task WriteAsync(TemplateScopeContext scope, PageBlockFragm
4441
}
4542

4643
var context = scope.CreateNewContext(args);
47-
var unrenderedBody = new TemplatePartialPage(scope.Context, "eval-page", block.Body, format, args);
44+
var unrenderedBody = new SharpPartialPage(scope.Context, "eval-page", block.Body, format, args);
4845

4946
using (var ms = MemoryStreamFactory.GetStream())
5047
{

0 commit comments

Comments
 (0)