當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Config.PathScope方法代碼示例

本文整理匯總了Golang中github.com/mholt/caddy/middleware/markdown.Config.PathScope方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.PathScope方法的具體用法?Golang Config.PathScope怎麽用?Golang Config.PathScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mholt/caddy/middleware/markdown.Config的用法示例。


在下文中一共展示了Config.PathScope方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: markdownParse

func markdownParse(c *Controller) ([]markdown.Config, error) {
	var mdconfigs []markdown.Config

	for c.Next() {
		md := markdown.Config{
			Renderer:    blackfriday.HtmlRenderer(0, "", ""),
			Templates:   make(map[string]string),
			StaticFiles: make(map[string]string),
		}

		// Get the path scope
		if !c.NextArg() || c.Val() == "{" {
			return mdconfigs, c.ArgErr()
		}
		md.PathScope = c.Val()

		// Load any other configuration parameters
		for c.NextBlock() {
			switch c.Val() {
			case "ext":
				exts := c.RemainingArgs()
				if len(exts) == 0 {
					return mdconfigs, c.ArgErr()
				}
				md.Extensions = append(md.Extensions, exts...)
			case "css":
				if !c.NextArg() {
					return mdconfigs, c.ArgErr()
				}
				md.Styles = append(md.Styles, c.Val())
			case "js":
				if !c.NextArg() {
					return mdconfigs, c.ArgErr()
				}
				md.Scripts = append(md.Scripts, c.Val())
			case "template":
				tArgs := c.RemainingArgs()
				switch len(tArgs) {
				case 0:
					return mdconfigs, c.ArgErr()
				case 1:
					if _, ok := md.Templates[markdown.DefaultTemplate]; ok {
						return mdconfigs, c.Err("only one default template is allowed, use alias.")
					}
					fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[0])
					md.Templates[markdown.DefaultTemplate] = fpath
				case 2:
					fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[1])
					md.Templates[tArgs[0]] = fpath
				default:
					return mdconfigs, c.ArgErr()
				}
			case "sitegen":
				if c.NextArg() {
					md.StaticDir = path.Join(c.Root, c.Val())
				} else {
					md.StaticDir = path.Join(c.Root, markdown.DefaultStaticDir)
				}
				if c.NextArg() {
					// only 1 argument allowed
					return mdconfigs, c.ArgErr()
				}
			default:
				return mdconfigs, c.Err("Expected valid markdown configuration property")
			}
		}

		// If no extensions were specified, assume .md
		if len(md.Extensions) == 0 {
			md.Extensions = []string{".md"}
		}

		mdconfigs = append(mdconfigs, md)
	}

	return mdconfigs, nil
}
開發者ID:bigtiger,項目名稱:caddy,代碼行數:77,代碼來源:markdown.go


注:本文中的github.com/mholt/caddy/middleware/markdown.Config.PathScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。