Beispiel #1
0
func (a *Admin) initTemplates(app *prago.App) error {
	templates := app.Data()["templates"].(*template.Template)
	if templates == nil {
		return errors.New("Templates not initialized")
	}

	app.AddTemplateFunction("tmpl", func(templateName string, x interface{}) (template.HTML, error) {
		var buf bytes.Buffer
		err := templates.ExecuteTemplate(&buf, templateName, x)
		return template.HTML(buf.String()), err
	})

	app.AddTemplateFunction("markdown", func(text string) template.HTML {
		return template.HTML(markdown.New(markdown.Breaks(true)).RenderToString([]byte(text)))
	})

	app.AddTemplateFunction("message", func(language, id string) template.HTML {
		return template.HTML(messages.Messages.Get(language, id))
	})

	app.AddTemplateFunction("thumb", func(ids string) string {
		for _, v := range strings.Split(ids, ",") {
			var image File
			err := a.Query().WhereIs("uid", v).Get(&image)
			if err == nil && image.isImage() {
				return image.GetSmall()
			}
		}
		return ""
	})

	return nil
}
Beispiel #2
0
func bindMarkdownAPI(a *Admin) {
	a.AdminController.Post(a.Prefix+"/_api/markdown", func(request prago.Request) {
		data, err := ioutil.ReadAll(request.Request().Body)
		if err != nil {
			panic(err)
		}
		prago.WriteAPI(request, markdown.New().RenderToString(data), 200)
	})
}
Beispiel #3
0
// Reader returns all documentation as a single page.
func Reader() io.Reader {
	var in bytes.Buffer

	for _, page := range pages {
		in.WriteString(fmt.Sprintf("\n# %s\n", page.Name))
		in.Write(MustAsset(page.File))
	}

	md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true))
	v := &renderer{}
	s := v.visit(md.Parse(in.Bytes()))
	return strings.NewReader(s)
}