structure changes

This commit is contained in:
Henrique Dias
2016-03-06 20:37:49 +00:00
parent 3f36200862
commit 1375038a66
43 changed files with 405 additions and 392 deletions

0
routes/assets/.gitkeep Normal file
View File

View File

@@ -6,7 +6,7 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// DELETE handles the delete requests on browse pages
@@ -32,17 +32,17 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Check for errors
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, nil)
}
} else {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "File not found.",
}, 404, nil)
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": message,
}, 200, nil)
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/templates"
"github.com/hacdias/caddy-hugo/tools/variables"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/browse"
)
@@ -15,7 +16,7 @@ import (
func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
functions := template.FuncMap{
"CanBeEdited": templates.CanBeEdited,
"Defined": templates.Defined,
"Defined": variables.Defined,
}
tpl, err := templates.Get(r, functions, "browse")

View File

@@ -12,7 +12,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/commands"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// POST handles the POST method on browse page. It's used to create new files,
@@ -37,13 +37,13 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Check if filename and archetype are specified in
// the request
if _, ok := info["filename"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Filename not specified.",
}, 500, nil)
}
if _, ok := info["archetype"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Archtype not specified.",
}, 500, nil)
}
@@ -67,7 +67,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
}
if err := commands.Run(c.Hugo, args, c.Path); err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -84,14 +84,14 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
}
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"location": url,
"message": "File created.",
}, 200, nil)
@@ -101,7 +101,7 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Parse the multipart form in the request
err := r.ParseMultipartForm(100000)
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -113,7 +113,7 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Open the first file
var infile multipart.File
if infile, err = hdr.Open(); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -121,14 +121,14 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Create the file
var outfile *os.File
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
// Copy the file content
if _, err = io.Copy(outfile, infile); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -137,5 +137,5 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
}
}
return utils.RespondJSON(w, nil, 200, nil)
return server.RespondJSON(w, nil, 200, nil)
}

View File

@@ -8,7 +8,7 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// PUT handles the HTTP PUT request for all /admin/browse related requests.
@@ -31,7 +31,7 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Check if filename and archetype are specified in
// the request
if _, ok := info["filename"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Filename not specified.",
}, 400, nil)
}
@@ -44,12 +44,12 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Renames the file/folder
if err := os.Rename(old, new); err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "File renamed.",
}, 200, nil)
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/frontmatter"
"github.com/hacdias/caddy-hugo/tools/templates"
"github.com/hacdias/caddy-hugo/tools/variables"
"github.com/spf13/hugo/parser"
)
@@ -110,8 +111,8 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
// Create the functions map, then the template, check for erros and
// execute the template if there aren't errors
functions := template.FuncMap{
"SplitCapitalize": templates.SplitCapitalize,
"Defined": templates.Defined,
"SplitCapitalize": variables.SplitCapitalize,
"Defined": variables.Defined,
}
tpl, err := templates.Get(r, functions, "editor", "frontmatter")

View File

@@ -11,7 +11,7 @@ import (
"time"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/commands"
"github.com/hacdias/caddy-hugo/tools/hugo"
"github.com/robfig/cron"
"github.com/spf13/cast"
"github.com/spf13/hugo/parser"
@@ -144,7 +144,7 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
return
}
go commands.Run(c, false)
go hugo.Run(c, false)
})
scheduler.Start()
}

View File

@@ -8,14 +8,14 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// POST handles the POST method on GIT page which is only an API.
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Check if git is installed on the computer
if _, err := exec.LookPath("git"); err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Git is not installed on your computer.",
}, 400, nil)
}
@@ -30,7 +30,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Check if command was sent
if _, ok := info["command"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Command not specified.",
}, 400, nil)
}
@@ -43,7 +43,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
}
if len(args) == 0 {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Command not specified.",
}, 400, nil)
}
@@ -53,12 +53,12 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
output, err := cmd.CombinedOutput()
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": err.Error(),
}, 500, err)
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": string(output),
}, 200, nil)
}