Cleaned up

This commit is contained in:
Alex Myasoedov 2016-02-29 22:34:47 +02:00
parent 23ecf33cc1
commit 20d1b189ca
3 changed files with 9 additions and 4 deletions

1
.gitignore vendored
View file

@ -22,3 +22,4 @@ _testmain.go
*.exe
bin/
src/
slides/

10
main.go
View file

@ -23,10 +23,11 @@ func NewApp() *gin.Engine {
haikunator := haikunator.NewHaikunator()
haikunator.TokenLength = 0
name := haikunator.Haikunate()
path := fmt.Sprintf("%s.md", name)
path := fmt.Sprintf("slides/%s.md", name)
session := sessions.Default(c)
session.Set("name", path)
session.Save()
c.HTML(200, "users/index.tmpl", gin.H{
"pubTo": path,
})
@ -37,14 +38,17 @@ func NewApp() *gin.Engine {
val := session.Get("name")
path, ok := val.(string)
if !ok {
panic("unlucky")
c.String(400, "No context")
}
if _, err := os.Stat(path); err != nil {
// coppy sapmle markdown file to the path
body, err := ioutil.ReadFile("initial-slides.md")
if err != nil {
panic(err)
}
ioutil.WriteFile(path, body, 0644)
c.String(200, string(body))
return
}
body, err := ioutil.ReadFile(path)
@ -59,7 +63,7 @@ func NewApp() *gin.Engine {
val := session.Get("name")
path, ok := val.(string)
if !ok {
panic("unlucky")
c.String(400, "No context")
}
body, _ := ioutil.ReadAll(c.Request.Body)
ioutil.WriteFile(path, body, 0644)

View file

@ -14,7 +14,7 @@
<body>
<div id="edit-pane">
<div id="controls">
<a href="{{ .pubTo}}" target="_blank" onclick="save();"> Present</a>
<a href="static/slides.html" target="_blank" onclick="save();"> Present</a>
</div>
<div id="editor"></div>
</div>