Exemplo n.º 1
0
        /// <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;
		}
Exemplo n.º 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;
		}
Exemplo n.º 3
0
        /// <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;
		}
Exemplo n.º 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());
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
		public void OnBeforeEachTest()
		{
			markdownFormat = new MarkdownFormat {
                VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()),
            };
		}
Exemplo n.º 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)
		{
		}