Beispiel #1
0
        public void Prepare()
        {
            if (!typeof(MarkdownViewBase).IsAssignableFrom(this.Markdown.MarkdownBaseType))
            {
                throw new ConfigurationErrorsException(
                          "Config.MarkdownBaseType must inherit from MarkdownViewBase");
            }

            if (this.Contents.IsNullOrEmpty())
            {
                return;
            }

            foreach (var markdownReplaceToken in Markdown.MarkdownReplaceTokens)
            {
                this.Contents = this.Contents.Replace(markdownReplaceToken.Key, markdownReplaceToken.Value);
            }

            var markdownStatements = new List <StatementExprBlock>();

            var markdownContents = StatementExprBlock.Extract(this.Contents, markdownStatements);

            this.MarkdownBlocks = markdownContents.CreateTemplateBlocks(markdownStatements).ToArray();

            var htmlStatements = new List <StatementExprBlock>();
            var htmlContents   = StatementExprBlock.Extract(this.Contents, htmlStatements);

            this.HtmlContents = Markdown.Transform(htmlContents);
            this.HtmlBlocks   = this.HtmlContents.CreateTemplateBlocks(htmlStatements).ToArray();

            SetTemplateDirectivePath();
        }
Beispiel #2
0
        public void Compile(bool force = false)
        {
            if (this.IsCompiled && !force)
            {
                return;
            }

            var sw = Stopwatch.StartNew();

            try
            {
                if (!typeof(MarkdownViewBase).IsAssignableFrom(this.Markdown.MarkdownBaseType))
                {
                    throw new ConfigurationErrorsException(
                              "Config.MarkdownBaseType must inherit from MarkdownViewBase");
                }

                if (this.Contents.IsNullOrEmpty())
                {
                    return;
                }

                var markdownStatements = new List <StatementExprBlock>();

                var markdownContents = StatementExprBlock.Extract(this.Contents, markdownStatements);

                this.MarkdownBlocks = markdownContents.CreateTemplateBlocks(markdownStatements).ToArray();

                var htmlStatements = new List <StatementExprBlock>();
                var htmlContents   = StatementExprBlock.Extract(this.Contents, htmlStatements);

                this.HtmlContents = Markdown.Transform(htmlContents);
                this.HtmlBlocks   = this.HtmlContents.CreateTemplateBlocks(htmlStatements).ToArray();

                SetTemplateDirectivePath();

                this.IsCompiled = true;
                Log.InfoFormat("Compiled {0} in {1}ms", this.FilePath, sw.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                Log.Error("Error compiling {0}".Fmt(this.FilePath), ex);
                throw;
            }
        }