示例#1
0
文件: http.go 项目: speedata/ltxdoc
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)
	}
}
示例#2
0
文件: http.go 项目: speedata/ltxdoc
func commandDetailHandler(w http.ResponseWriter, r *http.Request) {
	requestedCommand := mux.Vars(r)["command"]
	requestedPackage := mux.Vars(r)["package"]
	filtervalue := strings.ToLower(r.FormValue("filter"))

	cmd := latexref.GetCommandFromPackage(requestedCommand, requestedPackage)

	switch strings.ToLower(r.FormValue("format")) {
	case "xml":
		l := ltxref.Ltxref{Version: latexref.Version}
		l.Commands = append(l.Commands, cmd)
		str, err := l.ToXML()
		if err != nil {
			fmt.Println(err)
			return
		}
		sendXML(w, str)
		return
	case "txt":
		cmd.ToString(w)
		return
	default:
		backlink := &url.URL{}
		if requestedPackage == "" {
			backlink.Path = "/"
		} else {
			backlink.Path = "/pkg/" + requestedPackage
		}
		addKeyValueToUrl(backlink, "edit", r.FormValue("edit"))
		addKeyValueToUrl(backlink, "filter", r.FormValue("filter"))

		if cmd != nil {
			data := struct {
				Command      *ltxref.Command
				Backlink     string
				Edit         string
				Filter       string
				XMLUrl       string
				PlainTextUrl string
				Package      string
			}{
				Backlink:     backlink.String(),
				Edit:         editToken(r),
				Filter:       filtervalue,
				Command:      cmd,
				XMLUrl:       addXMLFormatString(r.URL),
				PlainTextUrl: addTXTFormatString(r.URL),
				Package:      requestedPackage,
			}
			err := tpl.ExecuteTemplate(w, "commanddetail.html", data)
			if err != nil {
				fmt.Println(err)
			}
			return

		}

	}
	fmt.Println("Command not found")
	return
}