<commit_before>package render

import (
	"fmt"
	"github.com/huangjunwen/JustSQL/context"
	"github.com/huangjunwen/JustSQL/handler"
	"io"
	"reflect"
	"text/template"
)

// Renderer contains templates to render object.
type Renderer struct {
	defaultTmpl *template.Template
	tmpl        *template.Template
}

func (r *Renderer) Run(dot interface{}, w io.Writer) error {
	tmpl := r.tmpl
	if tmpl == nil {
		tmpl = r.defaultTmpl
	}
	return tmpl.Execute(w, dot)
}

func (r *Renderer) AddTemplate(tmpl_name, tmpl_text string) error {
	if tmpl, err := r.defaultTmpl.New(tmpl_name); err != nil {
		return err
	} else {
		if tmpl_name == "" {
			r.tmpl = tmpl
		}
		return nil
	}
}

// Map type -> Renderer<commit_msg>Fix bugs in render.go<commit_after>package render

import (
	"fmt"
	"github.com/huangjunwen/JustSQL/context"
	"github.com/huangjunwen/JustSQL/handler"
	"io"
	"reflect"
	"text/template"
)

// Renderer contains templates to render object.
type Renderer struct {
	defaultTmpl *template.Template
	tmpl        *template.Template
}

func (r *Renderer) Run(dot interface{}, w io.Writer) error {
	tmpl := r.tmpl
	if tmpl == nil {
		tmpl = r.defaultTmpl
	}
	return tmpl.Execute(w, dot)
}

func (r *Renderer) AddTemplate(tmpl_name, tmpl_text string) error {
	tmpl := r.defaultTmpl.New(tmpl_name)
	if _, err := tmpl.Parse(tmpl_text); err != nil {
		return err
	} else {
		if tmpl_name == "" {
			r.tmpl = tmpl
		}
		return nil
	}
}

// Map type -> Renderer
{'fraction_non_alphanumeric': 0.13204951856946354, 'fraction_numerical': 0.0, 'mean_word_length': 3.546875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2708172', 'n_tokens_mistral': 583, 'n_tokens_neox': 558, 'n_words': 133}