当前位置: 首页>>代码示例>>Golang>>正文


Golang helpers.WriteToDisk函数代码示例

本文整理汇总了Golang中github.com/spf13/hugo/helpers.WriteToDisk函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteToDisk函数的具体用法?Golang WriteToDisk怎么用?Golang WriteToDisk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了WriteToDisk函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestScpGetLocal

func TestScpGetLocal(t *testing.T) {
	fs := new(afero.MemMapFs)
	ps := helpers.FilePathSeparator
	tests := []struct {
		path    string
		content []byte
	}{
		{"testpath" + ps + "test.txt", []byte(`T€st Content 123 fOO,bar:foo%bAR`)},
		{"FOo" + ps + "BaR.html", []byte(`FOo/BaR.html T€st Content 123`)},
		{"трям" + ps + "трям", []byte(`T€st трям/трям Content 123`)},
		{"은행", []byte(`T€st C은행ontent 123`)},
		{"Банковский кассир", []byte(`Банковский кассир T€st Content 123`)},
	}

	for _, test := range tests {
		r := bytes.NewReader(test.content)
		err := helpers.WriteToDisk(test.path, r, fs)
		if err != nil {
			t.Error(err)
		}

		c, err := resGetLocal(test.path, fs)
		if err != nil {
			t.Errorf("Error getting resource content: %s", err)
		}
		if bytes.Compare(c, test.content) != 0 {
			t.Errorf("\nExpected: %s\nActual: %s\n", string(test.content), string(c))
		}
	}

}
开发者ID:johndunne,项目名称:hugo,代码行数:31,代码来源:template_resources_test.go

示例2: createThemeMD

func createThemeMD(inpath string) (err error) {

	by := []byte(`# theme.toml template for a Hugo theme
# See https://github.com/spf13/hugoThemes#themetoml for an example

name = "` + strings.Title(helpers.MakeTitle(filepath.Base(inpath))) + `"
license = "MIT"
licenselink = "https://github.com/yourname/yourtheme/blob/master/LICENSE.md"
description = ""
homepage = "http://siteforthistheme.com/"
tags = ["", ""]
features = ["", ""]
min_version = 0.14

[author]
  name = ""
  homepage = ""

# If porting an existing theme
[original]
  name = ""
  homepage = ""
  repo = ""
`)

	err = helpers.WriteToDisk(filepath.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs)
	if err != nil {
		return
	}

	return nil
}
开发者ID:maruel,项目名称:hugo,代码行数:32,代码来源:new.go

示例3: NewTheme

func NewTheme(cmd *cobra.Command, args []string) {
	InitializeConfig()

	if len(args) < 1 {
		cmd.Usage()
		jww.FATAL.Fatalln("theme name needs to be provided")
	}

	createpath := helpers.AbsPathify(path.Join("themes", args[0]))
	jww.INFO.Println("creating theme at", createpath)

	if x, _ := helpers.Exists(createpath); x {
		jww.FATAL.Fatalln(createpath, "already exists")
	}

	mkdir(createpath, "layouts", "_default")
	mkdir(createpath, "layouts", "chrome")

	touchFile(createpath, "layouts", "index.html")
	touchFile(createpath, "layouts", "_default", "list.html")
	touchFile(createpath, "layouts", "_default", "single.html")

	touchFile(createpath, "layouts", "chrome", "header.html")
	touchFile(createpath, "layouts", "chrome", "footer.html")

	mkdir(createpath, "archetypes")
	touchFile(createpath, "archetypes", "default.md")

	mkdir(createpath, "static", "js")
	mkdir(createpath, "static", "css")

	by := []byte(`The MIT License (MIT)

Copyright (c) 2014 YOUR_NAME_HERE

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
`)

	err := helpers.WriteToDisk(path.Join(createpath, "LICENSE.md"), bytes.NewReader(by))
	if err != nil {
		jww.FATAL.Fatalln(err)
	}

	createThemeMD(createpath)
}
开发者ID:vinchu,项目名称:hugo,代码行数:60,代码来源:new.go

示例4: Publish

func (h *HTMLRedirectAlias) Publish(path string, permalink string, page interface{}) (err error) {
	if path, err = h.Translate(path); err != nil {
		jww.ERROR.Printf("%s, skipping.", err)
		return nil
	}

	t := "alias"
	if strings.HasSuffix(path, ".xhtml") {
		t = "alias-xhtml"
	}

	template := defaultAliasTemplates
	if h.Templates != nil {
		template = h.Templates
		t = "alias.html"
	}

	buffer := new(bytes.Buffer)
	err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink, page})
	if err != nil {
		return
	}

	return helpers.WriteToDisk(path, buffer, hugofs.Destination())
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:25,代码来源:htmlredirect.go

示例5: createThemeMD

func createThemeMD(inpath string) (err error) {

	by := []byte(`name = "` + strings.Title(helpers.MakeTitle(filepath.Base(inpath))) + `"
license = "MIT"
licenselink = "https://github.com/.../.../LICENSE.md"
description = ""
homepage = "http://siteforthistheme.com/"
tags = ["", ""]
features = ["", ""]

[author]
  name = ""
  homepage = ""

# If porting an existing theme
[original]
  name = ""
  homepage = ""
  repo = ""
`)

	err = helpers.WriteToDisk(filepath.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs)
	if err != nil {
		return
	}

	return nil
}
开发者ID:dunn,项目名称:hugo,代码行数:28,代码来源:new.go

