Exemplo n.º 1
0
func main() {
	mainParseArguments(os.Args)
	mainOpenFiles()
	err := bbgo.Process(mainInput, mainOutput)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error on processing bbcode file: %s.\n", err.Error())
		os.Exit(1)
	}
}
Exemplo n.º 2
0
func (page *page) AddMessage(format string, args ...interface{}) {
	msg := fmt.Sprintf(format, args...)
	bb := bytes.NewBuffer([]byte{})
	err := bbgo.Process(strings.NewReader(msg), bb)
	if err != nil {
		page.Fatalf("Failed to convert '%s' from BBCode to HTML: %s", err.Error())
	}
	imsgs, err := page.GetField("page-messages")
	if err != nil {
		page.Fatalf("page-messages field not set")
	}
	msgs, ok := imsgs.([]template.HTML)
	if !ok {
		fmt.Printf("%T", imsgs)
		page.Fatalf("Failed to convert field data for 'page-messages' into []template.HTML.")
	}
	page.SetField("page-messages", append(msgs, template.HTML(bb.String())))
}
Exemplo n.º 3
0
func infoDir(page *page, req *http.Request) {
	topic := path.Base(req.URL.Path)
	filepath := page.main.conf.AssetsPath() + "/info/" + topic + ".txt"
	file, err := os.Open(filepath)
	if err != nil {
		page.SetField("content", "Fant ikke noen slik side.")
		page.WriteHeader(404)
	} else {
		defer file.Close()
		buf := bytes.NewBuffer([]byte{})
		err = bbgo.Process(file, buf)
		if err != nil {
			page.Fatalf("Failed to convert file from BBCode to HTML: %s", err.Error())
		}
		page.SetField("content", template.HTML(buf.String()))
	}

	page.ExecuteTemplate("info")
}