Beispiel #1
0
func renderUserPage(w http.ResponseWriter, r *http.Request, userKey string) {

	c := appengine.NewContext(r)
	q := datastore.NewQuery("User").Filter("UserKey = ", userKey)
	var us []User
	_, err := q.GetAll(c, &us)
	if err != nil {
		errorPage(w, "InternalServerError", "User Error", "", 500)
		return
	}
	if len(us) == 0 {
		errorPage(w, "NotFound", "User NotFound", "", 404)
		return
	}
	var hs []Html
	qh := datastore.NewQuery("Html").Filter("UserKey = ", userKey)
	keys, err := qh.GetAll(c, &hs)
	if err != nil {
		errorPage(w, "InternalServerError", "Html Error", "", 500)
		return
	}
	if len(hs) == 0 {
		errorPage(w, "NotFound", "User NotFound", "", 404)
		return
	}

	u := us[0]

	slideTxt := ""
	slideTxt = addLine(slideTxt, u.Name+" Slides", "")
	slideTxt = addLine(slideTxt, "golang,GoPreEdit", "Tags:")
	slideTxt += "\n"

	slideTxt = addLine(slideTxt, u.Name, "")
	slideTxt = addLine(slideTxt, u.Job, "")
	slideTxt = addLine(slideTxt, u.Url, "")
	slideTxt = addLine(slideTxt, u.TwitterId, "@")

	slideTxt += "\n"

	for idx, elm := range hs {
		slideTxt = addLine(slideTxt, "* "+elm.Title, "")
		slideTxt = addLine(slideTxt, ".link ../"+keys[idx].StringID()+" "+elm.Title, "")
		slideTxt += "\n"
	}
	data := Who{
		author:  userKey,
		request: r,
	}

	ctx := present.Context{ReadFile: data.AttributeFile}
	reader := strings.NewReader(slideTxt)
	doc, err := ctx.Parse(reader, "tour.slide", 0)
	if err != nil {
		errorPage(w, "InternalServerError", "Parse", "", 500)
		return
	}

	tmpl, err := createTemplate()
	if err != nil {
		errorPage(w, "InternalServerError", "create template error", "", 500)
		return
	}

	if u.LastWord == "" {
		u.LastWord = "Thank you"
	}

	rtn := struct {
		*present.Doc
		Template    *template.Template
		PlayEnabled bool
		LastWord    string
	}{doc, tmpl, true, u.LastWord}

	err = tmpl.ExecuteTemplate(w, "root", rtn)
	if err != nil {
		errorPage(w, "InternalServerError", "execute template error", "", 500)
	}
}
Beispiel #2
0
func createSlide(u *User, s *Slide, w *Who) ([]byte, error) {

	//c := appengine.NewContext(w.request)

	// create space data
	slideTxt := ""
	slideTxt = addLine(slideTxt, s.Title, "")
	slideTxt = addLine(slideTxt, s.SubTitle, "")
	slideTxt = addLine(slideTxt, s.SpeakDate, "")
	slideTxt = addLine(slideTxt, s.Tags, "Tags:")
	slideTxt += "\n"

	slideTxt = addLine(slideTxt, u.Name, "")
	slideTxt = addLine(slideTxt, u.Job, "")
	slideTxt = addLine(slideTxt, u.Url, "")
	slideTxt = addLine(slideTxt, u.TwitterId, "@")

	slideTxt += "\n"
	slideTxt += s.Markdown

	//
	//Golang Present Tools Editor
	//15 Aug 2015
	//Tags: golang shizuoka_go
	//
	//secondarykey
	//Programer
	//http://github.com/shizuokago/52md
	//@secondarykey
	//
	//* This Service Alpha

	ctx := present.Context{ReadFile: w.AttributeFile}
	reader := strings.NewReader(slideTxt)
	doc, err := ctx.Parse(reader, "tour.slide", 0)
	if err != nil {
		return nil, err
	}

	tmpl, err := createTemplate()
	if err != nil {
		return nil, err
	}

	if u.LastWord == "" {
		u.LastWord = "Thank you"
	}

	rtn := struct {
		*present.Doc
		Template    *template.Template
		PlayEnabled bool
		LastWord    string
	}{doc, tmpl, true, u.LastWord}

	var b bytes.Buffer
	writer := bufio.NewWriter(&b)
	err = tmpl.ExecuteTemplate(writer, "root", rtn)
	if err != nil {
		return nil, err
	}
	writer.Flush()

	return b.Bytes(), nil
}