本文整理汇总了Golang中github.com/spf13/hugo/bufferpool.GetBuffer函数的典型用法代码示例。如果您正苦于以下问题:Golang GetBuffer函数的具体用法?Golang GetBuffer怎么用?Golang GetBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetBuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: renderAndWriteXML
func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n")
err := s.render(name, d, renderBuffer, layouts...)
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
var path []byte
if viper.GetBool("RelativeURLs") {
path = []byte(helpers.GetDottedRelativePath(dest))
} else {
s := viper.GetString("BaseURL")
if !strings.HasSuffix(s, "/") {
s += "/"
}
path = []byte(s)
}
transformer := transform.NewChain(transform.AbsURLInXML)
transformer.Apply(outBuffer, renderBuffer, path)
if err == nil {
err = s.WriteDestFile(dest, outBuffer)
}
return err
}
示例2: renderAndWritePage
func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
err := s.render(name, d, renderBuffer, layouts...)
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
transformLinks := transform.NewEmptyTransforms()
if viper.GetBool("CanonifyUrls") {
absURL, err := transform.AbsURL(viper.GetString("BaseUrl"))
if err != nil {
return err
}
transformLinks = append(transformLinks, absURL...)
}
if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
transformLinks = append(transformLinks, transform.LiveReloadInject)
}
transformer := transform.NewChain(transformLinks...)
transformer.Apply(outBuffer, renderBuffer)
if err == nil {
if err = s.WriteDestPage(dest, outBuffer); err != nil {
return err
}
}
return err
}
示例3: renderAndWritePage
func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
err := s.render(name, d, renderBuffer, layouts...)
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
transformLinks := transform.NewEmptyTransforms()
if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") {
transformLinks = append(transformLinks, transform.AbsURL)
}
if s.Running() && viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
transformLinks = append(transformLinks, transform.LiveReloadInject)
}
var path []byte
if viper.GetBool("RelativeURLs") {
translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest)
if err != nil {
return err
}
path = []byte(helpers.GetDottedRelativePath(translated))
} else if viper.GetBool("CanonifyURLs") {
s := viper.GetString("BaseURL")
if !strings.HasSuffix(s, "/") {
s += "/"
}
path = []byte(s)
}
transformer := transform.NewChain(transformLinks...)
transformer.Apply(outBuffer, renderBuffer, path)
if outBuffer.Len() == 0 {
jww.WARN.Printf("%q is rendered empty\n", dest)
if dest == "/" {
jww.ERROR.Println("=============================================================")
jww.ERROR.Println("Your rendered home page is blank: /index.html is zero-length")
jww.ERROR.Println(" * Did you specify a theme on the command-line or in your")
jww.ERROR.Printf(" %q file? (Current theme: %q)\n", filepath.Base(viper.ConfigFileUsed()), viper.GetString("Theme"))
if !viper.GetBool("Verbose") {
jww.ERROR.Println(" * For more debugging information, run \"hugo -v\"")
}
jww.ERROR.Println("=============================================================")
}
}
if err == nil {
if err = s.WriteDestPage(dest, outBuffer); err != nil {
return err
}
}
return err
}
示例4: StripHTML
// StripHTML accepts a string, strips out all HTML tags and returns it.
func StripHTML(s string) string {
// Shortcut strings with no tags in them
if !strings.ContainsAny(s, "<>") {
return s
}
s = stripHTMLReplacer.Replace(s)
// Walk through the string removing all tags
b := bp.GetBuffer()
defer bp.PutBuffer(b)
inTag := false
for _, r := range s {
switch r {
case '<':
inTag = true
case '>':
inTag = false
default:
if !inTag {
b.WriteRune(r)
}
}
}
return b.String()
}
示例5: doReplace
func doReplace(content []byte, matchers []absurlMatcher) []byte {
b := bp.GetBuffer()
defer bp.PutBuffer(b)
var items []item
if x := itemSlicePool.Get(); x != nil {
items = x.([]item)[:0]
defer itemSlicePool.Put(items)
} else {
items = make([]item, 0, 8)
}
lexer := &contentlexer{content: content,
items: items,
prefixLookup: &prefixes{pr: mainPrefixRunes},
matchers: matchers}
lexer.runReplacer()
for _, token := range lexer.items {
switch token.typ {
case tText:
b.Write(token.val)
default:
for _, e := range matchers {
if token.typ == e.replaceType {
b.Write(e.replacement)
break
}
}
}
}
return b.Bytes()
}
示例6: renderAndWritePage
func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
err := s.render(name, d, renderBuffer, layouts...)
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
transformLinks := transform.NewEmptyTransforms()
if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") {
transformLinks = append(transformLinks, transform.AbsURL)
}
if s.Running() && viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
transformLinks = append(transformLinks, transform.LiveReloadInject)
}
var path []byte
if viper.GetBool("RelativeURLs") {
translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest)
if err != nil {
return err
}
path = []byte(helpers.GetDottedRelativePath(translated))
} else if viper.GetBool("CanonifyURLs") {
s := viper.GetString("BaseURL")
if !strings.HasSuffix(s, "/") {
s += "/"
}
path = []byte(s)
}
transformer := transform.NewChain(transformLinks...)
transformer.Apply(outBuffer, renderBuffer, path)
if err == nil {
if err = s.WriteDestPage(dest, outBuffer); err != nil {
return err
}
}
return err
}
示例7: ReaderToString
// ReaderToString is the same as ReaderToBytes, but returns a string.
func ReaderToString(lines io.Reader) string {
if lines == nil {
return ""
}
b := bp.GetBuffer()
defer bp.PutBuffer(b)
b.ReadFrom(lines)
return b.String()
}
示例8: ReaderToBytes
// ReaderToBytes takes an io.Reader argument, reads from it
// and returns bytes.
func ReaderToBytes(lines io.Reader) []byte {
b := bp.GetBuffer()
defer bp.PutBuffer(b)
b.ReadFrom(lines)
bc := make([]byte, b.Len(), b.Len())
copy(bc, b.Bytes())
return bc
}
示例9: renderShortcodeWithPage
func renderShortcodeWithPage(tmpl *template.Template, data *ShortcodeWithPage) string {
buffer := bp.GetBuffer()
defer bp.PutBuffer(buffer)
err := tmpl.Execute(buffer, data)
if err != nil {
jww.ERROR.Println("error processing shortcode", tmpl.Name(), "\n ERR:", err)
jww.WARN.Println(data)
}
return buffer.String()
}
示例10: doReplace
func doReplace(content []byte, matchers []absURLMatcher) []byte {
b := bp.GetBuffer()
defer bp.PutBuffer(b)
lexer := &contentlexer{content: content,
b: b,
prefixLookup: &prefixes{pr: mainPrefixRunes},
matchers: matchers}
lexer.replace()
return b.Bytes()
}
示例11: renderShortcodeWithPage
func renderShortcodeWithPage(tmpl *template.Template, data *ShortcodeWithPage) string {
buffer := bp.GetBuffer()
defer bp.PutBuffer(buffer)
// TODO(bep) Refactor/rename this lock strategy
isInnerShortcodeCache.Lock()
defer isInnerShortcodeCache.Unlock()
err := tmpl.Execute(buffer, data)
if err != nil {
jww.ERROR.Println("error processing shortcode", tmpl.Name(), "\n ERR:", err)
jww.WARN.Println(data)
}
return buffer.String()
}
示例12: BenchmarkEmojiKyokomiFprint
func BenchmarkEmojiKyokomiFprint(b *testing.B) {
f := func(in []byte) []byte {
buff := bufferpool.GetBuffer()
defer bufferpool.PutBuffer(buff)
emoji.Fprint(buff, string(in))
bc := make([]byte, buff.Len(), buff.Len())
copy(bc, buff.Bytes())
return bc
}
doBenchmarkEmoji(b, f)
}
示例13: Apply
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
buffer := bp.GetBuffer()
defer bp.PutBuffer(buffer)
buffer.ReadFrom(r)
b := buffer.Bytes()
for _, tr := range *c {
b = tr(b)
}
buffer.Reset()
buffer.Write(b)
buffer.WriteTo(w)
return
}
示例14: Apply
func (c *chain) Apply(w io.Writer, r io.Reader, p []byte) error {
b1 := bp.GetBuffer()
defer bp.PutBuffer(b1)
b1.ReadFrom(r)
if len(*c) == 0 {
b1.WriteTo(w)
return nil
}
b2 := bp.GetBuffer()
defer bp.PutBuffer(b2)
fb := &fromToBuffer{path: p, from: b1, to: b2}
for i, tr := range *c {
if i > 0 {
if fb.from == b1 {
fb.from = b2
fb.to = b1
fb.to.Reset()
} else {
fb.from = b1
fb.to = b2
fb.to.Reset()
}
}
tr(fb)
}
fb.to.WriteTo(w)
return nil
}
示例15: renderAndWriteXML
func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n")
err := s.render(name, d, renderBuffer, layouts...)
absURLInXML, err := transform.AbsURLInXML(viper.GetString("BaseUrl"))
if err != nil {
return err
}
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
transformer := transform.NewChain(absURLInXML...)
transformer.Apply(outBuffer, renderBuffer)
if err == nil {
err = s.WriteDestFile(dest, outBuffer)
}
return err
}