<commit_before><?php

class CM_Response_Resource_CSS extends CM_Response_Resource_Abstract {

	public function process() {
		$this->setHeader('Content-Type', 'text/css');
		$this->enableCache();

		if ($this->_getFilename() == 'library.css') {
			$content = '';
			foreach (CM_Util::rglob('*.css', DIR_PUBLIC . 'static/css/library/') as $path) {
				$content .= new CM_File($path);
			}
		} elseif ($this->_getFilename() == 'internal.css') {
			$presets = new CM_Css($this->getRender()->getLayoutFile('presets.style')->read(), $this->getRender());
			$content = new CM_Css($this->getRender()->getLayoutFile('layout.style')->read(), $this->getRender(), $presets);

			foreach ($this->getRender()->getSite()->getThemes() as $theme) {
				foreach (CM_Util::rglob('*.css', $this->getRender()->getThemeDir(true, $theme) . 'css/') as $path) {
					$file = new CM_File($path);
					$content .= new CM_Css($file->read(), $this->getRender(), $presets);
				}
			}

			$components = array();
			foreach (self::getSite()->getNamespaces() as $namespace) {
				$components = array_merge($components, CM_Util::rglob('*.php', DIR_LIBRARY . $namespace . '/Component/'));
			}

			foreach ($this->_getClasses($components) as $class) {
				if (!preg_match('#^(\w+)_Component_(.+)$#', $class['name'], $matches)) {
					throw new CM_Exception("Cannot detect namespace from component's class-name");
				}
				$namespace = $matches[1];
				$componentName = $matches[2];
				$relativePaths = array();
				foreach ($this->getRender()->getSite()->getThemes() as $theme) {
					$basePath = $this->getRender()->getThemeDir(true, $theme, $namespace) . 'Component/' . $componentName . '/';
					foreach (CM_Util::rglob('*.style', $basePath) as $path) {
						$relativePaths[] = preg_replace('#^' . $basePath . '#', '', $path);
					}
				}
				foreach (array_unique($relativePaths) as $path) {
					$prefix = '.' . $class['name'];
					if ($path != 'default.style' && strpos($path, '/') === false) {
						$prefix .= '.' . preg_replace('#.style$#', '', $path);
					}

					$file = $this->getRender()->getLayoutFile('Component/' . $componentName . '/' . $path, $namespace);
					$content .= new CM_Css($file->read(), $this->getRender(), $presets, $prefix);
				}
			}
		} elseif (file_exists(DIR_PUBLIC . 'static/css/' . $this->_getFilename())) {
			$content = new CM_File(DIR_PUBLIC . 'static/css/' . $this->_getFilename());
		} else {
			throw new CM_Exception_Invalid('Invalid filename: `' . $this->_getFilename() . '`');
		}
		return $content;
	}
}<commit_msg>t132: Implement basic page css support<commit_after><?php

class CM_Response_Resource_CSS extends CM_Response_Resource_Abstract {

	public function process() {
		$this->setHeader('Content-Type', 'text/css');
		$this->enableCache();

		if ($this->_getFilename() == 'library.css') {
			$content = '';
			foreach (CM_Util::rglob('*.css', DIR_PUBLIC . 'static/css/library/') as $path) {
				$content .= new CM_File($path);
			}
		} elseif ($this->_getFilename() == 'internal.css') {
			$presets = new CM_Css($this->getRender()->getLayoutFile('presets.style')->read(), $this->getRender());
			$content = new CM_Css($this->getRender()->getLayoutFile('layout.style')->read(), $this->getRender(), $presets);

			foreach ($this->getRender()->getSite()->getThemes() as $theme) {
				foreach (CM_Util::rglob('*.css', $this->getRender()->getThemeDir(true, $theme) . 'css/') as $path) {
					$file = new CM_File($path);
					$content .= new CM_Css($file->read(), $this->getRender(), $presets);
				}
			}

			foreach (array('Component', 'Page') as $viewType) {
				$viewClasses = array();
				foreach (self::getSite()->getNamespaces() as $namespace) {
					$viewClasses = array_merge($viewClasses, CM_Util::rglob('*.php', DIR_LIBRARY . $namespace . '/' . $viewType . '/'));
				}
				foreach ($this->_getClasses($viewClasses) as $viewClass) {
					if (!preg_match('#^(\w+)_' . $viewType . '_(.+)$#', $viewClass['name'], $matches)) {
						throw new CM_Exception("Cannot detect namespace from component's class-name");
					}
					$namespace = $matches[1];
					$viewName = $matches[2];
					$relativePaths = array();
					foreach ($this->getRender()->getSite()->getThemes() as $theme) {
						$basePath = $this->getRender()->getThemeDir(true, $theme, $namespace) . $viewType . '/' . $viewName . '/';
						foreach (CM_Util::rglob('*.style', $basePath) as $path) {
							$relativePaths[] = preg_replace('#^' . $basePath . '#', '', $path);
						}
					}
					foreach (array_unique($relativePaths) as $path) {
						$prefix = null;
						if ('Component' == $viewType) {
							$prefix = '.' . $viewClass['name'];
							if ($path != 'default.style' && strpos($path, '/') === false) {
								$prefix .= '.' . preg_replace('#.style$#', '', $path);
							}
						}

						$file = $this->getRender()->getLayoutFile($viewType . '/' . $viewName . '/' . $path, $namespace);
						$content .= new CM_Css($file->read(), $this->getRender(), $presets, $prefix);
					}
				}
			}
		} elseif (file_exists(DIR_PUBLIC . 'static/css/' . $this->_getFilename())) {
			$content = new CM_File(DIR_PUBLIC . 'static/css/' . $this->_getFilename());
		} else {
			throw new CM_Exception_Invalid('Invalid filename: `' . $this->_getFilename() . '`');
		}
		return $content;
	}
}
{'fraction_non_alphanumeric': 0.2222853894258101, 'fraction_numerical': 0.0013265112753458404, 'mean_word_length': 3.742138364779874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '7381833', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1732, 'n_words': 316}