2013-05-26 19:54:50 -10:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.UI.JavaScript
|
|
|
|
|
|
{
|
2014-01-16 12:31:29 +11:00
|
|
|
|
public sealed class ServerVariablesParser
|
2013-05-26 19:54:50 -10:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-04-27 12:41:19 +10:00
|
|
|
|
/// Allows developers to add custom variables on parsing
|
2013-05-26 19:54:50 -10:00
|
|
|
|
/// </summary>
|
2014-01-29 09:33:14 +11:00
|
|
|
|
public static event EventHandler<Dictionary<string, object>> Parsing;
|
2013-05-26 19:54:50 -10:00
|
|
|
|
|
|
|
|
|
|
internal const string Token = "##Variables##";
|
|
|
|
|
|
|
|
|
|
|
|
internal static string Parse(Dictionary<string, object> items)
|
|
|
|
|
|
{
|
2013-05-27 01:23:49 -10:00
|
|
|
|
var vars = Resources.ServerVariables;
|
2013-05-26 19:54:50 -10:00
|
|
|
|
|
2015-04-27 12:41:19 +10:00
|
|
|
|
//Raise event for developers to add custom variables
|
2013-05-26 19:54:50 -10:00
|
|
|
|
if (Parsing != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parsing(null, items);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var json = JObject.FromObject(items);
|
2014-01-29 09:33:14 +11:00
|
|
|
|
return vars.Replace(Token, json.ToString());
|
|
|
|
|
|
|
2013-05-26 19:54:50 -10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|