コード例 #1
0
        /// <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);
        }
コード例 #2
0
    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;
        }));
    }
コード例 #3
0
    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;
        }));
    }
コード例 #4
0
 public MarkdownViewEngineHost(IViewEngineHost viewEngineHost, IRenderContext renderContext)
 {
     this.viewEngineHost = viewEngineHost;
     this.renderContext = renderContext;
     this.Context = this.renderContext.Context;
     this.parser = new MarkdownSharp.Markdown();
 }
コード例 #5
0
        /// <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)));
        }
コード例 #6
0
        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]";
                }
            }));
        }
コード例 #7
0
        /// <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();
            }));
        }
コード例 #8
0
        /// <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
0
 /// <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();
 }
コード例 #11
0
        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];
            }));
        }
コード例 #12
0
        /// <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,
                };
        }
コード例 #13
0
        /// <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,
            };
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        /// <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]";
                }
            }));
        }
コード例 #17
0
        /// <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();
            }));
        }
コード例 #18
0
        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;
            }));
        }
コード例 #19
0
        /// <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();
            }));
        }
コード例 #20
0
        /// <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;
            }));
        }
コード例 #21
0
 /// <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()));
 }
コード例 #22
0
        /// <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);
        }
コード例 #23
0
        /// <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;
        }
コード例 #24
0
        /// <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;
                });
        }
コード例 #25
0
 /// <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));
 }
コード例 #26
0
        /// <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);
        }
コード例 #27
0
        /// <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));
        }
コード例 #28
0
        /// <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;
        }
コード例 #29
0
 public string Invoke(string p_Content, dynamic p_Model, IViewEngineHost p_Host)
 {
     return(p_Content.Replace("@GrooveCaster.Version", Application.GetVersion()));
 }
コード例 #30
0
 public SuperSimpleViewEngineTests()
 {
     this.fakeHost   = new FakeViewEngineHost();
     this.viewEngine = new SuperSimpleViewEngine();
 }
コード例 #31
0
        /// <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;
                });
        }
コード例 #32
0
        /// <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;
        }
コード例 #33
0
 /// <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)));
 }
コード例 #34
0
        /// <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;
        }
コード例 #35
0
 public SuperSimpleViewEngineTests()
 {
     this.fakeHost = new FakeViewEngineHost();
     this.viewEngine = new SuperSimpleViewEngine();
 }
コード例 #36
0
        /// <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();
                });
        }
コード例 #37
0
 /// <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());
 }
コード例 #38
0
 public SuperSimpleViewEngineTests()
 {
     this.fakeHost = new FakeViewEngineHost();
     this.viewEngine = new SuperSimpleViewEngine(Enumerable.Empty<ISuperSimpleViewEngineMatcher>());
 }
コード例 #39
0
        /// <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;
        }
コード例 #40
0
 public string Invoke(string p_Content, dynamic p_Model, IViewEngineHost p_Host)
 {
     return p_Content.Replace("@GrooveCaster.Version", Application.GetVersion());
 }
コード例 #41
0
        /// <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;
 }
コード例 #43
0
        /// <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);
        }
コード例 #44
0
        /// <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);
        }
コード例 #45
0
        /// <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;
        }
コード例 #46
0
        /// <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);
        }