<commit_before><?php

	/**
	 * The inKWELL view class
	 *
	 * Views are instantiated objects which loosely couple data to templated languages.  These
	 * objects are primarily designed to work with HTML, so a number of helper methods are provided
	 * to more easily work with markup.
	 *
	 * @author <NAME> [mjs] <<EMAIL>>
	 * @copyright Copyright (c) 2012, <NAME>
	 * @license Please reference the LICENSE.txt file at the root of this distribution
	 *
	 * @package inKWell
	 */
	class View extends fTemplating implements inkwell
	{
		const DEFAULT_VIEW_ROOT     = 'views';
		const DEFAULT_CACHE_DIR     = 'cache';
		const PRIMARY_VIEW_ELEMENT  = '__main__'; // This must match Flourish

		/**
		 * The path from which relative views are loaded
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $viewRoot = NULL;

		/**
		 * The path where cached views and compressed styles/scripts are stored
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $cacheDirectory = NULL;

		/**
		 * The minification mode for compressing styles/scripts
		 *
		 * @static
		 * @access private
		 * @var string|NULL
		 */
		static private $minificationMode = NULL;

		/**
		 * A simple factory method for creating new views based on a file.
		 *
		 * @static
		 * @access public
		 * @param string $view_file The file to load
		 * @return View The view object with the view file loaded
		 */
		static public function create($view_file)
		{
			$view = new self();
			return $view->load($view_file);
		}

		/**
		 * The data storage area
		 *
		 * @access private
		 * @var array
		 */
		private $data = array();

		/**
		 * A list of callbacks to call when render() is called
		 *
		 * @access private
		 * @var array
		 */
		private $renderCallbacks = array();

		/**
		 * If the template represents string content
		 *
		 * @access private
		 * @var boolean
		 */
		private $isFood = FALSE;

		/**
		 * Initializes the templating engine
		 *
		 * @static
		 * @access public
		 * @param array $config The configuration array
		 * @param string $element The element name of the configuration array
		 * @return void
		 */
		static public function __init(array $config = array(), $element = NULL)
		{

			self::$viewRoot = implode(DIRECTORY_SEPARATOR, array(
				iw::getRoot(),
				($root_directory = iw::getRoot($element))
					? $root_directory
					: self::DEFAULT_SCAFFOLDING_ROOT
			));

			self::$viewRoot       = new fDirectory(self::$viewRoot);
			self::$cacheDirectory = iw::getWriteDirectory(
				isset($config['cache_directory'])
					? $config['cache_directory']
					: self::DEFAULT_CACHE_DIRECTORY
			);

			try {
				self::$cacheDirectory = new fDirectory(self::$cacheDirectory);
			} catch (fValidationException $e) {
				throw new fEnvironmentException (
					'Cache directory %s does not exist',
					self::$cacheDirectory
				);
			}

			if (!self::$cacheDirectory->isWritable()) {
				throw new fEnvironmentException (
					'Cache directory %s is not writable',
					self::$cacheDirectory
				);
			}

			if (!isset($config['disable_minification']) || !$config['disable_minification']) {
				if (isset($config['minification_mode'])) {
					if ($config['minification_mode']) {
						self::$minificationMode = $config['minification_mode'];
					}
				} else {
					self::$minificationMode = iw::getExecutionMode();
				}
			}
		}

		/**
		 * Check whether or not a particular view file exists relative to the
		 * view root.
		 *
		 * @static
		 * @access public
		 * @param string $view_file The relative path to the view file to check
		 * @return boolean TRUE if the view file is readable, FALSE otherwise
		 */
		static public function exists($view_file)
		{
			if ($view_file[0] !== '/' && $view_file[0] !== '\\') {
				$view_file = implode(DIRECTORY_SEPARATOR, array(
					self::$viewRoot,
					$view_file
				));
			} else {
				$view_file = implode(DIRECTORY_SEPARATOR, array(
					$_SERVER['DOCUMENT_ROOT'],<commit_msg>Added $data parameter to View::create() for packing initial data.<commit_after><?php

	/**
	 * The inKWELL view class
	 *
	 * Views are instantiated objects which loosely couple data to templated languages.  These
	 * objects are primarily designed to work with HTML, so a number of helper methods are provided
	 * to more easily work with markup.
	 *
	 * @author <NAME> [mjs] <<EMAIL>>
	 * @copyright Copyright (c) 2012, <NAME>
	 * @license Please reference the LICENSE.txt file at the root of this distribution
	 *
	 * @package inKWell
	 */
	class View extends fTemplating implements inkwell
	{
		const DEFAULT_VIEW_ROOT     = 'views';
		const DEFAULT_CACHE_DIR     = 'cache';
		const PRIMARY_VIEW_ELEMENT  = '__main__'; // This must match Flourish

		/**
		 * The path from which relative views are loaded
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $viewRoot = NULL;

		/**
		 * The path where cached views and compressed styles/scripts are stored
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $cacheDirectory = NULL;

		/**
		 * The minification mode for compressing styles/scripts
		 *
		 * @static
		 * @access private
		 * @var string|NULL
		 */
		static private $minificationMode = NULL;

		/**
		 * The data storage area
		 *
		 * @access private
		 * @var array
		 */
		private $data = array();

		/**
		 * A list of callbacks to call when render() is called
		 *
		 * @access private
		 * @var array
		 */
		private $renderCallbacks = array();

		/**
		 * If the template represents string content
		 *
		 * @access private
		 * @var boolean
		 */
		private $isFood = FALSE;

		/**
		 * Initializes the templating engine
		 *
		 * @static
		 * @access public
		 * @param array $config The configuration array
		 * @param string $element The element name of the configuration array
		 * @return void
		 */
		static public function __init(array $config = array(), $element = NULL)
		{

			self::$viewRoot = implode(DIRECTORY_SEPARATOR, array(
				iw::getRoot(),
				($root_directory = iw::getRoot($element))
					? $root_directory
					: self::DEFAULT_SCAFFOLDING_ROOT
			));

			self::$viewRoot       = new fDirectory(self::$viewRoot);
			self::$cacheDirectory = iw::getWriteDirectory(
				isset($config['cache_directory'])
					? $config['cache_directory']
					: self::DEFAULT_CACHE_DIRECTORY
			);

			try {
				self::$cacheDirectory = new fDirectory(self::$cacheDirectory);
			} catch (fValidationException $e) {
				throw new fEnvironmentException (
					'Cache directory %s does not exist',
					self::$cacheDirectory
				);
			}

			if (!self::$cacheDirectory->isWritable()) {
				throw new fEnvironmentException (
					'Cache directory %s is not writable',
					self::$cacheDirectory
				);
			}

			if (!isset($config['disable_minification']) || !$config['disable_minification']) {
				if (isset($config['minification_mode'])) {
					if ($config['minification_mode']) {
						self::$minificationMode = $config['minification_mode'];
					}
				} else {
					self::$minificationMode = iw::getExecutionMode();
				}
			}
		}

		/**
		 * A simple factory method for creating new views based on a file.
		 *
		 * @static
		 * @access public
		 * @param string|array $view_file The view file or an array of candidate view files to load
		 * @param array $data An optional array of initial data
		 * @return View The view object with the view file loaded
		 */
		static public function create($view_file, $data = array())
		{
			$view = new self();
			$view->load($view_file);
			$view->pack($data);

			return $view;
		}

		/**
		 * Check whether or not a particular view file exists relative to the
		 * view root.
		 *
		 * @static
		 * @access public
		 * @param string $view_file The relative path to the view file to check
		 * @return boolean TRUE if the view file is readable, FALSE otherwise
		 */
		static public function exists($view_file)
		{
			if ($view_file[0] !== '/' && $view_file[0] !== '\\') {
				$view_file = implode(DIRECTORY_SEPARATOR, array(
					self::$viewRoot,
					$view_file
				));
			} else {
				$view_file = implode(DIRECTORY_SEPARATOR, array(
					$_SERVER['DOCUMENT_ROOT'],
{'fraction_non_alphanumeric': 0.11711711711711711, 'fraction_numerical': 0.0014609203798392988, 'mean_word_length': 3.0507889546351086, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '3179499', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2322, 'n_words': 750}