當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.HandleTOMLMetaData函數代碼示例

本文整理匯總了Golang中github.com/spf13/hugo/parser.HandleTOMLMetaData函數的典型用法代碼示例。如果您正苦於以下問題:Golang HandleTOMLMetaData函數的具體用法?Golang HandleTOMLMetaData怎麽用?Golang HandleTOMLMetaData使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了HandleTOMLMetaData函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: IsThemeVsHugoVersionMismatch

// 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
}
開發者ID:johndunne,項目名稱:hugo,代碼行數:57,代碼來源:hugo.go

示例2: readData

func readData(f *source.File) (interface{}, error) {
	switch f.Extension() {
	case "yaml", "yml":
		return parser.HandleYAMLMetaData(f.Bytes())
	case "json":
		return parser.HandleJSONMetaData(f.Bytes())
	case "toml":
		return parser.HandleTOMLMetaData(f.Bytes())
	default:
		return nil, fmt.Errorf("Data not supported for extension '%s'", f.Extension())
	}
}
開發者ID:sun-friderick,項目名稱:hugo,代碼行數:12,代碼來源:site.go

示例3: TestDataDirToml

func TestDataDirToml(t *testing.T) {
	sources := []source.ByteSource{
		{filepath.FromSlash("test/kung.toml"), []byte("[foo]\nbar = 1")},
	}

	expected, err := parser.HandleTOMLMetaData([]byte("[test]\n[test.kung]\n[test.kung.foo]\nbar = 1"))

	if err != nil {
		t.Fatalf("Error %s", err)
	}

	doTestDataDir(t, expected, []source.Input{&source.InMemorySource{ByteSource: sources}})
}
開發者ID:sun-friderick,項目名稱:hugo,代碼行數:13,代碼來源:site_test.go

示例4: TestDataDirMultipleSources

// issue 892
func TestDataDirMultipleSources(t *testing.T) {
	s1 := []source.ByteSource{
		{filepath.FromSlash("test/first.toml"), []byte("bar = 1")},
	}

	s2 := []source.ByteSource{
		{filepath.FromSlash("test/first.toml"), []byte("bar = 2")},
		{filepath.FromSlash("test/second.toml"), []byte("tender = 2")},
	}

	expected, _ := parser.HandleTOMLMetaData([]byte("[test.first]\nbar = 1\n[test.second]\ntender=2"))

	doTestDataDir(t, expected, []source.Input{&source.InMemorySource{ByteSource: s1}, &source.InMemorySource{ByteSource: s2}})

}
開發者ID:sun-friderick,項目名稱:hugo,代碼行數:16,代碼來源:site_test.go

示例5: isThemeVsHugoVersionMismatch

// isThemeVsHugoVersionMismatch returns whether the current Hugo version is
// less than the theme's min_version.
func isThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
	if !helpers.ThemeSet() {
		return
	}

	themeDir := helpers.GetThemeDir()

	fs := hugofs.Source()
	path := filepath.Join(themeDir, "theme.toml")

	exists, err := helpers.Exists(path, fs)

	if err != nil || !exists {
		return
	}

	b, err := afero.ReadFile(fs, path)

	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
}
開發者ID:vincentsys,項目名稱:hugo,代碼行數:42,代碼來源:hugo.go


注:本文中的github.com/spf13/hugo/parser.HandleTOMLMetaData函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。