github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/render/string.go (about)

     1  package render
     2  
     3  import "io"
     4  
     5  type stringRenderer struct {
     6  	*Engine
     7  	body string
     8  }
     9  
    10  func (s stringRenderer) ContentType() string {
    11  	return "text/plain"
    12  }
    13  
    14  func (s stringRenderer) Render(w io.Writer, data Data) error {
    15  	t, err := s.TemplateEngine(s.body, data, s.Helpers)
    16  	if err != nil {
    17  		return err
    18  	}
    19  	_, err = w.Write([]byte(t))
    20  	return err
    21  }
    22  
    23  // String renderer that will run the string through
    24  // the github.com/aymerick/raymond package and return
    25  // "text/plain" as the content type.
    26  func String(s string) Renderer {
    27  	e := New(Options{})
    28  	return e.String(s)
    29  }
    30  
    31  // String renderer that will run the string through
    32  // the github.com/aymerick/raymond package and return
    33  // "text/plain" as the content type.
    34  func (e *Engine) String(s string) Renderer {
    35  	return stringRenderer{
    36  		Engine: e,
    37  		body:   s,
    38  	}
    39  }