<commit_before><?php

/**
 * This file is part of the Nextras community extensions of Nette Framework
 *
 * @license    MIT
 * @link       https://github.com/nextras/forms
 * @author     <NAME>
 */

namespace Nextras\Forms\Controls\Fragments;

use Nette;
use Nette\Application\UI\IRenderable;
use Nette\Application\UI\ITemplate;
use Nette\Application\UI\ITemplateFactory;
use Nette\Application\UI\Presenter;
use Nette\Bridges\ApplicationLatte\Template;


/**
 * TemplateControlTrait
 * @author <NAME>
 */
trait TemplateControlTrait
{
	use ComponentControlTrait;


	/** @var string */
	protected $templateFile;


	public function setTemplateFile($file)
	{
		if (!file_exists($file)) {
			throw new Nette\InvalidArgumentException("File does not exists '$file'.");
		}

		$this->templateFile = $file;
		return $this;
	}


	public function getTemplateFile()
	{
		return $this->templateFile;
	}


	/**
	 * Returns form control
	 * @return Nette\Utils\Html
	 */
	public function getControl()
	{
		$this->control->setHtml($this->toString());
		return $this->control;
	}


	/**
	 * Common render method.
	 * @return void
	 */
	protected function beforeRender()
	{
	}


	/**
	 * Renders form control
	 * @return void
	 */
	public function render()
	{
		echo $this->toString();
	}


	/**
	 * Returns rendered template
	 * @return string
	 */
	public function toString()
	{
		$this->beforeRender();
		return (string) $this->getTemplate();
	}


	/**** Application\UI\Control **************************************************************************************/<commit_msg>TemplateControlTrait: fixed template initialization in beforeRender<commit_after><?php

/**
 * This file is part of the Nextras community extensions of Nette Framework
 *
 * @license    MIT
 * @link       https://github.com/nextras/forms
 * @author     <NAME>
 */

namespace Nextras\Forms\Controls\Fragments;

use Nette;
use Nette\Application\UI\IRenderable;
use Nette\Application\UI\ITemplate;
use Nette\Application\UI\ITemplateFactory;
use Nette\Application\UI\Presenter;
use Nette\Bridges\ApplicationLatte\Template;


/**
 * TemplateControlTrait
 * @author <NAME>
 */
trait TemplateControlTrait
{
	use ComponentControlTrait;


	/** @var string */
	protected $templateFile;


	public function setTemplateFile($file)
	{
		if (!file_exists($file)) {
			throw new Nette\InvalidArgumentException("File does not exists '$file'.");
		}

		$this->templateFile = $file;
		return $this;
	}


	public function getTemplateFile()
	{
		return $this->templateFile;
	}


	/**
	 * Returns form control
	 * @return Nette\Utils\Html
	 */
	public function getControl()
	{
		$this->control->setHtml($this->toString());
		return $this->control;
	}


	/**
	 * Common render method.
	 * @return void
	 */
	protected function beforeRender()
	{
	}


	/**
	 * Renders form control
	 * @return void
	 */
	public function render()
	{
		echo $this->toString();
	}


	/**
	 * Returns rendered template
	 * @return string
	 */
	public function toString()
	{
		$template = $this->getTemplate();
		$this->beforeRender();
		return (string) $template;
	}


	/**** Application\UI\Control **************************************************************************************/
{'fraction_non_alphanumeric': 0.18389010302841086, 'fraction_numerical': 0.0, 'mean_word_length': 3.847201210287443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '3741225', 'n_tokens_mistral': 1042, 'n_tokens_neox': 952, 'n_words': 221}