Commits

Dobrosław Żybort  committed b61124f

Add more syntaxes

  • Participants
  • Parent commits 7b6cdcd

Comments (0)

Files changed (3)

 	}
 
 	return T("index.html").Execute(wri, map[string]interface{}{
-		"pastes": pastes,
-		"ctx":    ctx,
+		"pastes":   pastes,
+		"ctx":      ctx,
+		"syntaxes": syntaxes.Syntaxes,
 	})
 }
 
 package main
 
 import (
+	"encoding/json"
 	"fmt"
 	"github.com/gorilla/pat"
 	"github.com/gorilla/sessions"
+	"io/ioutil"
 	"net/http"
+	"os"
 )
 
+type Syntax struct {
+	LangName string `json:"langName"`
+	LangFile string `json:"langFile"`
+	Selected bool   `json:"selected"`
+}
+
+type AllSyntaxes struct {
+	Syntaxes []Syntax `json:"syntaxes"`
+}
+
 var router *pat.Router
 var store sessions.Store
+var syntaxes AllSyntaxes
 
 //=============================================================================
 
 	return url.Path
 }
 
+func init() {
+	file, err := ioutil.ReadFile("./data/syntaxes.json")
+	if err != nil {
+		fmt.Printf("File error: %v\n", err)
+		os.Exit(1)
+	}
+	json.Unmarshal(file, &syntaxes)
+}
+
 func main() {
 	err := dbInit()
 	if err != nil {

File templates/index.html

 	<form action="{{ reverse "addPaste" }}" method="POST">
 		<p>Title: <input type="text" name="title"></p>
 		<select name="paste_syntax">
-			<option value="cpp">C++</option>
-			<option value="go">Go</option>
-			<option value="no-highlight" selected="selected">Plain Text</option>
-			<option value="python">Python</option>
+		{{ range .syntaxes }}
+			<option value="{{ .LangFile }}" {{ if .Selected }}selected="selected"{{ end }}>{{ .LangName }}</option>
+		{{ end }}
 		</select> 
 		<p>Code: <textarea name="code" rows="15" cols="60"></textarea></p>
 		<p>Author: