func mainHandler(w http.ResponseWriter, r *http.Request) { filter := strings.ToLower(r.FormValue("filter")) expert := r.FormValue("expert") == "on" tag := strings.ToLower(r.FormValue("tag")) l := ltxref.Ltxref{Version: latexref.Version} l.Commands = latexref.FilterCommands(filter, tag, expert) l.Packages = latexref.FilterPackages(filter, tag) l.Environments = latexref.FilterEnvironments(filter, tag, expert) l.DocumentClasses = latexref.FilterDocumentClasses(filter, tag, expert) switch strings.ToLower(r.FormValue("format")) { case "xml": str, err := l.ToXML() if err != nil { fmt.Println(err) } sendXML(w, str) return case "txt": l.ToString(w, true) return } data := struct { Filter string Tag string Edit string Expert bool L ltxref.Ltxref Tags []string XMLUrl string PlainTextUrl string }{ L: l, Filter: filter, Tag: tag, Edit: editToken(r), Expert: expert, Tags: latexref.Tags(), XMLUrl: addXMLFormatString(r.URL), PlainTextUrl: addTXTFormatString(r.URL), } err := tpl.ExecuteTemplate(w, "main.html", data) if err != nil { fmt.Println(err) } }
func environmentDetailHandler(w http.ResponseWriter, r *http.Request) { requestedEnvironment := mux.Vars(r)["environment"] filtervalue := strings.ToLower(r.FormValue("filter")) env := latexref.GetEnvironmentWithName(requestedEnvironment) if env == nil { // not found -> error // TODO return } switch strings.ToLower(r.FormValue("format")) { case "xml": l := ltxref.Ltxref{Version: latexref.Version} l.Environments = append(l.Environments, env) str, err := l.ToXML() if err != nil { fmt.Println(err) return } sendXML(w, str) return case "txt": env.ToString(w) default: backlink := &url.URL{} backlink.Path = "/" addKeyValueToUrl(backlink, "edit", r.FormValue("edit")) addKeyValueToUrl(backlink, "filter", r.FormValue("filter")) data := struct { Backlink string Filter string Edit string Environment ltxref.Environment XMLUrl string PlainTextUrl string }{ Backlink: backlink.String(), Edit: editToken(r), Filter: filtervalue, Environment: *env, XMLUrl: addXMLFormatString(r.URL), PlainTextUrl: addTXTFormatString(r.URL), } err := tpl.ExecuteTemplate(w, "envdetail", data) if err != nil { fmt.Println(err) } return } }