<commit_before>package ufront.web.mvc;
import thx.error.NullArgument;
import thx.error.Error;
import ufront.web.mvc.ViewContext;
using Types;

class ViewResult extends ActionResult
{
	public var view : IView;
	public var viewData : Hash<Dynamic>;
	public var viewName : String;

	public function new(?data : Hash<Dynamic>, ?dataObj : {})
	{
		if (null == data)
			viewData = new Hash();
		else
			viewData = data;
		if (null != dataObj)
			Hashes.importObject(viewData, dataObj);
	}

	function createContext(result : ViewEngineResult, controllerContext : ControllerContext)
	{
		return new ViewContext(controllerContext, view, result.viewEngine, viewData, controllerContext.controller.getViewHelpers());
	}

	override function executeResult(context : ControllerContext)
	{
		NullArgument.throwIfNull(context);

		if(null == viewName || "" == viewName)
			viewName = context.routeData.getRequired("action");
		var result = null;
		if(null == view)
		{
			result = findView(context, viewName);
			if(null == result)
				throw new Error("unable to find a view for '{0}'", context.controller.typeName() + "/" + viewName);
            this.view = result.view;
		}
		var viewContext = createContext(result, context);
		var data = new Hash();
		var r = null;
		try {
			r = view.render(viewContext, data);
		} catch(e : Dynamic) {
			throw new Error("error in the template processing: {0}", Std.string(e));
		}
		writeResponse(context, r, data);
		if(null != result)
			result.viewEngine.releaseView(context, view);
	}

	function writeResponse(context : ControllerContext, content : String, data : Hash<Dynamic>)<commit_msg>Change hash to StringMap<commit_after>package ufront.web.mvc;
import thx.error.NullArgument;
import thx.error.Error;
import ufront.web.mvc.ViewContext;
import haxe.ds.StringMap;
using Types;

class ViewResult extends ActionResult
{
	public var view : IView;
	public var viewData : Hash<Dynamic>;
	public var viewName : String;

	public function new(?data : Hash<Dynamic>, ?dataObj : {})
	{
		if (null == data)
			viewData = new StringMap();
		else
			viewData = data;
		if (null != dataObj)
			Hashes.importObject(viewData, dataObj);
	}

	function createContext(result : ViewEngineResult, controllerContext : ControllerContext)
	{
		return new ViewContext(controllerContext, view, result.viewEngine, viewData, controllerContext.controller.getViewHelpers());
	}

	override function executeResult(context : ControllerContext)
	{
		NullArgument.throwIfNull(context);

		if(null == viewName || "" == viewName)
			viewName = context.routeData.getRequired("action");
		var result = null;
		if(null == view)
		{
			result = findView(context, viewName);
			if(null == result)
				throw new Error("unable to find a view for '{0}'", context.controller.typeName() + "/" + viewName);
            this.view = result.view;
		}
		var viewContext = createContext(result, context);
		var data = new StringMap();
		var r = null;
		try {
			r = view.render(viewContext, data);
		} catch(e : Dynamic) {
			throw new Error("error in the template processing: {0}", Std.string(e));
		}
		writeResponse(context, r, data);
		if(null != result)
			result.viewEngine.releaseView(context, view);
	}

	function writeResponse(context : ControllerContext, content : String, data : Hash<Dynamic>)
{'fraction_non_alphanumeric': 0.12526668698567509, 'fraction_numerical': 0.0012191405059433099, 'mean_word_length': 4.3980263157894735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3607191', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1002, 'n_words': 264}