<commit_before>package flotilla

import "fmt"

type (
	// TData is a map sent to and accessible within the template, by the
	// builtin rendertemplate function.
	TData map[string]interface{}

	ctxprc func(*Ctx) string
)

func templatedata(any interface{}) TData {
	if rcvd, ok := any.(map[string]interface{}); ok {
		td := rcvd
		fmt.Printf("any IS a map\n")
		return td
	} else {
		td := make(map[string]interface{})
		td["Any"] = any
		fmt.Printf("any IS NOT a map\n")
		return td
	}
}

func TemplateData(ctx *Ctx, any interface{}) TData {
	td := templatedata(any)
	td["Ctx"] = ctx
	td["Request"] = ctx.Request
	td["Session"] = ctx.Session
	td["Data"] = ctx.Data
	td["Flash"] = allflashmessages(ctx)
	td.ContextProcessors(ctx)
	return td
}

// GetFlashMessages gets flash messages stored with TData by category.
func (t TData) GetFlashMessages(categories ...string) []string {
	var ret []string
	if fls, ok := t["Flash"].(map[string]string); ok {
		for k, v := range fls {
			if existsIn(k, categories) {
				ret = append(ret, v)
			}
		}
	}
	return ret
}

// ContextProcessor takes any context processor function and returns the
// the resulting string, or "" in the event of a problem with processing
func (t TData) ContextProcessor(fn ctxprc) string {
	if tctx, ok := t["Ctx"].(*Ctx); ok {
		x := fn(tctx)
		return x
	}
	return ""
}

func (t TData) ContextProcessors(ctx *Ctx) {
	if ctx.ctxprocessors != nil {
		for k, v := range ctx.ctxprocessors {
			if v, ok := v.(ctxprc); ok {
				t[k] = t.ContextProcessor(v)
			}
		}
	}
}
<commit_msg>template data return refactor & change<commit_after>package flotilla

type (
	// TData is a map sent to and accessible within the template, by the
	// builtin rendertemplate function.
	TData map[string]interface{}

	ctxprc func(*Ctx) string
)

func templatedata(any interface{}) TData {
	if rcvd, ok := any.(map[string]interface{}); ok {
		td := rcvd
		return td
	} else {
		td := make(map[string]interface{})
		td["Any"] = any
		return td
	}
}

func TemplateData(ctx *Ctx, any interface{}) TData {
	td := templatedata(any)
	td["Ctx"] = ctx
	td["Request"] = ctx.Request
	td["Session"] = ctx.Session
	td["Data"] = ctx.Data
	td["Flash"] = allflashmessages(ctx)
	td.ContextProcessors(ctx)
	return td
}

// GetFlashMessages gets flash messages stored with TData by category.
func (t TData) GetFlashMessages(categories ...string) []string {
	var ret []string
	if fls, ok := t["Flash"].(map[string]string); ok {
		for k, v := range fls {
			if existsIn(k, categories) {
				ret = append(ret, v)
			}
		}
	}
	return ret
}

// ContextProcessor takes any context processor function and returns the
// the resulting string, or "" in the event of a problem with processing
func (t TData) ContextProcessor(fn ctxprc) string {
	if tctx, ok := t["Ctx"].(*Ctx); ok {
		x := fn(tctx)
		return x
	}
	return ""
}

func (t TData) ContextProcessors(ctx *Ctx) {
	if ctx.ctxprocessors != nil {
		for k, v := range ctx.ctxprocessors {
			if v, ok := v.(ctxprc); ok {
				t[k] = t.ContextProcessor(v)
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.143233454066513, 'fraction_numerical': 0.0, 'mean_word_length': 3.6595092024539877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7344322', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1081, 'n_words': 331}