MCPcopy Create free account
hub / github.com/unrolled/render / HTML

Method HTML

render.go:517–559  ·  view source on GitHub ↗

HTML builds up the response from the specified template and bindings.

(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions)

Source from the content-addressed store, hash-verified

515
516// HTML builds up the response from the specified template and bindings.
517func (r *Render) HTML(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions) error {
518 // If we are in development mode, recompile the templates on every HTML request.
519 r.lock.RLock() // rlock here because we're reading the hasWatcher
520 if r.opt.IsDevelopment && !r.hasWatcher {
521 r.lock.RUnlock() // runlock here because CompileTemplates will lock
522 r.CompileTemplates()
523 r.lock.RLock()
524 }
525
526 templates := r.templates
527 r.lock.RUnlock()
528
529 opt := r.prepareHTMLOptions(htmlOpt)
530 if tpl := templates.Lookup(name); tpl != nil {
531 if len(opt.Layout) > 0 {
532 tpl.Funcs(r.layoutFuncs(templates, name, binding))
533 name = opt.Layout
534 }
535
536 if len(opt.Funcs) > 0 {
537 tpl.Funcs(opt.Funcs)
538 }
539 }
540
541 ct := r.opt.HTMLContentType + r.compiledCharset
542 if opt.ContentType != "" {
543 ct = opt.ContentType
544 }
545
546 head := Head{
547 ContentType: ct,
548 Status: status,
549 }
550
551 h := HTML{
552 Head: head,
553 Name: name,
554 Templates: templates,
555 bp: r.opt.BufferPool,
556 }
557
558 return r.Render(w, h, binding)
559}
560
561// JSON marshals the given interface object and writes the JSON response.
562func (r *Render) JSON(w io.Writer, status int, v interface{}, opts ...CallOptions) error {

Callers 15

TestRenderPartialFunction · 0.80
TestIOFSEmbedHTMLBasicFunction · 0.80
TestIOFSDirHTMLBasicFunction · 0.80
BenchmarkHTMLFunction · 0.80
layoutFuncsMethod · 0.80
TestHTMLBadFunction · 0.80
TestHTMLBasicFunction · 0.80
BenchmarkBigHTMLBuffersFunction · 0.80

Calls 6

CompileTemplatesMethod · 0.95
prepareHTMLOptionsMethod · 0.95
layoutFuncsMethod · 0.95
RenderMethod · 0.95
RLockMethod · 0.65
RUnlockMethod · 0.65

Tested by 15

TestRenderPartialFunction · 0.64
TestIOFSEmbedHTMLBasicFunction · 0.64
TestIOFSDirHTMLBasicFunction · 0.64
BenchmarkHTMLFunction · 0.64
TestHTMLBadFunction · 0.64
TestHTMLBasicFunction · 0.64
BenchmarkBigHTMLBuffersFunction · 0.64
TestHTMLXHTMLFunction · 0.64