예제 #1
0
파일: builtin.go 프로젝트: adriamb/gopad
func doGETBuiltin(c *gin.Context) {

	id := normalize(c.Param("id"))

	var content string

	tbox, err := rice.FindBox("builtin")
	if err == nil {
		content = tbox.MustString(id + ".md")
	} else {
		bytes, err := ioutil.ReadFile("web/builtin/" + id + ".md")
		if err == nil {
			content = string(bytes)
		}
	}

	if err != nil {
		dumpError(c, err)
		return
	}

	err = nil
	c.HTML(http.StatusOK, "builtin.tmpl", gin.H{
		"htmlHeaders": render.HTMLHeaders(),
		"content":     content,
		"error":       err,
	})
}
예제 #2
0
파일: entries.go 프로젝트: adriamb/gopad
func doGETEntries(c *gin.Context) {

	var entries []*model.Entry
	var err error

	ws := normalize(c.Param("ws"))
	id := normalize(c.Param("id"))

	if id != "" {

		var entry *model.Entry

		entry, err = instance.Srv.Store.Entry.GetEntry(ws, id, "")

		if err == nil {
			entries = append(entries, entry)
		}

	} else {

		entries, err = instance.Srv.Store.Entry.ListEntries(ws)

	}

	if err != nil {
		dumpError(c, err)
		return
	}

	htmlEntries := []tmplEntry{}
	for _, entry := range entries {
		htmlEntries = append(htmlEntries, tmplEntry{entry})
	}

	err = nil
	c.HTML(http.StatusOK, "entries.tmpl", gin.H{
		"htmlHeaders": render.HTMLHeaders(),
		"entries":     htmlEntries,
		"ws":          ws,
		"error":       err,
	})
}
예제 #3
0
파일: entry.go 프로젝트: adriamb/gopad
func doGETEntryEdit(c *gin.Context) {

	ws := normalize(c.Param("ws"))
	id := normalize(c.Param("id"))

	var entry *model.Entry
	var err error
	var editable = true
	versions := []Version{}

	if id != "new" {

		if strings.Contains(id, ".") {

			split := strings.SplitN(id, ".", 2)
			id = split[0]
			version := split[1]
			entry, err = instance.Srv.Store.Entry.GetEntry(ws, id, version)
			editable = false

		} else {

			entry, err = instance.Srv.Store.Entry.GetEntry(ws, id, "")

		}

		if err == nil {

			versions = append(versions, Version{
				Description: "Last",
				URL:         "/w/" + ws + "/e/" + id + "/edit",
			})

			var versionids []string
			versionids, err = instance.Srv.Store.Entry.GetEntryVersions(ws, id)
			sort.Sort(sort.Reverse(sort.StringSlice(versionids)))

			if len(versionids) > 15 {
				versionids = versionids[:15]
			}

			for _, versionid := range versionids {
				t, timeerr := time.Parse(store.DateTimeFormat, versionid)

				if timeerr == nil {
					versions = append(versions, Version{
						Description: t.Format(versionDateTimeDisplay),
						URL:         "/w/" + ws + "/e/" + id + "." + versionid + "/edit",
					})
				}
			}
		}

		if err != nil {
			dumpError(c, err)
			return
		}

	} else {

		entry = &model.Entry{
			ID:       instance.Srv.Store.Entry.NewID(),
			Markdown: "# Title\n",
		}

	}

	c.HTML(http.StatusOK, "entry.tmpl", gin.H{
		"htmlHeaders": render.HTMLHeaders(),
		"ws":          ws,
		"entry":       entry,
		"editable":    editable,
		"versions":    versions,
	})

}