/// <summary>Creates a new MarkdownFormat.</summary>
        ///
        /// <param name="pageTemplate">The page template.</param>
        ///
        /// <returns>A MarkdownFormat.</returns>
		public MarkdownFormat Create(string pageTemplate)
		{
			var markdownFormat = new MarkdownFormat();
			markdownFormat.AddPage(
				new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate));

			return markdownFormat;
		}
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MarkdownPage"/> class.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="fullPath">The full path.</param>
        /// <param name="name">The name.</param>
        /// <param name="contents">The contents.</param>
        /// <param name="pageType">Type of the page.</param>
		public MarkdownPage(MarkdownFormat markdown, string fullPath, string name, string contents, MarkdownPageType pageType)
			: this()
		{
			Markdown = markdown;
			FilePath = fullPath;
			Name = name;
			Contents = contents;
			PageType = pageType;
		}
        /// <summary>Creates a new MarkdownFormat.</summary>
        ///
        /// <param name="websiteTemplate">The website template.</param>
        /// <param name="pageTemplate">   The page template.</param>
        ///
        /// <returns>A MarkdownFormat.</returns>
		public MarkdownFormat Create(string websiteTemplate, string pageTemplate)
		{
			var markdownFormat = new MarkdownFormat {
			    VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost())
            };

            markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
			markdownFormat.AddPage(
				new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate) {
                    Template = "websiteTemplate",
				});

			return markdownFormat;
		}
