Exemple #1
0
func packageDetailHandler(w http.ResponseWriter, r *http.Request) {
	requestedPackage := mux.Vars(r)["package"]
	filtervalue := strings.ToLower(r.FormValue("filter"))

	pkg := latexref.GetPackageWithName(requestedPackage)
	if pkg == nil {
		// not found -> error // TODO
		return
	}

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

		data := struct {
			Backlink     string
			Edit         string
			Filter       string
			Package      ltxref.Package
			XMLUrl       string
			PlainTextUrl string
		}{
			Backlink:     backlink.String(),
			Edit:         editToken(r),
			Filter:       filtervalue,
			Package:      *pkg,
			XMLUrl:       addXMLFormatString(r.URL),
			PlainTextUrl: addTXTFormatString(r.URL),
		}
		err := tpl.ExecuteTemplate(w, "pkgdetail", data)
		if err != nil {
			fmt.Println(err)
		}
		return
	}
}
Exemple #2
0
func documentclassDetailHandler(w http.ResponseWriter, r *http.Request) {
	requestedDocumentclass := mux.Vars(r)["documentclass"]
	filtervalue := strings.ToLower(r.FormValue("filter"))

	class := latexref.GetDocumentClass(requestedDocumentclass)
	if class == nil {
		// not found -> error // TODO
		return
	}
	switch strings.ToLower(r.FormValue("format")) {
	case "xml":
		l := ltxref.Ltxref{Version: latexref.Version}
		l.DocumentClasses = append(l.DocumentClasses, class)
		str, err := l.ToXML()
		if err != nil {
			fmt.Println(err)
			return
		}
		sendXML(w, str)
		return
	case "txt":
		class.ToString(w)
		return
	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
			DocumentClass ltxref.DocumentClass
			XMLUrl        string
			PlainTextUrl  string
		}{
			Backlink:      backlink.String(),
			Edit:          editToken(r),
			Filter:        filtervalue,
			DocumentClass: *class,
			XMLUrl:        addXMLFormatString(r.URL),
			PlainTextUrl:  addTXTFormatString(r.URL),
		}
		err := tpl.ExecuteTemplate(w, "classdetail", data)
		if err != nil {
			fmt.Println(err)
		}
	}
	return
}
Exemple #3
0
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
	}
}
Exemple #4
0
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)
	}
}
Exemple #5
0
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
}