/// <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) { //Regex(@"@Partial\['(?<ViewName>[^\]]+)'(?:.[ ]?@?(?<Model>(Model|Current)(?:\.(?<ParameterName>[a-zA-Z0-9-_]+))*))?\];?", RegexOptions.Compiled); 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); }
public string Invoke(string content, dynamic model, IViewEngineHost host) { return(TranslationSubstitutionsRegEx.Replace( content, m => { // A match was found! string translationResult; // Get the translation 'key'. var translationKey = m.Groups["TranslationKey"].Value; // Load the appropriate translation. This could farm off to // a ResourceManager for example. The below implementation // obviously isn't very useful and is just illustrative. :) if (translationKey == "Hello_World") { translationResult = "Hello World!"; } else { // We didn't find any translation key matches so we will // use the key itself. translationResult = translationKey; } return translationResult; })); }
public string Invoke(string content, dynamic model, IViewEngineHost host) { return(TranslationSubstitutionsRegEx.Replace( content, m => { // A match was found! string translationResult; // Get the translation 'key'. var translationKey = m.Groups["TranslationKey"].Value; // Load the appro if (translationKey == "Hello_World") { translationResult = "Hello World!"; } else { // We didn't find any translation key matches so we will // use the key itself. translationResult = translationKey; } return translationResult; })); }
public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext) { this.viewEngineHost = viewEngineHost; this.renderContext = renderContext; this.Context = this.renderContext.Context; this.parser = new MarkdownSharp.Markdown(); }
/// <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))); }
public string Invoke(string content, dynamic model, IViewEngineHost host) { return(EqualSubstitutionsRegEx.Replace( content, m => { var LeftItem = m.Groups["LeftItem"].Value; var RightItem = m.Groups["RightItem"].Value; var NotItem = m.Groups["Not"].Value; var ResultItem = m.Groups["ResultItem"].Value; if (LeftItem != null && RightItem != null) { if (LeftItem == RightItem && String.IsNullOrEmpty(NotItem)) { return ResultItem; } ; if (LeftItem != RightItem && !String.IsNullOrEmpty(NotItem)) { return ResultItem; } ; return "[ERR]"; } else { return "[ERR]"; } })); }
/// <summary> /// Expand a @Current match inside an @Each iterator /// </summary> /// <param name="contents">Contents of the @Each block</param> /// <param name="item">Current item from the @Each enumerable</param> /// <param name="host">View engine host</param> /// <returns>String result of the expansion of the @Each.</returns> private static string ReplaceCurrentMatch(string contents, object item, IViewEngineHost host) { return(EachItemSubstitutionRegEx.Replace( contents, eachMatch => { if (string.IsNullOrEmpty(eachMatch.Groups["ParameterName"].Value)) { return eachMatch.Groups["Encode"].Success ? host.HtmlEncode(item.ToString()) : item.ToString(); } var properties = GetCaptureGroupValues(eachMatch, "ParameterName"); var substitution = GetPropertyValueFromParameterCollection(item, properties); if (!substitution.Item1) { return "[ERR!]"; } if (substitution.Item2 == null) { return string.Empty; } return eachMatch.Groups["Encode"].Success ? host.HtmlEncode(substitution.Item2.ToString()) : substitution.Item2.ToString(); })); }
/// <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); }
/// <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(); }
/// <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 Markdown(); }
public string Invoke(string content, dynamic model, IViewEngineHost host) { var Finder = new TextResourceFinder(resource, (NancyContext)host.Context); return(ResourceRegEx.Replace( content, m => { var key = m.Groups ["Key"].Value; return Finder [key]; })); }
/// <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, }; }
/// <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, }; }
/// <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 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); }
/// <summary> /// Invokes the master page rendering with current sections if necessary /// </summary> /// <param name="template">The template.</param> /// <param name="model">The model.</param> /// <param name="host">View engine host</param> /// <returns>Template with master page applied and sections substituted</returns> private string PerformMasterPageSubstitutions(string template, object model, IViewEngineHost host) { var masterPageName = GetMasterPageName(template); if (string.IsNullOrWhiteSpace(masterPageName)) { return(template); } var masterTemplate = host.GetTemplate(masterPageName, model); var sectionMatches = SectionContentsRegEx.Matches(template); var sections = sectionMatches.Cast <Match>().ToDictionary(sectionMatch => sectionMatch.Groups["SectionName"].Value, sectionMatch => sectionMatch.Groups["SectionContents"].Value); return(this.RenderMasterPage(masterTemplate, sections, model, host)); }
//private static readonly Regex ObfuscateLinkTokenRegEx = new Regex(@"@ObfuscateLink?\.(?<PlainLink>[^;]+);?", RegexOptions.Compiled); public string Invoke(string content, dynamic model, IViewEngineHost host) { return(ObfuscateLinkTokenRegEx.Replace( content, m => { var PlainLink = m.Groups["PlainLink"].Value; if (!String.IsNullOrEmpty(PlainLink)) { return DoObfuscate(PlainLink); } else { return "[ERR]"; } })); }
/// <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 = new StringBuilder(); foreach (var item in substitutionEnumerable) { var modifiedContent = PerformPartialSubstitutions(contents, item, host); modifiedContent = PerformConditionalSubstitutions(modifiedContent, item, host); result.Append(ReplaceCurrentMatch(modifiedContent, item, host)); } return result.ToString(); })); }
public string Invoke(string content, dynamic model, IViewEngineHost host) { return(TranslationSubstitutionsRegEx.Replace( content, m => { // A match was found! // Get the translation 'key'. var translationKey = m.Groups["TranslationKey"].Value; // Load the appropriate translation. This could farm off to // a ResourceManager for example. The below implementation // obviously isn't very useful and is just illustrative. :) var translationResult = translationKey == "Hello_World" ? "Hello World!" : translationKey; return translationResult; })); }
/// <summary> /// Performs single @Model.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 @Model.PropertyName blocks expanded.</returns> private string PerformSingleSubstitutions(string template, object model, IViewEngineHost host) { return(SingleSubstitutionsRegEx.Replace( template, m => { var properties = GetCaptureGroupValues(m, "ParameterName"); var substitution = GetPropertyValueFromParameterCollection(model, 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(); })); }
/// <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 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) { result += ReplaceCurrentMatch(contents, item, host); } return result; })); }
/// <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())); }
/// <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); }
/// <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; }
/// <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; }); }
/// <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)); }
/// <summary> /// Renders a master page - does a normal render then replaces any section tags with sections passed in /// </summary> /// <param name="masterTemplate">The master page template</param> /// <param name="sections">Dictionary of section contents</param> /// <param name="model">The model.</param> /// <param name="host">View engine host</param> /// <returns>Template with the master page applied and sections substituted</returns> private string RenderMasterPage(string masterTemplate, IDictionary <string, string> sections, object model, IViewEngineHost host) { var result = this.Render(masterTemplate, model, host); result = SectionDeclarationRegEx.Replace( result, m => { var sectionName = m.Groups["SectionName"].Value; return(sections.ContainsKey(sectionName) ? sections[sectionName] : string.Empty); }); return(result); }
/// <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)); }
/// <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; }
public string Invoke(string p_Content, dynamic p_Model, IViewEngineHost p_Host) { return(p_Content.Replace("@GrooveCaster.Version", Application.GetVersion())); }
public SuperSimpleViewEngineTests() { this.fakeHost = new FakeViewEngineHost(); this.viewEngine = new SuperSimpleViewEngine(); }
/// <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 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) { result += ReplaceCurrentMatch(contents, item, host); } return result; }); }
/// <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; }
/// <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))); }
/// <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; }
/// <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(); }); }
/// <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()); }
public SuperSimpleViewEngineTests() { this.fakeHost = new FakeViewEngineHost(); this.viewEngine = new SuperSimpleViewEngine(Enumerable.Empty<ISuperSimpleViewEngineMatcher>()); }
/// <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; }
public string Invoke(string p_Content, dynamic p_Model, IViewEngineHost p_Host) { return p_Content.Replace("@GrooveCaster.Version", Application.GetVersion()); }
/// <summary> /// Expand a @Current match inside an @Each iterator /// </summary> /// <param name="contents">Contents of the @Each block</param> /// <param name="item">Current item from the @Each enumerable</param> /// <param name="host">View engine host</param> /// <returns>String result of the expansion of the @Each.</returns> private static string ReplaceCurrentMatch(string contents, object item, IViewEngineHost host) { return EachItemSubstitutionRegEx.Replace( contents, eachMatch => { if (string.IsNullOrEmpty(eachMatch.Groups["ParameterName"].Value)) { return eachMatch.Groups["Encode"].Success ? host.HtmlEncode(item.ToString()) : item.ToString(); } var properties = GetCaptureGroupValues(eachMatch, "ParameterName"); var substitution = GetPropertyValueFromParameterCollection(item, properties); if (!substitution.Item1) { return "[ERR!]"; } if (substitution.Item2 == null) { return string.Empty; } return eachMatch.Groups["Encode"].Success ? host.HtmlEncode(substitution.Item2.ToString()) : substitution.Item2.ToString(); }); }
public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext) { this.viewEngineHost = viewEngineHost; this.renderContext = renderContext; this.Context = this.renderContext.Context; }
/// <summary> /// Invokes the master page rendering with current sections if necessary /// </summary> /// <param name="template">The template.</param> /// <param name="model">The model.</param> /// <param name="host">View engine host</param> /// <returns>Template with master page applied and sections substituted</returns> private string PerformMasterPageSubstitutions(string template, object model, IViewEngineHost host) { var masterPageName = GetMasterPageName(template); if (string.IsNullOrWhiteSpace(masterPageName)) { return template; } var masterTemplate = host.GetTemplate(masterPageName, model); var sectionMatches = SectionContentsRegEx.Matches(template); var sections = sectionMatches.Cast<Match>().ToDictionary(sectionMatch => sectionMatch.Groups["SectionName"].Value, sectionMatch => sectionMatch.Groups["SectionContents"].Value); return this.RenderMasterPage(masterTemplate, sections, model, host); }
/// <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); }
/// <summary> /// Renders a master page - does a normal render then replaces any section tags with sections passed in /// </summary> /// <param name="masterTemplate">The master page template</param> /// <param name="sections">Dictionary of section contents</param> /// <param name="model">The model.</param> /// <param name="host">View engine host</param> /// <returns>Template with the master page applied and sections substituted</returns> private string RenderMasterPage(string masterTemplate, IDictionary<string, string> sections, object model, IViewEngineHost host) { var result = this.Render(masterTemplate, model, host); result = SectionDeclarationRegEx.Replace( result, m => { var sectionName = m.Groups["SectionName"].Value; return sections.ContainsKey(sectionName) ? sections[sectionName] : string.Empty; }); return result; }
/// <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); }