shithub: hugo

Download patch

ref: f5308da32013279664379111d84fb8fa50d7e5f3
parent: e71bef79e504f8a016652380ad4c0ca89a2b8898
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Sep 14 13:31:39 EDT 2015

Move isThemeVsHugoVersionMismatch to /commands

To prevent potential package cycles in /helpers.

--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -17,6 +17,8 @@
 
 import (
 	"fmt"
+	"github.com/spf13/hugo/parser"
+	"io/ioutil"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -292,7 +294,7 @@
 		}
 	}
 
-	themeVersionMismatch, minVersion := helpers.IsThemeVsHugoVersionMismatch()
+	themeVersionMismatch, minVersion := isThemeVsHugoVersionMismatch()
 
 	if themeVersionMismatch {
 		jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
@@ -534,4 +536,58 @@
 
 	wg.Wait()
 	return nil
+}
+
+// isThemeVsHugoVersionMismatch returns whether the current Hugo version is < theme's min_version
+func isThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
+	if !helpers.ThemeSet() {
+		return
+	}
+
+	themeDir := helpers.GetThemeDir()
+
+	fs := hugofs.SourceFs
+	path := filepath.Join(themeDir, "theme.toml")
+
+	exists, err := helpers.Exists(path, fs)
+
+	if err != nil || !exists {
+		return
+	}
+
+	f, err := fs.Open(path)
+
+	if err != nil {
+		return
+	}
+
+	defer f.Close()
+
+	b, err := ioutil.ReadAll(f)
+
+	if err != nil {
+		return
+	}
+
+	c, err := parser.HandleTOMLMetaData(b)
+
+	if err != nil {
+		return
+	}
+
+	config := c.(map[string]interface{})
+
+	if minVersion, ok := config["min_version"]; ok {
+		switch minVersion.(type) {
+		case float32:
+			return helpers.HugoVersionNumber < minVersion.(float32), fmt.Sprint(minVersion)
+		case float64:
+			return helpers.HugoVersionNumber < minVersion.(float64), fmt.Sprint(minVersion)
+		default:
+			return
+		}
+
+	}
+
+	return
 }
--- a/helpers/hugo.go
+++ b/helpers/hugo.go
@@ -15,31 +15,26 @@
 
 import (
 	"fmt"
-	"io/ioutil"
-	"path/filepath"
-
-	"github.com/spf13/hugo/hugofs"
-	"github.com/spf13/hugo/parser"
 )
 
 // this should be the only one
-const hugoVersionMain = 0.15
-const hugoVersionSuffix = "-DEV" // blank this when doing a release
+const HugoVersionNumber = 0.15
+const HugoVersionSuffix = "-DEV" // blank this when doing a release
 
 // HugoVersion returns the current Hugo version. It will include
 // a suffix, typically '-DEV', if it's development version.
 func HugoVersion() string {
-	return hugoVersion(hugoVersionMain, hugoVersionSuffix)
+	return hugoVersion(HugoVersionNumber, HugoVersionSuffix)
 }
 
 // HugoReleaseVersion is same as HugoVersion, but no suffix.
 func HugoReleaseVersion() string {
-	return hugoVersionNoSuffix(hugoVersionMain)
+	return hugoVersionNoSuffix(HugoVersionNumber)
 }
 
 // NextHugoReleaseVersion returns the next Hugo release version.
 func NextHugoReleaseVersion() string {
-	return hugoVersionNoSuffix(hugoVersionMain + 0.01)
+	return hugoVersionNoSuffix(HugoVersionNumber + 0.01)
 }
 
 func hugoVersion(version float32, suffix string) string {
@@ -48,62 +43,4 @@
 
 func hugoVersionNoSuffix(version float32) string {
 	return fmt.Sprintf("%.2g", version)
-}
-
-// IsThemeVsHugoVersionMismatch returns whether the current Hugo version is < theme's min_version
-func IsThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
-	if !ThemeSet() {
-		return
-	}
-
-	themeDir, err := getThemeDirPath("")
-
-	if err != nil {
-		return
-	}
-
-	fs := hugofs.SourceFs
-	path := filepath.Join(themeDir, "theme.toml")
-
-	exists, err := Exists(path, fs)
-
-	if err != nil || !exists {
-		return
-	}
-
-	f, err := fs.Open(path)
-
-	if err != nil {
-		return
-	}
-
-	defer f.Close()
-
-	b, err := ioutil.ReadAll(f)
-
-	if err != nil {
-		return
-	}
-
-	c, err := parser.HandleTOMLMetaData(b)
-
-	if err != nil {
-		return
-	}
-
-	config := c.(map[string]interface{})
-
-	if minVersion, ok := config["min_version"]; ok {
-		switch minVersion.(type) {
-		case float32:
-			return hugoVersionMain < minVersion.(float32), fmt.Sprint(minVersion)
-		case float64:
-			return hugoVersionMain < minVersion.(float64), fmt.Sprint(minVersion)
-		default:
-			return
-		}
-
-	}
-
-	return
 }