From 4a19c6d5e33b357e33f1a2922b24373e6c0ab2f1 Mon Sep 17 00:00:00 2001
From: Henrique Dias <hacdias@gmail.com>
Date: Sat, 25 Jun 2016 22:05:45 +0100
Subject: [PATCH] fix some things

---
 internal/{editor => file}/editor.go | 14 +++++++-------
 internal/file/file.go               |  3 +--
 2 files changed, 8 insertions(+), 9 deletions(-)
 rename internal/{editor => file}/editor.go (88%)

diff --git a/internal/editor/editor.go b/internal/file/editor.go
similarity index 88%
rename from internal/editor/editor.go
rename to internal/file/editor.go
index ffc07f8a..74117e5b 100644
--- a/internal/editor/editor.go
+++ b/internal/file/editor.go
@@ -1,11 +1,11 @@
-package editor
+package file
 
 import (
 	"bytes"
 	"path/filepath"
 	"strings"
 
-	"github.com/hacdias/caddy-filemanager/internal/file"
+	"github.com/hacdias/caddy-hugo/tools/frontmatter"
 	"github.com/spf13/hugo/parser"
 )
 
@@ -18,7 +18,7 @@ type Editor struct {
 }
 
 // GetEditor gets the editor based on a FileInfo struct
-func (i *file.Info) GetEditor() (*Editor, error) {
+func (i *Info) GetEditor() (*Editor, error) {
 	// Create a new editor variable and set the mode
 	editor := new(Editor)
 	editor.Mode = strings.TrimPrefix(filepath.Ext(i.Name), ".")
@@ -52,12 +52,12 @@ func (i *file.Info) GetEditor() (*Editor, error) {
 
 			// Parses the page content and the frontmatter
 			editor.Content = strings.TrimSpace(string(page.Content()))
-			editor.FrontMatter, _, err = Pretty(page.FrontMatter())
+			editor.FrontMatter, _, err = frontmatter.Pretty(page.FrontMatter())
 			editor.Class = "complete"
 		} else {
 			// The editor will handle only content
 			editor.Class = "content-only"
-			editor.Content = fi.Content
+			editor.Content = i.Content
 		}
 	case "json", "toml", "yaml":
 		// Defines the class and declares an error
@@ -65,9 +65,9 @@ func (i *file.Info) GetEditor() (*Editor, error) {
 
 		// Checks if the file already has the frontmatter rune and parses it
 		if editor.hasFrontMatterRune(i.Raw) {
-			editor.FrontMatter, _, err = Pretty(i.Raw)
+			editor.FrontMatter, _, err = frontmatter.Pretty(i.Raw)
 		} else {
-			editor.FrontMatter, _, err = Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode))
+			editor.FrontMatter, _, err = frontmatter.Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode))
 		}
 
 		// Check if there were any errors
diff --git a/internal/file/file.go b/internal/file/file.go
index 37a3e9fc..2bc06876 100644
--- a/internal/file/file.go
+++ b/internal/file/file.go
@@ -13,7 +13,6 @@ import (
 
 	"github.com/dustin/go-humanize"
 	"github.com/hacdias/caddy-filemanager/internal/config"
-	"github.com/hacdias/caddy-filemanager/internal/editor"
 	p "github.com/hacdias/caddy-filemanager/internal/page"
 	"github.com/hacdias/caddy-filemanager/utils/errors"
 	"github.com/mholt/caddy/caddyhttp/httpserver"
@@ -170,7 +169,7 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config
 		},
 	}
 
-	if editor.CanBeEdited(i.Name) {
+	if CanBeEdited(i.Name) {
 		editor, err := i.GetEditor()
 
 		if err != nil {