Exemple #4
0
        /// <summary>Registers this object.</summary>
        ///
        /// <param name="appHost">The application host.</param>
        public void Register(IAppHost appHost)
        {
            if (instance == null) instance = this;

            this.AppHost = appHost;
            appHost.ViewEngines.Add(this);

            if (!WatchForModifiedPages)
                WatchForModifiedPages = appHost.Config.DebugMode;

            foreach (var ns in EndpointHostConfig.RazorNamespaces)
                Evaluator.AddAssembly(ns);

            this.MarkdownBaseType = appHost.Config.MarkdownBaseType ?? this.MarkdownBaseType;
            this.MarkdownGlobalHelpers = appHost.Config.MarkdownGlobalHelpers ?? this.MarkdownGlobalHelpers;

            this.ReplaceTokens = appHost.Config.HtmlReplaceTokens ?? new Dictionary<string, string>();
            var webHostUrl = appHost.Config.WebHostUrl;
            if (!webHostUrl.IsNullOrEmpty())
                this.ReplaceTokens["~/"] = webHostUrl.WithTrailingSlash();

            if (VirtualPathProvider == null)
                VirtualPathProvider = AppHost.VirtualPathProvider;

            RegisterMarkdownPages(appHost.Config.WebHostPhysicalPath);

            appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => {
                MarkdownPage markdownPage = null;

                if (catchAllPathsNotFound.Contains(pathInfo))
                    return null;

                markdownPage = FindByPathInfo(pathInfo);

                if (WatchForModifiedPages)
                    ReloadModifiedPageAndTemplates(markdownPage);

                if (markdownPage == null)
                {
                    if (pathInfo.EndsWith(".md"))
                    {
                        pathInfo = pathInfo.EndsWithIgnoreCase(DefaultPage + ".md")
                            ? pathInfo.Substring(0, pathInfo.Length - (DefaultPage + ".md").Length)
                            : pathInfo.WithoutExtension();

                        return new RedirectHttpHandler {
                            AbsoluteUrl = webHostUrl.IsNullOrEmpty()
                                ? null
                                : webHostUrl.CombineWith(pathInfo),
                            RelativeUrl = webHostUrl.IsNullOrEmpty()
                                ? pathInfo
                                : null
                        };
                    }

                    if (catchAllPathsNotFound.Count > 1000) //prevent DDOS
                        catchAllPathsNotFound = new HashSet<string>();

					var tmp = new HashSet<string>(catchAllPathsNotFound) { pathInfo };
                    catchAllPathsNotFound = tmp;
					return null;
                }
                
                return new MarkdownHandler(pathInfo) {
                    MarkdownFormat = this,
                    MarkdownPage = markdownPage,
                    RequestName = "MarkdownPage"
                };
            });

            appHost.ContentTypeFilters.Register(ContentType.MarkdownText, SerializeToStream, null);
            appHost.ContentTypeFilters.Register(ContentType.PlainText, SerializeToStream, null);
            appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.MarkdownText.ToContentFormat());
            appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.PlainText.ToContentFormat());
        }
        /// <summary>Registers this object.</summary>
        ///
        /// <param name="appHost">The application host.</param>
        public void Register(IAppHost appHost)
        {
            if (instance == null)
            {
                instance = this;
            }

            this.AppHost = appHost;
            appHost.ViewEngines.Add(this);

            if (!WatchForModifiedPages)
            {
                WatchForModifiedPages = appHost.Config.DebugMode;
            }

            foreach (var ns in EndpointHostConfig.RazorNamespaces)
            {
                Evaluator.AddAssembly(ns);
            }

            this.MarkdownBaseType      = appHost.Config.MarkdownBaseType ?? this.MarkdownBaseType;
            this.MarkdownGlobalHelpers = appHost.Config.MarkdownGlobalHelpers ?? this.MarkdownGlobalHelpers;

            this.ReplaceTokens = appHost.Config.HtmlReplaceTokens ?? new Dictionary <string, string>();
            var webHostUrl = appHost.Config.WebHostUrl;

            if (!webHostUrl.IsNullOrEmpty())
            {
                this.ReplaceTokens["~/"] = webHostUrl.WithTrailingSlash();
            }

            if (VirtualPathProvider == null)
            {
                VirtualPathProvider = AppHost.VirtualPathProvider;
            }

            RegisterMarkdownPages(appHost.Config.WebHostPhysicalPath);

            appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => {
                MarkdownPage markdownPage = null;

                if (catchAllPathsNotFound.Contains(pathInfo))
                {
                    return(null);
                }

                markdownPage = FindByPathInfo(pathInfo);

                if (WatchForModifiedPages)
                {
                    ReloadModifiedPageAndTemplates(markdownPage);
                }

                if (markdownPage == null)
                {
                    if (pathInfo.EndsWith(".md"))
                    {
                        pathInfo = pathInfo.EndsWithIgnoreCase(DefaultPage + ".md")
                            ? pathInfo.Substring(0, pathInfo.Length - (DefaultPage + ".md").Length)
                            : pathInfo.WithoutExtension();

                        return(new RedirectHttpHandler {
                            AbsoluteUrl = webHostUrl.IsNullOrEmpty()
                                ? null
                                : webHostUrl.CombineWith(pathInfo),
                            RelativeUrl = webHostUrl.IsNullOrEmpty()
                                ? pathInfo
                                : null
                        });
                    }

                    if (catchAllPathsNotFound.Count > 1000) //prevent DDOS
                    {
                        catchAllPathsNotFound = new HashSet <string>();
                    }

                    var tmp = new HashSet <string>(catchAllPathsNotFound)
                    {
                        pathInfo
                    };
                    catchAllPathsNotFound = tmp;
                    return(null);
                }

                return(new MarkdownHandler(pathInfo)
                {
                    MarkdownFormat = this,
                    MarkdownPage = markdownPage,
                    RequestName = "MarkdownPage"
                });
            });

            appHost.ContentTypeFilters.Register(ContentType.MarkdownText, SerializeToStream, null);
            appHost.ContentTypeFilters.Register(ContentType.PlainText, SerializeToStream, null);
            appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.MarkdownText.ToContentFormat());
            appHost.Config.IgnoreFormatsInMetadata.Add(ContentType.PlainText.ToContentFormat());
        }
		public void OnBeforeEachTest()
		{
			markdownFormat = new MarkdownFormat {
                VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()),
            };
		}
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MarkdownPage"/> class.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="fullPath">The full path.</param>
        /// <param name="name">The name.</param>
        /// <param name="contents">The contents.</param>
		public MarkdownPage(MarkdownFormat markdown, string fullPath, string name, string contents)
			: this(markdown, fullPath, name, contents, MarkdownPageType.ViewPage)
		{
		}