// Shows the sponsor slides configuration page.
func SponsorSlidesGetHandler(w http.ResponseWriter, r *http.Request) {
	if !UserIsAdmin(w, r) {
		return
	}

	template, err := template.ParseFiles("templates/setup_sponsor_slides.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	sponsorSlides, err := db.GetAllSponsorSlides()
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		SponsorSlides []SponsorSlide
	}{eventSettings, sponsorSlides}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #2
0
func (h *HTMLRedirectAlias) Publish(path string, permalink string, page interface{}) (err error) {
	if path, err = h.Translate(path); err != nil {
		jww.ERROR.Printf("%s, skipping.", err)
		return nil
	}

	t := "alias"
	if strings.HasSuffix(path, ".xhtml") {
		t = "alias-xhtml"
	}

	template := defaultAliasTemplates
	if h.Templates != nil {
		template = h.Templates
		t = "alias.html"
	}

	buffer := new(bytes.Buffer)
	err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink, page})
	if err != nil {
		return
	}

	return helpers.WriteToDisk(path, buffer, hugofs.Destination())
}
Beispiel #3
0
func defaultFormatFunc(h http.HTTP) http.Formatter {

	var bt []byte
	var err error

	hc := h.(*HipChat)
	b := new(bytes.Buffer)
	template := hc.Template()

	body := new(Body)
	body.Notify = true

	return func(e *log.Entry) []byte {

		bt = bt[0:0]
		b.Reset()
		body.From = e.ApplicationID
		body.Color = hc.GetDisplayColor(e.Level)

		if err = template.ExecuteTemplate(b, "hipchat", e); err != nil {
			log.WithFields(log.F("error", err)).Error("Error parsing HipChat handler template")
		}

		body.Message = b.String()

		// shouldn't be possible to fail here
		// at least with the default handler...
		bt, _ = json.Marshal(body)

		return bt
	}
}
// Shows the lower third configuration page.
func LowerThirdsGetHandler(w http.ResponseWriter, r *http.Request) {
	if !UserIsAdmin(w, r) {
		return
	}

	template, err := template.ParseFiles("templates/setup_lower_thirds.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	lowerThirds, err := db.GetAllLowerThirds()
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		LowerThirds []LowerThird
	}{eventSettings, lowerThirds}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #5
0
// Shows the page to edit a team's fields.
func TeamEditGetHandler(w http.ResponseWriter, r *http.Request) {
	if !UserIsAdmin(w, r) {
		return
	}

	vars := mux.Vars(r)
	teamId, _ := strconv.Atoi(vars["id"])
	team, err := db.GetTeamById(teamId)
	if err != nil {
		handleWebErr(w, err)
		return
	}
	if team == nil {
		http.Error(w, fmt.Sprintf("Error: No such team: %d", teamId), 400)
		return
	}

	template, err := template.ParseFiles("templates/edit_team.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		*Team
	}{eventSettings, team}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
func renderSchedule(w http.ResponseWriter, r *http.Request, errorMessage string) {
	teams, err := db.GetAllTeams()
	if err != nil {
		handleWebErr(w, err)
		return
	}
	template, err := template.ParseFiles("templates/setup_schedule.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		MatchType        string
		ScheduleBlocks   []ScheduleBlock
		NumTeams         int
		Matches          []Match
		TeamFirstMatches map[int]string
		ErrorMessage     string
	}{eventSettings, cachedMatchType, cachedScheduleBlocks, len(teams), cachedMatches, cachedTeamFirstMatches,
		errorMessage}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #7
0
func defaultFormatFunc(email *Email) Formatter {
	var err error
	b := new(bytes.Buffer)

	// apparently there is a race condition when I was using
	// email.to... below in the SetHeader for whatever reason
	// so copying the "to" values solves the issue
	// I wonder if it's a flase positive in the race detector.....
	to := make([]string, len(email.to), len(email.to))
	copy(to, email.to)

	template := email.Template()
	message := gomail.NewMessage()

	message.SetHeader("From", email.from)
	message.SetHeader("To", to...)

	return func(e *log.Entry) *gomail.Message {
		b.Reset()
		if err = template.ExecuteTemplate(b, "email", e); err != nil {
			log.WithFields(log.F("error", err)).Error("Error parsing Email handler template")
		}

		message.SetHeader("Subject", e.Message)
		message.SetBody(contentType, b.String())

		return message
	}
}
Beispiel #8
0
func statusResponse(res http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(res, "<!doctype html>\n")
	fmt.Fprintf(res, "<html>\n")
	fmt.Fprintf(res, "<body>\n")

	lockfile := getLockfile()

	switch req.Method {
	case "POST":
		switch req.PostFormValue("operation") {
		case "lock":
			if lockfile.IsLocked {
				fmt.Fprintf(res, "cannot lock, sorry<br>\n")
			} else {
				locker := req.PostFormValue("locker")
				if isValidLocker(locker) {
					lockfile.IsLocked = true
					lockfile.HeldBy = req.PostFormValue("locker")
					lockfile.ModificationTime = currentTimeString()
					writeLockfile(lockfile)
				} else {
					fmt.Fprintf(res, "you have terrible taste in names<br>\n")
				}
			}
		case "release":
			lockfile.IsLocked = false
			lockfile.ModificationTime = currentTimeString()
			writeLockfile(lockfile)
		}
	}

	template, err := template.New("locked_greeting").Parse(
		`{{define "LockStatusPage"}}
			{{if .IsLocked}}
				<b>{{.HeldBy}}</b> has the lock since <b>{{.ModificationTime}}</b><br>
				<form method='POST'>
					<input type='hidden' name='operation' value='release'>
					<input type='submit' value='release lock'>
				</form>
			{{else}}
				unlocked right now, since <b>{{.ModificationTime}}</b><br>
				<form method='POST'>
					<input type='hidden' name='operation' value='lock'>
					<input type='text' name='locker' placeholder='My Glorious Name'>
					<input type='submit' value='grab lock'>
				</form>
			{{end}}
		{{end}}`)
	if err != nil {
		panic(err)
	}
	if err := template.ExecuteTemplate(res, "LockStatusPage", lockfile); err != nil {
		panic(err)
	}
	fmt.Fprintf(res, "</body>\n")
	fmt.Fprintf(res, "</html>\n")
}
Beispiel #9
0
func (site Site) writeIndex() {
	indexFile := fmt.Sprintf("%s/index.html", site.OutputPath)

	template := template.Must(template.ParseFiles("templates/index.html", "templates/base.html"))

	file, err := os.Create(indexFile)
	if err != nil {
		log.Panic(err)
	}
	template.ExecuteTemplate(file, "base", site)
}
Beispiel #10
0
func (site Site) writeArticle(article parser.ParsedFile) {
	filePath := fmt.Sprintf("%s/%s.html", site.OutputPath, article.Slug)

	template := template.Must(template.ParseFiles("templates/article.html", "templates/base.html"))

	file, err := os.Create(filePath)
	if err != nil {
		log.Panic(err)
	}
	site.Article = article
	template.ExecuteTemplate(file, "base", site)
}
Beispiel #11
0
func renderSettings(w http.ResponseWriter, r *http.Request, errorMessage string) {
	template, err := template.ParseFiles("templates/setup_settings.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		ErrorMessage string
	}{eventSettings, errorMessage}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #12
0
func (tm *TemplateManager) Render(templateName string, data interface{}) (string, error) {
	template, ok := tm.templates[templateName]
	if !ok {
		return "", errors.New("Template '" + templateName + "' does not exist.")
	}

	buf := tm.bufpool.Get()
	defer tm.bufpool.Put(buf)

	err := template.ExecuteTemplate(buf, "root", data)
	if err != nil {
		return "", err
	}

	return buf.String(), nil
}
// Shows the field configuration page.
func FieldGetHandler(w http.ResponseWriter, r *http.Request) {
	template, err := template.ParseFiles("templates/setup_field.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		AllianceStationDisplays map[string]string
		LightsMode              string
	}{eventSettings, mainArena.allianceStationDisplays, mainArena.lights.currentMode}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
func main() {

	// definiujemy templatki które mają dziedziczyć z base.html
	// parse files weżmie pod uwagę przekazane parametry
	templates := templateMap{
		"index.html": template.Must(template.ParseFiles("view/index.html", "view/base.html")),
		"other.html": template.Must(template.ParseFiles("view/other.html", "view/base.html")),
	}

	// przekazujemy trochę danych do template'a
	// cała mapa będzie dostępna jako "."
	data := map[string]string{"name": "John"}

	// renderujemy templatki
	for _, template := range templates {
		template.ExecuteTemplate(os.Stdout, "base", data)
	}
}
Beispiel #15
0
func (site Site) writePage(page parser.ParsedFile) {
	// First of all create the pages/ folder if it doesn't exist
	pagesPath := fmt.Sprintf("%s/pages", site.OutputPath)
	if _, err := os.Stat(pagesPath); os.IsNotExist(err) {
		os.Mkdir(pagesPath, 0777)
	}

	filePath := fmt.Sprintf("%s/%s.html", pagesPath, page.Slug)

	template := template.Must(template.ParseFiles("templates/page.html", "templates/base.html"))

	file, err := os.Create(filePath)
	if err != nil {
		log.Panic(err)
	}
	site.Page = page
	template.ExecuteTemplate(file, "base", site)
}
Beispiel #16
0
func (this *OrderController) Get() {
	w := this.ResponseWriter
	r := this.Request
	skill := r.FormValue("skill")
	// common := CommonController{HTTP: this.HTTP}
	// common.ShowPage("", "Order.add.tpl")
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	log.Println(cookie.UserId)
	if cookie.UserId == nil { //没有登录,则跳转到登录界面
		http.Redirect(w, r, "/login", http.StatusSeeOther)
	} else {
		t, err := t.ParseFiles("views/Order.add.tpl")
		if err != nil {
			log.Println(err)
		}
		t.ExecuteTemplate(w, "orderAdd", skill)
	}
}
func renderAllianceSelection(w http.ResponseWriter, r *http.Request, errorMessage string) {
	template, err := template.ParseFiles("templates/setup_alliance_selection.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	nextRow, nextCol := determineNextCell()
	data := struct {
		*EventSettings
		Alliances    [][]*AllianceTeam
		RankedTeams  []*RankedTeam
		NextRow      int
		NextCol      int
		ErrorMessage string
	}{eventSettings, cachedAlliances, cachedRankedTeams, nextRow, nextCol, errorMessage}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #18
0
func renderTeams(w http.ResponseWriter, r *http.Request, showErrorMessage bool) {
	teams, err := db.GetAllTeams()
	if err != nil {
		handleWebErr(w, err)
		return
	}

	template, err := template.ParseFiles("templates/setup_teams.html", "templates/base.html")
	if err != nil {
		handleWebErr(w, err)
		return
	}
	data := struct {
		*EventSettings
		Teams            []Team
		ShowErrorMessage bool
	}{eventSettings, teams, showErrorMessage}
	err = template.ExecuteTemplate(w, "base", data)
	if err != nil {
		handleWebErr(w, err)
		return
	}
}
Beispiel #19
0
func (h *HTMLRedirectAlias) Publish(path string, permalink template.HTML) (err error) {
	if path, err = h.Translate(path); err != nil {
		return
	}

	t := "alias"
	if strings.HasSuffix(path, ".xhtml") {
		t = "alias-xhtml"
	}

	template := DefaultAliasTemplates
	if h.Templates != nil {
		template = h.Templates
	}

	buffer := new(bytes.Buffer)
	err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink})
	if err != nil {
		return
	}

	return helpers.WriteToDisk(path, buffer, hugofs.DestinationFS)
}