示例6: touchFile

func touchFile(x ...string) {
	inpath := filepath.Join(x...)
	mkdir(filepath.Dir(inpath))
	err := helpers.WriteToDisk(inpath, bytes.NewReader([]byte{}), hugofs.SourceFs)
	if err != nil {
		jww.FATAL.Fatalln(err)
	}
}
开发者ID:maruel,项目名称:hugo,代码行数:8,代码来源:new.go

示例7: Publish

func (fs *Filesystem) Publish(path string, r io.Reader) (err error) {
	translated, err := fs.Translate(path)
	if err != nil {
		return
	}

	return helpers.WriteToDisk(translated, r, hugofs.DestinationFS)
}
开发者ID:blevesearch,项目名称:hugoidx,代码行数:8,代码来源:file.go

示例8: Publish

func (pp *PagePub) Publish(path string, r io.Reader) (err error) {

	translated, err := pp.Translate(path)
	if err != nil {
		return
	}

	return helpers.WriteToDisk(translated, r, hugofs.DestinationFS)
}
开发者ID:reedobrien,项目名称:hugo,代码行数:9,代码来源:page.go

示例9: saveSource

func (p *Page) saveSource(by []byte, inpath string, safe bool) (err error) {
	if !filepath.IsAbs(inpath) {
		inpath = helpers.AbsPathify(inpath)
	}
	jww.INFO.Println("creating", inpath)

	if safe {
		err = helpers.SafeWriteToDisk(inpath, bytes.NewReader(by), hugofs.SourceFs)
	} else {
		err = helpers.WriteToDisk(inpath, bytes.NewReader(by), hugofs.SourceFs)
	}
	if err != nil {
		return
	}
	return nil
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:16,代码来源:page.go

示例10: createConfig

func createConfig(inpath string, kind string) (err error) {
	in := map[string]string{"baseurl": "http://yourSiteHere", "title": "my new hugo site", "languageCode": "en-us"}
	kind = parser.FormatSanitize(kind)

	by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind))
	if err != nil {
		return err
	}

	err = helpers.WriteToDisk(path.Join(inpath, "config."+kind), bytes.NewReader(by))
	if err != nil {
		return
	}

	return nil
}
开发者ID:vinchu,项目名称:hugo,代码行数:16,代码来源:new.go

示例11: createConfig

func createConfig(inpath string, kind string) (err error) {
	in := map[string]string{
		"baseurl":      "http://replace-this-with-your-hugo-site.com/",
		"title":        "My New Hugo Site",
		"languageCode": "en-us",
	}
	kind = parser.FormatSanitize(kind)

	by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind))
	if err != nil {
		return err
	}

	err = helpers.WriteToDisk(filepath.Join(inpath, "config."+kind), bytes.NewReader(by), hugofs.SourceFs)
	if err != nil {
		return
	}

	return nil
}
开发者ID:maruel,项目名称:hugo,代码行数:20,代码来源:new.go

示例12: createConfigFromJekyll

func createConfigFromJekyll(inpath string, kind string, jekyllConfig map[string]interface{}) (err error) {
	title := "My New Hugo Site"
	baseURL := "http://example.org/"

	for key, value := range jekyllConfig {
		lowerKey := strings.ToLower(key)

		switch lowerKey {
		case "title":
			if str, ok := value.(string); ok {
				title = str
			}

		case "url":
			if str, ok := value.(string); ok {
				baseURL = str
			}
		}
	}

	in := map[string]interface{}{
		"baseURL":            baseURL,
		"title":              title,
		"languageCode":       "en-us",
		"disablePathToLower": true,
	}
	kind = parser.FormatSanitize(kind)

	by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind))
	if err != nil {
		return err
	}

	err = helpers.WriteToDisk(filepath.Join(inpath, "config."+kind), bytes.NewReader(by), hugofs.Source())
	if err != nil {
		return
	}

	return nil
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:40,代码来源:import_jekyll.go

示例13: Publish

func (h *HTMLRedirectAlias) Publish(path string, permalink template.HTML) (err error) {
	if path, err = h.Translate(path); err != nil {
		return
	}

	t := "alias"
	if strings.HasSuffix(path, ".xhtml") {
		t = "alias-xhtml"
	}

	template := DefaultAliasTemplates
	if h.Templates != nil {
		template = h.Templates
	}

	buffer := new(bytes.Buffer)
	err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink})
	if err != nil {
		return
	}

	return helpers.WriteToDisk(path, buffer, hugofs.DestinationFS)
}
开发者ID:nurhavid,项目名称:hugo,代码行数:23,代码来源:htmlredirect.go

示例14: createThemeMD

func createThemeMD(inpath string) (err error) {

	in := map[string]interface{}{
		"name":        helpers.MakeTitle(filepath.Base(inpath)),
		"license":     "MIT",
		"source_repo": "",
		"author":      "",
		"description": "",
		"tags":        []string{"", ""},
	}

	by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune("toml"))
	if err != nil {
		return err
	}

	err = helpers.WriteToDisk(path.Join(inpath, "theme.toml"), bytes.NewReader(by))
	if err != nil {
		return
	}

	return nil
}
开发者ID:vinchu,项目名称:hugo,代码行数:23,代码来源:new.go


注:本文中的github.com/spf13/hugo/helpers.WriteToDisk函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。