本文整理汇总了C#中IViewEngineHost类的典型用法代码示例。如果您正苦于以下问题:C# IViewEngineHost类的具体用法?C# IViewEngineHost怎么用?C# IViewEngineHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IViewEngineHost类属于命名空间,在下文中一共展示了IViewEngineHost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MarkdownViewEngineHost
public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext)
{
this.viewEngineHost = viewEngineHost;
this.renderContext = renderContext;
this.Context = this.renderContext.Context;
this.parser = new MarkdownSharp.Markdown();
}
示例2: MarkdownViewEngineHost
/// <summary>
/// Initializes a new instance of the <see cref="MarkdownViewEngineHost"/> class.
/// </summary>
/// <param name="viewEngineHost">A decorator <see cref="IViewEngineHost"/></param>
/// <param name="renderContext">The render context.</param>
/// <param name="viewExtensions">The allowed extensions</param>
public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext, IEnumerable<string> viewExtensions)
{
this.viewEngineHost = viewEngineHost;
this.renderContext = renderContext;
this.validExtensions = viewExtensions;
this.Context = this.renderContext.Context;
this.parser = new MarkdownSharp.Markdown();
}
示例3: SuperSimpleViewEngine
/// <summary>
/// Initializes a new instance of the <see cref="SuperSimpleViewEngine"/> class.
/// </summary>
public SuperSimpleViewEngine(IViewEngineHost viewEngineHost)
{
this.viewEngineHost = viewEngineHost;
this.processors = new List<Func<string, object, string>>
{
this.PerformSingleSubstitutions,
this.PerformEachSubstitutions,
this.PerformConditionalSubstitutions,
this.PerformPartialSubstitutions,
this.PerformMasterPageSubstitutions,
};
}
示例4: PerformPathSubstitutions
/// <summary>
/// Perform path expansion substitutions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with paths expanded</returns>
private static string PerformPathSubstitutions(string template, object model, IViewEngineHost host)
{
var result = template;
result = PathExpansionRegEx.Replace(
result,
m =>
{
var path = m.Groups["Path"].Value;
return host.ExpandPath(path);
});
return result;
}
示例5: PerformConditionalSubstitutions
/// <summary>
/// Performs @If.PropertyName and @IfNot.PropertyName substitutions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with @If.PropertyName @IfNot.PropertyName blocks removed/expanded.</returns>
private static string PerformConditionalSubstitutions(string template, object model, IViewEngineHost host)
{
var result = template;
result = ConditionalSubstitutionRegEx.Replace(
result,
m =>
{
var properties = GetCaptureGroupValues(m, "ParameterName");
var modelSource = GetCaptureGroupValues(m, "ModelSource").SingleOrDefault();
if (modelSource != null && modelSource.Equals("Context", StringComparison.OrdinalIgnoreCase))
{
model = host.Context;
}
var predicateResult = GetPredicateResult(model, properties, m.Groups["Null"].Value == "Null");
if (m.Groups["Not"].Value == "Not")
{
predicateResult = !predicateResult;
}
return predicateResult ? m.Groups["Contents"].Value : string.Empty;
});
return result;
}
示例6: PerformAntiForgeryTokenSubstitutions
/// <summary>
/// Perform CSRF anti forgery token expansions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with anti forgery tokens expanded</returns>
private static string PerformAntiForgeryTokenSubstitutions(string template, object model, IViewEngineHost host)
{
return AntiForgeryTokenRegEx.Replace(template, x => host.AntiForgeryToken());
}
示例7: Render
/// <summary>
/// Renders a template
/// </summary>
/// <param name="template">The template to render.</param>
/// <param name="model">The model to user for rendering.</param>
/// <param name="host">The view engine host</param>
/// <returns>A string containing the expanded template.</returns>
public string Render(string template, dynamic model, IViewEngineHost host)
{
var output =
this.processors.Aggregate(template, (current, processor) => processor(current, model ?? new object(), host));
return this.matchers.Aggregate(output, (current, extension) => extension.Invoke(current, model, host));
}
示例8: PerformPartialSubstitutions
/// <summary>
/// Perform @Partial partial view expansion
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with partials expanded</returns>
private string PerformPartialSubstitutions(string template, dynamic model, IViewEngineHost host)
{
var result = template;
result = PartialSubstitutionRegEx.Replace(
result,
m =>
{
var partialViewName = m.Groups["ViewName"].Value;
var partialModel = model;
var properties = GetCaptureGroupValues(m, "ParameterName");
if (m.Groups["Model"].Length > 0)
{
var modelValue = GetPropertyValueFromParameterCollection(partialModel, properties);
if (modelValue.Item1 != true)
{
return "[ERR!]";
}
partialModel = modelValue.Item2;
}
var partialTemplate = host.GetTemplate(partialViewName, partialModel);
return this.Render(partialTemplate, partialModel, host);
});
return result;
}
示例9: PerformEachSubstitutions
/// <summary>
/// Performs @Each.PropertyName substitutions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with @Each.PropertyName blocks expanded.</returns>
private string PerformEachSubstitutions(string template, object model, IViewEngineHost host)
{
return EachSubstitutionRegEx.Replace(
template,
m =>
{
var properties = GetCaptureGroupValues(m, "ParameterName");
var modelSource = GetCaptureGroupValues(m, "ModelSource").SingleOrDefault();
if (modelSource != null && modelSource.Equals("Context", StringComparison.OrdinalIgnoreCase))
{
model = host.Context;
}
var substitutionObject = GetPropertyValueFromParameterCollection(model, properties);
if (substitutionObject.Item1 == false)
{
return "[ERR!]";
}
if (substitutionObject.Item2 == null)
{
return string.Empty;
}
var substitutionEnumerable = substitutionObject.Item2 as IEnumerable;
if (substitutionEnumerable == null)
{
return "[ERR!]";
}
var contents = m.Groups["Contents"].Value;
var result = string.Empty;
foreach (var item in substitutionEnumerable)
{
var modifiedContent = PerformPartialSubstitutions(contents, item, host);
modifiedContent = PerformConditionalSubstitutions(modifiedContent, item, host);
result += ReplaceCurrentMatch(modifiedContent, item, host);
}
return result;
});
}
示例10: PerformConditionalSubstitutions
/// <summary>
/// Performs @If.PropertyName and @IfNot.PropertyName substitutions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with @If.PropertyName @IfNot.PropertyName blocks removed/expanded.</returns>
private string PerformConditionalSubstitutions(string template, object model, IViewEngineHost host)
{
var result = template;
result = ConditionalSubstitutionRegEx.Replace(
result,
m =>
{
var properties = GetCaptureGroupValues(m, "ParameterName");
var predicateResult = GetPredicateResult(model, properties);
if (m.Groups["Not"].Value == "Not")
{
predicateResult = !predicateResult;
}
return predicateResult ? m.Groups["Contents"].Value : string.Empty;
});
return result;
}
示例11: Render
/// <summary>
/// Renders a template
/// </summary>
/// <param name="template">The template to render.</param>
/// <param name="model">The model to user for rendering.</param>
/// <param name="host">The view engine host</param>
/// <returns>A string containing the expanded template.</returns>
public string Render(string template, dynamic model, IViewEngineHost host)
{
return this.processors.Aggregate(template, (current, processor) => processor(current, model ?? new object(), host));
}
示例12: PerformPathSubstitutions
/// <summary>
/// Perform path expansion substitutions
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">The model.</param>
/// <param name="host">View engine host</param>
/// <returns>Template with paths expanded</returns>
private static string PerformPathSubstitutions(string template, object model, IViewEngineHost host)
{
var result = template;
result = PathExpansionRegEx.Replace(
result,
m =>
{
var path = m.Groups["Path"].Value;
return host.ExpandPath(path);
});
result = AttributeValuePathExpansionRegEx.Replace(
result,
m =>
{
var attribute = m.Groups["Attribute"];
var quote = m.Groups["Quote"].Value;
var path = m.Groups["Path"].Value;
var expandedPath = host.ExpandPath(path);
return string.Format("{0}={1}{2}{1}", attribute, quote, expandedPath);
});
return result;
}
示例13: Invoke
public string Invoke(string p_Content, dynamic p_Model, IViewEngineHost p_Host)
{
return p_Content.Replace("@GrooveCaster.Version", Application.GetVersion());
}
示例14: MarkdownViewEngineHost
public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext)
{
this.viewEngineHost = viewEngineHost;
this.renderContext = renderContext;
this.Context = this.renderContext.Context;
}
示例15: PerformViewBagSubstitutions
/// <summary>
/// Performs single @ViewBag.PropertyName substitutions.
/// </summary>
/// <param name="template">The template.</param>
/// <param name="model">This parameter is not used, the model is based on the "host.Context.ViewBag".</param>
/// <param name="host">View engine host</param>
/// <returns>Template with @ViewBag.PropertyName blocks expanded.</returns>
private static string PerformViewBagSubstitutions(string template, object model, IViewEngineHost host)
{
return ViewBagSubstitutionsRegEx.Replace(
template,
m =>
{
var properties = GetCaptureGroupValues(m, "ParameterName");
var substitution = GetPropertyValueFromParameterCollection(((dynamic)host.Context).ViewBag, properties);
if (!substitution.Item1)
{
return "[ERR!]";
}
if (substitution.Item2 == null)
{
return string.Empty;
}
return m.Groups["Encode"].Success ? host.HtmlEncode(substitution.Item2.ToString()) : substitution.Item2.ToString();
});
}