diff options
author | Pacien | 2013-07-01 12:42:28 +0200 |
---|---|---|
committer | Pacien | 2013-07-01 12:42:28 +0200 |
commit | c879511377bdb76615b58b212f030e82fb88d3be (patch) | |
tree | 9c3783284594b98d923e230d361ec76e86200f3b /common.go | |
parent | 7b0b720efbf39ded2f72363d36424281df2b0491 (diff) | |
download | foldaweb-c879511377bdb76615b58b212f030e82fb88d3be.tar.gz |
Replace file manipulation functions by the fcmd package
Diffstat (limited to 'common.go')
-rw-r--r-- | common.go | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -22,6 +22,7 @@ package main | |||
22 | import ( | 22 | import ( |
23 | "bytes" | 23 | "bytes" |
24 | "fmt" | 24 | "fmt" |
25 | "github.com/Pacien/fcmd" | ||
25 | "github.com/drbawb/mustache" | 26 | "github.com/drbawb/mustache" |
26 | "github.com/russross/blackfriday" | 27 | "github.com/russross/blackfriday" |
27 | "io/ioutil" | 28 | "io/ioutil" |
@@ -69,7 +70,7 @@ func merge(files map[string][]byte) (merged []byte) { | |||
69 | // render and write everything inside | 70 | // render and write everything inside |
70 | 71 | ||
71 | func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) map[string][]byte { | 72 | func parse(dirPath string, elements map[string][]byte, exts []string, overwrite bool) map[string][]byte { |
72 | _, filesList := ls(dirPath) | 73 | _, filesList := fcmd.Ls(dirPath) |
73 | for _, fileName := range filesList { | 74 | for _, fileName := range filesList { |
74 | if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) { | 75 | if isParsable(fileName, exts) && (overwrite || elements[fileName[:len(fileName)-len(path.Ext(fileName))]] == nil) { |
75 | var err error | 76 | var err error |
@@ -93,7 +94,7 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s | |||
93 | elements = parse(dirPath, elements, exts, true) | 94 | elements = parse(dirPath, elements, exts, true) |
94 | 95 | ||
95 | if recursive { | 96 | if recursive { |
96 | dirs, _ := ls(dirPath) | 97 | dirs, _ := fcmd.Ls(dirPath) |
97 | for _, dir := range dirs { | 98 | for _, dir := range dirs { |
98 | go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive) | 99 | go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive) |
99 | } | 100 | } |
@@ -102,7 +103,7 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s | |||
102 | template := merge(elements) | 103 | template := merge(elements) |
103 | page := mustache.Render(string(template), makeContext(dirPath, sourceDir, outputDir, exts)) | 104 | page := mustache.Render(string(template), makeContext(dirPath, sourceDir, outputDir, exts)) |
104 | 105 | ||
105 | err := writeFile(path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), saveAs), []byte(page)) | 106 | err := fcmd.WriteFile(path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), saveAs), []byte(page)) |
106 | if err != nil { | 107 | if err != nil { |
107 | fmt.Println(err) | 108 | fmt.Println(err) |
108 | return | 109 | return |
@@ -117,10 +118,10 @@ func copyFiles(dirPath, sourceDir, outputDir string, exts []string, recursive bo | |||
117 | return | 118 | return |
118 | } | 119 | } |
119 | 120 | ||
120 | dirs, files := ls(dirPath) | 121 | dirs, files := fcmd.Ls(dirPath) |
121 | for _, file := range files { | 122 | for _, file := range files { |
122 | if !isParsable(file, exts) { | 123 | if !isParsable(file, exts) { |
123 | err := cp(path.Join(dirPath, file), path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), file)) | 124 | err := fcmd.Cp(path.Join(dirPath, file), path.Join(outputDir, strings.TrimPrefix(dirPath, sourceDir), file)) |
124 | if err != nil { | 125 | if err != nil { |
125 | fmt.Println(err) | 126 | fmt.Println(err) |
126 | } | 127 | } |