Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspf13 <steve.francia@gmail.com>2014-05-09 02:30:11 +0400
committerspf13 <steve.francia@gmail.com>2014-05-09 02:30:58 +0400
commit6b9d4a93da92b9ef390b6d62bcb5835e86703bd3 (patch)
tree1a7f8e2f9a5faf22043e40c1677bb8d2ec40cdd9 /parser/frontmatter.go
parentbe3e5592dc43d79073283c234b141eb644d3d8a0 (diff)
Adding new commands (new site [path], new theme [name])
Diffstat (limited to 'parser/frontmatter.go')
-rw-r--r--parser/frontmatter.go59
1 files changed, 54 insertions, 5 deletions
diff --git a/parser/frontmatter.go b/parser/frontmatter.go
index 374fe020b..d3c3f0347 100644
--- a/parser/frontmatter.go
+++ b/parser/frontmatter.go
@@ -29,6 +29,47 @@ type FrontmatterType struct {
includeMark bool
}
+func InterfaceToConfig(in interface{}, mark rune) ([]byte, error) {
+ if in == nil {
+ return []byte{}, fmt.Errorf("input was nil")
+ }
+
+ b := new(bytes.Buffer)
+
+ switch mark {
+ case rune(YAML_LEAD[0]):
+ by, err := goyaml.Marshal(in)
+ if err != nil {
+ return nil, err
+ }
+ b.Write(by)
+ _, err = b.Write([]byte("..."))
+ if err != nil {
+ return nil, err
+ }
+ return b.Bytes(), nil
+ case rune(TOML_LEAD[0]):
+ err := toml.NewEncoder(b).Encode(in)
+ if err != nil {
+ return nil, err
+ }
+ return b.Bytes(), nil
+ case rune(JSON_LEAD[0]):
+ by, err := json.MarshalIndent(in, "", " ")
+ if err != nil {
+ return nil, err
+ }
+ b.Write(by)
+ _, err = b.Write([]byte("\n"))
+ if err != nil {
+ return nil, err
+ }
+ return b.Bytes(), nil
+ default:
+ return nil, fmt.Errorf("Unsupported Format provided")
+ }
+}
+
func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
if in == nil {
return []byte{}, fmt.Errorf("input was nil")
@@ -60,8 +101,6 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
err = toml.NewEncoder(b).Encode(in)
if err != nil {
- fmt.Println("toml encoder failed", in)
- fmt.Println(err)
return nil, err
}
_, err = b.Write([]byte("\n" + TOML_DELIM_UNIX))
@@ -72,8 +111,6 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
case rune(JSON_LEAD[0]):
by, err := json.MarshalIndent(in, "", " ")
if err != nil {
- fmt.Println("json encoder failed", in)
- fmt.Println(err)
return nil, err
}
b.Write(by)
@@ -88,7 +125,7 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
}
func FormatToLeadRune(kind string) rune {
- switch strings.ToLower(kind) {
+ switch FormatSanitize(kind) {
case "yaml":
return rune([]byte(YAML_LEAD)[0])
case "toml":
@@ -98,7 +135,19 @@ func FormatToLeadRune(kind string) rune {
default:
return rune([]byte(TOML_LEAD)[0])
}
+}
+func FormatSanitize(kind string) string {
+ switch strings.ToLower(kind) {
+ case "yaml", "yml":
+ return "yaml"
+ case "toml", "tml":
+ return "toml"
+ case "json", "js":
+ return "json"
+ default:
+ return "toml"
+ }
}
func DetectFrontMatter(mark rune) (f *FrontmatterType) {