PopSourceFile() public méthode

Pops the source file being executed.
Cannot PopSourceFile more than PushSourceFile
public PopSourceFile ( ) : string
Résultat string
Exemple #1
0
        private object EvaluateAndRender(TemplateContext context, bool render)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            CheckErrors();

            // Make sure that we are using the same parserOptions
            if (SourceFilePath != null)
            {
                context.PushSourceFile(SourceFilePath);
            }

            try
            {
                context.UseScientific = LexerOptions.Lang == ScriptLang.Scientific;
                var result = context.Evaluate(Page);
                if (render)
                {
                    if (Page != null && context.EnableOutput && result != null)
                    {
                        context.Write(Page.Span, result);
                    }
                }
                return(result);
            }
            finally
            {
                if (SourceFilePath != null)
                {
                    context.PopSourceFile();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Evaluates the template using the specified context. See remarks.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <param name="render"><c>true</c> to render the output to the <see cref="TemplateContext.Output"/></param>
        /// <exception cref="System.ArgumentNullException">If context is null</exception>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        private object EvaluateAndRender(TemplateContext context, bool render)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            CheckErrors();

            // Make sure that we are using the same parserOptions
            if (SourceFilePath != null)
            {
                context.PushSourceFile(SourceFilePath);
            }

            try
            {
                if (Page == null || Page.Body.Statements.Count == 0)
                {
                    return(null);
                }

                if (render)
                {
                    ResolvePageLayout(context);
                }

                var result = context.Evaluate(Page);
                if (render)
                {
                    if (Page != null && context.EnableOutput && result != null)
                    {
                        context.Write(Page.Span, result);
                    }
                }
                return(result);
            }
            finally
            {
                if (SourceFilePath != null)
                {
                    context.PopSourceFile();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Evaluates the template using the specified context. See remarks.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <exception cref="System.ArgumentNullException">If context is null</exception>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        private object EvaluateAndRender(TemplateContext context, bool render)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (HasErrors)
            {
                throw new InvalidOperationException("This template has errors. Check the <Messages> property for more details");
            }

            // Make sure that we are using the same parserOptions
            if (SourceFilePath != null)
            {
                context.PushSourceFile(SourceFilePath);
            }

            try
            {
                var result = context.Evaluate(Page);
                if (render)
                {
                    if (Page != null && context.EnableOutput && result != null)
                    {
                        context.Write(Page.Span, result);
                    }
                }
                return(result);
            }
            finally
            {
                if (SourceFilePath != null)
                {
                    context.PopSourceFile();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Renders this template using the specified context. See remarks.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <exception cref="System.ArgumentNullException">If context is null</exception>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        /// <remarks>
        /// When using this method, the result of rendering this page is output to <see cref="TemplateContext.Output"/>
        /// </remarks>
        public void Render(TemplateContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (HasErrors)
            {
                throw new InvalidOperationException("This template has errors. Check the <Messages> property for more details");
            }

            // Make sure that we are using the same options
            if (SourceFilePath != null)
            {
                context.PushSourceFile(SourceFilePath);
            }

            try
            {
                context.Result = null;
                Page?.Evaluate(context);

                if (Page != null && context.EnableOutput && context.Result != null)
                {
                    context.Write(Page.Span, context.Result);
                    context.Result = null;
                }
            }
            finally
            {
                if (SourceFilePath != null)
                {
                    context.PopSourceFile();
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Renders this template using the specified context. See remarks.
        /// </summary>
        /// <param name="context">The template context.</param>
        /// <exception cref="System.ArgumentNullException">If context is null</exception>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        /// <remarks>
        /// When using this method, the result of rendering this page is output to <see cref="TemplateContext.Output"/>
        /// </remarks>
        public void Render(TemplateContext context)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));
            if (HasErrors) throw new InvalidOperationException("This template has errors. Check the <Messages> property for more details");

            // Make sure that we are using the same options
            if (SourceFilePath != null)
            {
                context.PushSourceFile(SourceFilePath);
            }

            try
            {
                context.Result = null;
                Page?.Evaluate(context);

                if (Page != null && context.EnableOutput && context.Result != null)
                {
                    context.Write(Page.Span, context.Result);
                    context.Result = null;
                }
            }
            finally
            {
                if (SourceFilePath != null)
                {
                    context.PopSourceFile();
                }
            }
        }