github.com/haraldLmueller/buffalo@v0.11.1/render/html.go (about)

     1  package render
     2  
     3  import (
     4  	"html"
     5  
     6  	"github.com/gobuffalo/plush"
     7  	"github.com/shurcooL/github_flavored_markdown"
     8  )
     9  
    10  // HTML renders the named files using the 'text/html'
    11  // content type and the github.com/gobuffalo/plush
    12  // package for templating. If more than 1 file is provided
    13  // the second file will be considered a "layout" file
    14  // and the first file will be the "content" file which will
    15  // be placed into the "layout" using "<%= yield %>".
    16  func HTML(names ...string) Renderer {
    17  	e := New(Options{})
    18  	return e.HTML(names...)
    19  }
    20  
    21  // HTML renders the named files using the 'text/html'
    22  // content type and the github.com/gobuffalo/plush
    23  // package for templating. If more than 1 file is provided
    24  // the second file will be considered a "layout" file
    25  // and the first file will be the "content" file which will
    26  // be placed into the "layout" using "<%= yield %>". If no
    27  // second file is provided and an `HTMLLayout` is specified
    28  // in the options, then that layout file will be used
    29  // automatically.
    30  func (e *Engine) HTML(names ...string) Renderer {
    31  	if e.HTMLLayout != "" && len(names) == 1 {
    32  		names = append(names, e.HTMLLayout)
    33  	}
    34  	hr := &templateRenderer{
    35  		Engine:      e,
    36  		contentType: "text/html",
    37  		names:       names,
    38  	}
    39  	return hr
    40  }
    41  
    42  // MDTemplateEngine runs the input through github flavored markdown before sending it to the Plush engine.
    43  func MDTemplateEngine(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error) {
    44  	if ct, ok := data["contentType"].(string); ok && ct == "text/plain" {
    45  		return plush.BuffaloRenderer(string(input), data, helpers)
    46  	}
    47  	source := github_flavored_markdown.Markdown([]byte(input))
    48  	source = []byte(html.UnescapeString(string(source)))
    49  	return plush.BuffaloRenderer(string(source), data, helpers)
    50  }