<commit_before>package renderer

import (
	"bufio"
	"bytes"
	"io"
	"os"
	"path/filepath"
	"text/template"

	"github.com/joefitzgerald/inductor/tpl"
)

type engine struct {
	renderOptions *RenderOptions
	outDir        string
}

// New creates a new Renderer instance
func New(opts *RenderOptions, outDir string) Renderer {
	return &engine{
		renderOptions: opts,
		outDir:        outDir,
	}
}

// Render generates the packer.json and Autounattend.xml files used by Packer
func (e *engine) Render(tc tpl.TemplateContainer) error {
	for _, t := range tc.ListTemplates() {
		tOutPath := filepath.Join(e.outDir, t.BaseFilename())
		tOutFile, err := os.Create(tOutPath)
		if err != nil {
			return err
		}
		defer tOutFile.Close()
		tOutWriter := bufio.NewWriter(tOutFile)
		e.renderTemplate(t, tOutWriter)
	}
	return nil
}
<commit_msg>Extract writeFile method<commit_after>package renderer

import (
	"bufio"
	"bytes"
	"io"
	"os"
	"path/filepath"
	"text/template"

	"github.com/joefitzgerald/inductor/tpl"
)

type engine struct {
	renderOptions *RenderOptions
	outDir        string
}

// New creates a new Renderer instance
func New(opts *RenderOptions, outDir string) Renderer {
	return &engine{
		renderOptions: opts,
		outDir:        outDir,
	}
}

// Render generates the packer.json and Autounattend.xml files used by Packer
func (e *engine) Render(tc tpl.TemplateContainer) error {
	for _, t := range tc.ListTemplates() {
		if err := e.writeTemplate(t); err != nil {
			return err
		}
	}
	return nil
}

func (e *engine) writeTemplate(t tpl.Templater) error {
	f, err := os.Create(filepath.Join(e.outDir, t.BaseFilename()))
	if err != nil {
		return err
	}
	defer f.Close()
	w := bufio.NewWriter(f)
	e.renderTemplate(t, w)
	return nil
}

{'fraction_non_alphanumeric': 0.11866359447004608, 'fraction_numerical': 0.0, 'mean_word_length': 3.7851239669421486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2836707', 'n_tokens_mistral': 652, 'n_tokens_neox': 638, 'n_words': 163}