// Render the current page as a PDF document, writing it to the given filename or writable
// destination object.
491588
func (self *Commands) Pdf(destination interface{}, args *PdfArgs) error {
	var dest io.Writer

	if args == nil {
		args = &PdfArgs{}
	}

	defaults.SetDefaults(args)

	switch destination.(type) {
	case string:
		filename := destination.(string)

		if _, w, ok := self.browser.GetWriterForPath(filename); ok {
			dest = w
		} else if d, err := os.Create(filename); err == nil {
			dest = d
		} else {
			return err
		}
	case io.Writer:
		dest = destination.(io.Writer)
	default:
		return fmt.Errorf("Must specify either a filename or io.Writer destination")
	}

	if dest == nil {
		return fmt.Errorf("A destination for the PDF must be specified")
	}

	if rv, err := self.browser.Tab().RPC(`Page`, `printToPDF`, map[string]interface{}{
		`scale`: 1,
	}); err == nil {
		if dataS := maputil.M(rv.Result).String(`data`); len(dataS) > 0 {
			if data, err := base64.StdEncoding.DecodeString(dataS); err == nil {
				_, err := dest.Write(data)

				if closer, ok := dest.(io.Closer); ok {
					if err := closer.Close(); err == nil {
						log.Debugf("Destination file closed.")
					} else {
						return err
					}
				}

				return err
			} else {
				return fmt.Errorf("decode error: %v", err)
			}
		} else {
			return fmt.Errorf("Empty response")
		}
	} else {
		return err
	}
}
638452
func (ct *CompiledTemplate) Render(name string, source structs.QuerySource) (*structs.PreparedQuery, error) {
	// Make it "safe" to render a default structure.
	if ct == nil {
		return nil, fmt.Errorf("Cannot render an uncompiled template")
	}

	// Start with a fresh, detached copy of the original so we don't disturb
	// the prototype.
	dup, err := copystructure.Copy(ct.query)
	if err != nil {
		return nil, err
	}
	query, ok := dup.(*structs.PreparedQuery)
	if !ok {
		return nil, fmt.Errorf("Failed to copy query")
	}

	// Run the regular expression, if provided. We execute on a copy here
	// to avoid internal lock contention because we expect this to be called
	// from multiple goroutines.
	var matches []string
	if ct.re != nil {
		re := ct.re.Copy()
		matches = re.FindStringSubmatch(name)
	}

	// Create a safe match function that can't fail at run time. It will
	// return an empty string for any invalid input.
	match := ast.Function{
		ArgTypes:   []ast.Type{ast.TypeInt},
		ReturnType: ast.TypeString,
		Variadic:   false,
		Callback: func(inputs []interface{}) (interface{}, error) {
			i, ok := inputs[0].(int)
			if ok && i >= 0 && i < len(matches) {
				return matches[i], nil
			}
			return "", nil
		},
	}

	// Build up the HIL evaluation context.
	config := &hil.EvalConfig{
		GlobalScope: &ast.BasicScope{
			VarMap: map[string]ast.Variable{
				"name.full": ast.Variable{
					Type:  ast.TypeString,
					Value: name,
				},
				"name.prefix": ast.Variable{
					Type:  ast.TypeString,
					Value: query.Name,
				},
				"name.suffix": ast.Variable{
					Type:  ast.TypeString,
					Value: strings.TrimPrefix(name, query.Name),
				},
				"agent.segment": ast.Variable{
					Type:  ast.TypeString,
					Value: source.Segment,
				},
			},
			FuncMap: map[string]ast.Function{
				"match": match,
			},
		},
	}

	// Run through the Service sub-structure and evaluate all the strings
	// as HIL.
	eval := func(path string, v reflect.Value) error {
		tree, ok := ct.trees[path]
		if !ok {
			return nil
		}

		res, err := hil.Eval(tree, config)
		if err != nil {
			return fmt.Errorf("Bad evaluation for '%s' in Service%s: %s", v.String(), path, err)
		}
		if res.Type != hil.TypeString {
			return fmt.Errorf("Expected Service%s field to be a string, got %s", path, res.Type)
		}

		v.SetString(res.Value.(string))
		return nil
	}
	if err := walk(&query.Service, eval); err != nil {
		return nil, err
	}

	if ct.removeEmptyTags {
		tags := make([]string, 0, len(query.Service.Tags))
		for _, tag := range query.Service.Tags {
			if tag != "" {
				tags = append(tags, tag)
			}
		}
		query.Service.Tags = tags
	}

	return query, nil
}
28271
func (collection Collection) Render(context *qor.Context, name string, objects ...interface{}) template.HTML {
	seoSetting := collection.GetSEOSetting(context, name, objects...)
	return seoSetting.FormattedHTML(context)
}
867128
func Render(v string, ctx *Context) (string, error) {
	return (&I{Value: v}).Render(ctx)
}
459438
func (p *PageView) Render() vecty.ComponentOrHTML {
	return elem.Body(
		// Display a textarea on the right-hand side of the page.
		elem.Div(
			vecty.Markup(
				vecty.Style("float", "right"),
			),
			elem.TextArea(
				vecty.Markup(
					vecty.Style("font-family", "monospace"),
					vecty.Property("rows", 14),
					vecty.Property("cols", 70),

					// When input is typed into the textarea, update the local
					// component state and rerender.
					event.Input(func(e *vecty.Event) {
						p.Input = e.Target.Get("value").String()
						vecty.Rerender(p)
					}),
				),
				vecty.Text(p.Input), // initial textarea text.
			),
		),

		// Render the markdown.
		&Markdown{Input: p.Input},
	)
}
82950
func (r JSON) Render(w http.ResponseWriter) (err error) {
	if err = WriteJSON(w, r.Data); err != nil {
		panic(err)
	}
	return
}
672608
func (g *Generator) Render(templ string) ([]byte, error) {
	if g.loader == nil {
		g.loader = &symbols.Loader{Source: g.Starlark}
		g.links = map[string]*symbol{}
	}

	t, err := template.New("main").Funcs(g.funcMap()).Parse(templ)
	if err != nil {
		return nil, err
	}

	buf := bytes.Buffer{}
	if err := t.Execute(&buf, nil); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
867592
func (t *File_Template) Render(params map[string]*Value) (string, error) {
	sSet := stringset.New(len(params))
	replacementSlice := make([]string, 0, len(t.Param)*2)
	for k, param := range t.Param {
		replacementSlice = append(replacementSlice, k)
		if newVal, ok := params[k]; ok {
			if err := param.Accepts(newVal); err != nil {
				return "", fmt.Errorf("param %q: %s", k, err)
			}
			sSet.Add(k)
			replacementSlice = append(replacementSlice, newVal.JSONRender())
		} else if param.Default != nil {
			replacementSlice = append(replacementSlice, param.Default.JSONRender())
		} else {
			return "", fmt.Errorf("param %q: missing", k)
		}
	}
	if len(params) != sSet.Len() {
		unknown := make([]string, 0, len(params))
		for k := range params {
			if !sSet.Has(k) {
				unknown = append(unknown, k)
			}
		}
		sort.Strings(unknown)
		return "", fmt.Errorf("unknown parameters: %q", unknown)
	}

	r := strings.NewReplacer(replacementSlice...)

	return r.Replace(t.Body), nil
}
23614
func RenderTemplate(destPath, srcPath string, data interface{}) (err error) {
	tmpl, err := template.ParseFiles(srcPath)
	if err != nil {
		return NewBuildIfError(err, "Failed to parse template "+srcPath)
	}

	f, err := os.Create(destPath)
	if err != nil {
		return NewBuildIfError(err, "Failed to create  ", "path", destPath)
	}

	err = tmpl.Execute(f, data)
	if err != nil {
		return NewBuildIfError(err, "Failed to Render template "+srcPath)
	}

	err = f.Close()
	if err != nil {
		return NewBuildIfError(err, "Failed to close file stream "+destPath)
	}
	return
}
970251
func (s String) Render(resolve VariableResolver) (string, error) {
	var buff bytes.Buffer
	if err := s.RenderTo(&buff, resolve); err != nil {
		return "", err
	}
	return buff.String(), nil
}
1109350
func (f *File) Render(spec *templateproto.Specifier) (*dm.Quest_Desc, error) {
	t := f.Template[spec.TemplateName]
	params, err := t.Parameters.Render(spec.Params)
	if err != nil {
		return nil, fmt.Errorf("rendering %q: field distributor parameters: %s", spec.TemplateName, err)
	}
	distribParams, err := t.DistributorParameters.Render(spec.Params)
	if err != nil {
		return nil, fmt.Errorf("rendering %q: field distributor parameters: %s", spec.TemplateName, err)
	}
	return &dm.Quest_Desc{
		DistributorConfigName: t.DistributorConfigName,
		Parameters:            params,
		DistributorParameters: distribParams,
		Meta:                  t.Meta,
	}, nil
}
137555
func (r IndentedJSON) Render(w http.ResponseWriter) error {
	r.WriteContentType(w)
	jsonBytes, err := json.MarshalIndent(r.Data, "", "    ")
	if err != nil {
		return err
	}
	_, err = w.Write(jsonBytes)
	return err
}
396873
func (r *Renderer) Render(str []byte) []byte {
	bl, sl, el := len(r.begin), len(str), len(r.end)
	data := make([]byte, bl+sl+el)
	copy(data, r.begin)
	copy(data[bl:], str)
	copy(data[bl+sl:], r.end)
	return data
}
659187
func (c *Context) Render(code int, viewName string, data interface{}) error {
	c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
	c.Writer.WriteHeader(code)

	t, err := c.NapNap.template.Clone()
	if err != nil {
		return err
	}

	viewPath := path.Join(c.NapNap.templateRootPath, "views", viewName)
	t, err = t.ParseFiles(viewPath)
	if err != nil {
		return err
	}

	t.ExecuteTemplate(c.Writer, viewName, data)
	return nil
}
798725
func (g *Group) Render(writer io.Writer) error {
	return g.RenderWithFile(writer, NewFile(""))
}
366733
func Render(w http.ResponseWriter, data interface{}, rCode int, tpl *template.Template) {
	// In case of HTML response, setting appropriate header type for text/HTML response
	w.Header().Set(HeaderContentType, HTMLContentType)
	w.WriteHeader(rCode)

	// Rendering an HTML template with appropriate data
	err := tpl.Execute(w, data)
	if err != nil {
		LOGHANDLER.Error(err.Error())
	}
}
679808
func (r AsciiJSON) Render(w http.ResponseWriter) (err error) {
	r.WriteContentType(w)
	ret, err := json.Marshal(r.Data)
	if err != nil {
		return err
	}

	var buffer bytes.Buffer
	for _, r := range string(ret) {
		cvt := string(r)
		if r >= 128 {
			cvt = fmt.Sprintf("\\u%04x", int64(r))
		}
		buffer.WriteString(cvt)
	}

	_, err = w.Write(buffer.Bytes())
	return err
}