예제 #1
0
파일: frontend.go 프로젝트: nathankerr/soar
func AssetsServer(w http.ResponseWriter, req *http.Request) {
	_, filename := path.Split(req.URL.Path)

	assets_client, err := soar.NewClient(":1234")
	if err != nil {
		panic(err)
	}

	if filename == "" {
		// List files
		io.WriteString(w, "<html><head><title>Asset List</title></head><body>")

		returns, err := assets_client.Invoke("List")
		if err != nil {
			panic(err)
		}

		files, ok := returns[0].([]string)
		if !ok {
			panic("cannot recast asset response")
		}

		for _, file := range files {
			io.WriteString(w, "<a href=\"/assets/"+file+"\">"+file+"</a> ")
			io.WriteString(w, "<a href=\"/render/"+file+"\">(as pdf)</a>")
			io.WriteString(w, "<br/>")
		}

		io.WriteString(w, "</body></html>")
	} else {
		// Show contents of a file
		returns, err := assets_client.Invoke("Get", filename)
		if err != nil {
			panic(err)
		}

		data, ok := returns[0].([]byte)
		if !ok {
			panic("cannot recast assets response")
		}

		w.Write(data)
	}
}
예제 #2
0
파일: render.go 프로젝트: nathankerr/soar
func (r *Render) Render(filename string) []byte {
	assets_client, err := soar.NewClient(":1234")
	if err != nil {
		panic(err)
	}

	tmpdir, err := ioutil.TempDir("tmp/", "")
	if err != nil {
		panic(err)
	}

	returns, err := assets_client.Invoke("Get", filename)
	if err != nil {
		panic(err)
	}

	input, ok := returns[0].([]byte)
	if !ok {
		panic("could not recast assets return")
	}

	input_file := filepath.Join(tmpdir, "input.tex")
	ioutil.WriteFile(input_file, input, 0666)

	pdf_out := filepath.Join(tmpdir, "input.pdf")
	xelatex := exec.Command("xelatex",
		//"-o", pdf_out,
		"-output-directory="+tmpdir,
		input_file,
	)
	xelatex.Stdout = os.Stdout
	xelatex.Stderr = os.Stderr
	if xelatex.Run() != nil {
		log.Fatal("pdfserver xelatex.Run:", err)
	}

	content, err := ioutil.ReadFile(pdf_out)
	if err != nil {
		log.Fatal("pdfserver read content:", err)
	}

	return content
}
예제 #3
0
파일: frontend.go 프로젝트: nathankerr/soar
func RenderServer(w http.ResponseWriter, req *http.Request) {
	_, filename := path.Split(req.URL.Path)

	render_client, err := soar.NewClient(":1233")
	if err != nil {
		panic(err)
	}

	returns, err := render_client.Invoke("Render", filename)
	if err != nil {
		panic(err)
	}

	data, ok := returns[0].([]byte)
	if !ok {
		panic("cannot recast render response")
	}

	w.Write(data)
}