// MustRender renders the template into the output writer or panics.
//
// It never writes partial output. It also panics if attempt to write to
// the output fails.
769558
func MustRender(c context.Context, out io.Writer, name string, args Args) {
	if b, _ := c.Value(&contextKey).(*boundBundle); b != nil {
		b.MustRender(c, b.Extra, out, name, args)
		return
	}
	panic(errNoBundle)
}
40846
func (nap *NapNap) SetRender(templateRootPath string) {
	sharedTemplatePath := path.Join(templateRootPath, "shares/*")
	tmpl, err := template.ParseGlob(sharedTemplatePath)
	template := template.Must(tmpl, err)
	if template == nil {
		_logger.debug("no template")
		template = template.New("")
	}
	nap.template = template
	nap.templateRootPath = templateRootPath
}
515952
func (tm *TaskTemplateManager) handleFirstRender() {
	// missingDependencies is the set of missing dependencies.
	var missingDependencies map[string]struct{}

	// eventTimer is used to trigger the firing of an event showing the missing
	// dependencies.
	eventTimer := time.NewTimer(tm.config.MaxTemplateEventRate)
	if !eventTimer.Stop() {
		<-eventTimer.C
	}

	// outstandingEvent tracks whether there is an outstanding event that should
	// be fired.
	outstandingEvent := false

	// Wait till all the templates have been rendered
WAIT:
	for {
		select {
		case <-tm.shutdownCh:
			return
		case err, ok := <-tm.runner.ErrCh:
			if !ok {
				continue
			}

			tm.config.Lifecycle.Kill(context.Background(),
				structs.NewTaskEvent(structs.TaskKilling).
					SetFailsTask().
					SetDisplayMessage(fmt.Sprintf("Template failed: %v", err)))
		case <-tm.runner.TemplateRenderedCh():
			// A template has been rendered, figure out what to do
			events := tm.runner.RenderEvents()

			// Not all templates have been rendered yet
			if len(events) < len(tm.lookup) {
				continue
			}

			for _, event := range events {
				// This template hasn't been rendered
				if event.LastWouldRender.IsZero() {
					continue WAIT
				}
			}

			break WAIT
		case <-tm.runner.RenderEventCh():
			events := tm.runner.RenderEvents()
			joinedSet := make(map[string]struct{})
			for _, event := range events {
				missing := event.MissingDeps
				if missing == nil {
					continue
				}

				for _, dep := range missing.List() {
					joinedSet[dep.String()] = struct{}{}
				}
			}

			// Check to see if the new joined set is the same as the old
			different := len(joinedSet) != len(missingDependencies)
			if !different {
				for k := range joinedSet {
					if _, ok := missingDependencies[k]; !ok {
						different = true
						break
					}
				}
			}

			// Nothing to do
			if !different {
				continue
			}

			// Update the missing set
			missingDependencies = joinedSet

			// Update the event timer channel
			if !outstandingEvent {
				// We got new data so reset
				outstandingEvent = true
				eventTimer.Reset(tm.config.MaxTemplateEventRate)
			}
		case <-eventTimer.C:
			if missingDependencies == nil {
				continue
			}

			// Clear the outstanding event
			outstandingEvent = false

			// Build the missing set
			missingSlice := make([]string, 0, len(missingDependencies))
			for k := range missingDependencies {
				missingSlice = append(missingSlice, k)
			}
			sort.Strings(missingSlice)

			if l := len(missingSlice); l > missingDepEventLimit {
				missingSlice[missingDepEventLimit] = fmt.Sprintf("and %d more", l-missingDepEventLimit)
				missingSlice = missingSlice[:missingDepEventLimit+1]
			}

			missingStr := strings.Join(missingSlice, ", ")
			tm.config.Events.EmitEvent(structs.NewTaskEvent(consulTemplateSourceName).SetDisplayMessage(fmt.Sprintf("Missing: %s", missingStr)))
		}
	}
}
757992
func MustCompile(sel string) Selector {
	compiled, err := Compile(sel)
	if err != nil {
		panic(err)
	}
	return compiled
}
170258
func (document *Document) InitializeForRendering(arguments string) {
	cArguments := C.CString(arguments)
	defer C.free(unsafe.Pointer(cArguments))
	C.initialize_for_rendering(document.handle, cArguments)
}
951847
func XMLRender(status int, indent bool, data interface{}, prefix []byte) *XML {
	return &XML{
		Indent: indent,
		Prefix: prefix,
		Data:   data,
		Head: &Head{
			Status:  status,
			Content: ContentXML,
		},
	}
}
61655
func (r *Templater) Render(content string, context map[string]interface{}, snippets map[string]string, failOnMissing bool) (rendered string, err error) {
	// @step: create the template
	tm := template.New(templateName)
	if _, err = tm.Funcs(r.templateFuncsMap(tm)).Parse(content); err != nil {
		return
	}
	if failOnMissing {
		tm.Option("missingkey=error")
	}

	// @step: add the snippits into the mix
	for filename, snippet := range snippets {
		if filename == templateName {
			return "", fmt.Errorf("snippet cannot have the same name as the template: %s", filename)
		}
		if _, err = tm.New(filename).Parse(snippet); err != nil {
			return rendered, fmt.Errorf("unable to parse snippet: %s, error: %s", filename, err)
		}
	}

	// @step: render the actual template
	writer := new(bytes.Buffer)
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("failed to parse template, error: %s", r)
		}
	}()
	if err = tm.ExecuteTemplate(writer, templateName, context); err != nil {
		return
	}

	return writer.String(), nil
}
1206933
func (r *RenderTemplateResult) renderOutput(wr io.Writer) (err error) {
	defer func() {
		if rerr := recover(); rerr != nil {
			resultsLog.Error("ApplyBytes: panic recovery", "recover-error", rerr)
			err = fmt.Errorf("Template Execution Panic in %s:\n%s", r.Template.Name(), rerr)
		}
	}()
	err = r.Template.Render(wr, r.ViewArgs)
	return
}
612241
func (t *Template) Render(w io.Writer, context ...interface{}) error {
	return t.render(newWriter(w), context...)
}
426257
func MustMarshal(object interface{}, options JSONOptions) []byte {
	output, err := json.Marshal(&object)

	if err != nil {
		panic(err)
	}

	switch {
	case options.Indent:
		buffer := bytes.Buffer{}

		// TODO(@kobolog): Expose indentation options via JSONOptions.
		json.Indent(&buffer, output, "", "\t")

		return buffer.Bytes()

	default:
		return output
	}
}
1022403
func MustParse(source string) *Template {
	result, err := Parse(source)
	if err != nil {
		panic(err)
	}
	return result
}
105553
func (t *TemplateManager) Render(w io.Writer, name string, data interface{}) error {
	stack := []*Template{}
	tplSrc, err := t.getSrc(name)
	if err != nil {
		return err
	}
	err = t.push(&stack, tplSrc, name)
	if err != nil {
		return err
	}
	tpl, err := t.assemble(stack)
	if err != nil {
		return err
	}
	if err != nil {
		return err
	}

	if tpl == nil {
		return Errorf("Nil template named %s", name)
	}

	err = tpl.Execute(w, data)
	if err != nil {
		return err
	}

	return nil
}
454329
func (r *Render) Html(w http.ResponseWriter, status int, name string, binding interface{}) error {
	if r.opt.IsDevelopment {
		r.compile()
	}

	if tSet, ok := r.templates[name]; !ok {
		return fmt.Errorf("Cannot find template %q in Render", name)
	} else {
		if r.opt.UseBufPool {
			buf := r.bufPool.Get()
			if err := tSet.template.Execute(buf, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := buf.WriteTo(w)
			r.bufPool.Put(buf)
			return err
		} else {
			out := new(bytes.Buffer)
			if err := tSet.template.Execute(out, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := io.Copy(w, out)
			return err
		}
	}
}
640322
func RenderTemplateToStream(output io.Writer, srcPath []string, data interface{}) (err error) {
	tmpl, err := template.ParseFiles(srcPath...)
	if err != nil {
		return NewBuildIfError(err, "Failed to parse template "+srcPath[0])
	}

	err = tmpl.Execute(output, data)
	if err != nil {
		return NewBuildIfError(err, "Failed to render template "+srcPath[0])
	}
	return
}
330738
func (r *Renderer) RenderEvent(event *TaskEvent) string {
	switch event.Type {
	case "eos":
		return ""
	}

	s := ""

	if r.options.showTime {
		s += fmt.Sprintf("(%s) ", time.Unix(0, event.Time).Format(time.UnixDate))
	}

	if event.Thread != "" {
		s += fmt.Sprintf("[%s] -- ", event.Thread)
	}

	s += fmt.Sprintf("%s", event.Stage)

	if event.Subtask.Name != "" {
		s += " -- "
		if event.Subtask.Total != 0 {
			s += fmt.Sprintf("(%d/%d): ", event.Subtask.Index, event.Subtask.Total)
		}

		s += fmt.Sprintf("%s", event.Subtask.Name)

		if event.Subtask.Progress.Total != 0 {
			s += fmt.Sprintf(" ... %d%%",
				(event.Subtask.Progress.Current/event.Subtask.Progress.Total)*100,
			)
		}
	}

	return s
}
204084
func (b *batchRenderer) render(startTime float64) {
	// If the batch is empty, mark as unscheduled, and stop render cycle.
	if len(b.batch) == 0 {
		b.scheduled = false
		return
	}

	// Drain the current batch.
	pending := b.batch
	b.batch = nil
	b.idx = make(map[Component]int)

	// Process batch.
	for i, c := range pending {
		// Skip unmounted components.
		if c.Context().unmounted {
			continue
		}

		// Check for remaining time budget, targeting 60fps (~16ms per frame).
		if i > 0 {
			elapsed := global.Get("performance").Call("now").Float() - startTime
			budgetRemaining := (1000 / 60) - elapsed
			avgRenderTime := elapsed / float64(i)
			// If the budget remaining is less than 2 times the average
			// Component render time, push the remainder of the batch to the
			// next frame.
			if budgetRemaining < avgRenderTime*2 {
				b.batch = pending[i:]
				for i, c := range b.batch {
					b.idx[c] = i
				}
				break
			}
		}

		// Perform render.
		prevHTML := extractHTML(c.Context().prevRender)
		nextHTML, skip, pendingMounts := renderComponent(c, c)
		if skip {
			continue
		}
		replaceNode(nextHTML.node, prevHTML.node)
		mount(pendingMounts...)
	}

	// Schedule next frame.
	requestAnimationFrame(b.render)
}
711030
func NewHTMLTemplateRendererWithProvider(writer http.ResponseWriter, provider HTMLTemplateProvider) *HTMLTemplateRenderer {
	return &HTMLTemplateRenderer{
		writer:   writer,
		provider: provider,
	}
}