Ejemplo n.º 1
0
        public TemplateAST Parse(string path)
        {
            string templateFile = Path.Combine(_engine.Path, path);

            _log.Debug("Begin parse template file [{0}].", templateFile);

            if (!File.Exists(templateFile))
            {
                ExceptionHelper.ThrowFileNotFound(templateFile);
            }

            using (StreamReader r = new StreamReader(templateFile))
            {
                string        template = r.ReadToEnd();
                LexicalParser lp       = new LexicalParser();
                lp.SetParseContent(template);
                SemanticParser sp = new SemanticParser();
                sp.SetParseContent(lp.Parse());
                TemplateAST ast = sp.Parse();

                _log.Debug("Parse template file [{0}] success.", templateFile);

                ParseIncludeTemplate(ast);
                return(ast);
            }
        }
Ejemplo n.º 2
0
        public string RenderRaw(string textTemplate)
        {
            textTemplate.ThrowIfNullArgument(nameof(textTemplate));

            try
            {
                LexicalParser lp = new LexicalParser();
                lp.SetParseContent(textTemplate);
                SemanticParser sp = new SemanticParser();
                sp.SetParseContent(lp.Parse());
                TemplateAST ast = sp.Parse();

                return(this.Render(ast));
            }
            catch (ELParseException)
            {
                throw;
            }
            catch (EvalException)
            {
                throw;
            }
            catch (TemplateParseException)
            {
                throw;
            }
            catch (TemplateRenderException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowWrapped(ex);
                return(string.Empty);
            }
        }