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


Golang mustache.RenderString函數代碼示例

本文整理匯總了Golang中github.com/wendal/mustache.RenderString函數的典型用法代碼示例。如果您正苦於以下問題:Golang RenderString函數的具體用法?Golang RenderString怎麽用?Golang RenderString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: MakeSummary

func MakeSummary(post Mapper, lines int, topCtx mustache.Context) string {
	content := post["_content"].(*DocContent).Source
	r := bufio.NewReader(bytes.NewBufferString(content))
	dst := ""
	for lines > 0 {
		line, _ := r.ReadString('\n')
		dst += line
		lines--
		if lines == 0 {
			for "" != strings.Trim(line, "\r\n\t ") {
				line, _ = r.ReadString('\n')
				dst += line
			}
		}
	}
	str, err := mustache.RenderString(dst, topCtx)
	if err != nil {
		log.Println("BAD Mustache after Summary cut!")
		str, err = mustache.RenderString(dst, topCtx)
		if err != nil {
			log.Println("BAD Mustache Summary?", err)
			str = post["_content"].(*DocContent).Main
		}
	}
	return MarkdownToHtml(str)
}
開發者ID:JoeyFan,項目名稱:gor,代碼行數:26,代碼來源:compile.go

示例2: MakeSummary

func MakeSummary(post Mapper, lines int, topCtx mustache.Context) string {
	content := post["_content"].(*DocContent).Source
	r := bufio.NewReader(bytes.NewBufferString(content))
	dst := ""
	for lines > 0 {
		line, _ := r.ReadString('\n')
		dst += line
		lines--
		if lines == 0 {
			for "" != strings.Trim(line, "\r\n\t ") {
				line, _ = r.ReadString('\n')
				dst += line
			}
		}
	}
	str, err := mustache.RenderString(dst, topCtx)
	if err != nil {
		log.Println("BAD Mustache after Summary cut!")
		str, err = mustache.RenderString(dst, topCtx)
		if err != nil {
			log.Println("BAD Mustache Summary?", err)
			str = post["_content"].(*DocContent).Main
		}
	}
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	buf := bytes.NewBuffer(nil)
	mdParser.Markdown(bytes.NewBufferString(str), markdown.ToHTML(buf))
	return buf.String()
}
開發者ID:yemaocheng,項目名稱:gor,代碼行數:29,代碼來源:compile.go

示例3: PrapreMainContent

func PrapreMainContent(id string, content string, ctx mustache.Context) (string, error) {
	//mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	str, err := mustache.RenderString(content, ctx)
	if err != nil {
		return str, err
	}
	if strings.HasSuffix(id, ".md") || strings.HasSuffix(id, ".markdown") {
		//log.Println("R: MD : " + id)
		str = MarkdownToHtml(str)
	}
	return str, nil
}
開發者ID:JoeyFan,項目名稱:gor,代碼行數:12,代碼來源:compile.go

示例4: PrapreMainContent

func PrapreMainContent(id string, content string, ctx mustache.Context) (string, error) {
	str, err := mustache.RenderString(content, ctx)
	if err != nil {
		Log(INFO, "Error when parse %s", id)
		return str, err
	}
	if strings.HasSuffix(id, ".md") || strings.HasSuffix(id, ".markdown") {
		Log(DEBUG, "Read markdown: %s", id)
		str = MarkdownToHtml(str)
	}
	return str, nil
}
開發者ID:newblue,項目名稱:neyo,代碼行數:12,代碼來源:compile.go

示例5: MakeSummary

func MakeSummary(post Mapper, lines int, topCtx mustache.Context) string {
	content := post["_content"].(*DocContent).Source
	r := bufio.NewReader(bytes.NewBufferString(content))
	dst := ""
	readUntil := ""
	for lines > 0 {
		line, _ := r.ReadString('\n')
		dst += line
		lines--
		if strings.Trim(line, "\r\n\t ") == "```" {
			if readUntil == "" {
				readUntil = "```"
			} else {
				readUntil = ""
			}
		}
		if lines == 0 {
			var err error
			for readUntil != strings.Trim(line, "\r\n\t ") {
				line, err = r.ReadString('\n')
				dst += line
				if err != nil {
					break
				}
			}
		}
	}
	str, err := mustache.RenderString(dst, topCtx)
	if err != nil {
		log.Println("BAD Mustache after Summary cut!")
		str, err = mustache.RenderString(dst, topCtx)
		if err != nil {
			log.Println("BAD Mustache Summary?", err)
			str = post["_content"].(*DocContent).Main
		}
	}
	str = strings.Replace(str, TOC_MARKUP, "", 1)
	return MarkdownToHtml(str)
}
開發者ID:29n,項目名稱:gor,代碼行數:39,代碼來源:compile.go

示例6: PrapreMainContent

func PrapreMainContent(id string, content string, ctx mustache.Context) (string, error) {
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	str, err := mustache.RenderString(content, ctx)
	if err != nil {
		return str, err
	}
	if strings.HasSuffix(id, ".md") || strings.HasSuffix(id, ".markdown") {
		//log.Println("R: MD : " + id)
		buf := bytes.NewBuffer(nil)
		mdParser.Markdown(bytes.NewBufferString(str), markdown.ToHTML(buf))
		str = buf.String()
	}
	return str, nil
}
開發者ID:yemaocheng,項目名稱:gor,代碼行數:14,代碼來源:compile.go

示例7: RenderInLayout

func RenderInLayout(content string, layoutName string, layouts map[string]Mapper, ctx mustache.Context) (string, error) {
	//log.Println("Render Layout", layoutName, ">>", content, "<<END")
	ctx2 := make(map[string]string)
	ctx2["content"] = content
	layout := layouts[layoutName]
	str, err := mustache.RenderString(layout["_content"].(*DocContent).Source, ctx2, ctx)
	if err != nil {
		return content, err
	}
	if layout.Layout() != "" {
		return RenderInLayout(str, layout.Layout(), layouts, ctx)
	}
	return str, nil
}
開發者ID:yemaocheng,項目名稱:gor,代碼行數:14,代碼來源:compile.go


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