forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvScriptBlock.cs
More file actions
34 lines (30 loc) · 1.05 KB
/
Copy pathCsvScriptBlock.cs
File metadata and controls
34 lines (30 loc) · 1.05 KB
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ServiceStack.Text;
namespace ServiceStack.Script
{
/// <summary>
/// Parse csv contents into a string dictionary List and assign to identifier
/// Usage: {{#csv list}}
/// Item,Qty
/// Apples,2
/// Oranges,3
/// {{/csv}}
/// </summary>
public class CsvScriptBlock : ScriptBlock
{
public override string Name => "csv";
public override ScriptLanguage Body => ScriptVerbatim.Language;
public override Task WriteAsync(ScriptScopeContext scope, PageBlockFragment block, CancellationToken ct)
{
var literal = block.Argument.ParseVarName(out var name);
var strFragment = (PageStringFragment)block.Body[0];
var csvList = Context.DefaultMethods.parseCsv(strFragment.ValueString);
scope.PageResult.Args[name.ToString()] = csvList;
return TypeConstants.EmptyTask;
}
}
}