/** * Handler * * @param mixed $files * @param boolean $style of the output * @return string */ private static function handler($files, $style) { // set variables self::$cache_folder = Kohana::config('kosass.cache_folder'); // if files is not an array convert to one if (!is_array($files)) { $files = array($files); } // set files self::$files = $files; // add absolute path to file names self::get_files_path(); // load cache library $cache = new Kohaml_Cache('kosass'); // check for debug $debug = FALSE; //Kohana::config('kosass.debug'); // init Kosass $kosass = new Kosass($style, $debug); // loop files foreach (self::$files as $file) { // add cache file name self::$cache_files[] = $cache->check($file); $name = basename($file, '.' . Kohana::config('kosass.ext')); // if cache file does not exists then cache output from Kohaml if (!$cache->skip() || $debug) { // put file contents into an array then pass to render $output = $kosass->compile(file($file), $name); // cache output if (!$debug) { $cache->cache($output); } } } // destroy static variables self::destruct(); }
public function index($file) { if (empty($file)) { die('no file'); } header("Content-type: text/css"); header("Pragma: public"); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); $file = kohana::find_file('views', "sass/{$file}", false, 'sass'); # public_blog/blogs/stock if (!file_exists($file)) { die('invalid file'); } # echo kohana::debug(file($file)); die(); #$files = 'advanced'; #if (!is_array($files)) $files = array($files); echo Kosass::factory('compact')->compile(file($file)); # output directly to battle-test this sucka # echo sass::stylesheet('advanced', 'compact'); die; }
public function page($page_id = NULL) { valid::id_key($page_id); ob_start(); #TODO: if any tools are protected on this page, search for a possible # theme template and load that within the page css. # Is page_name protected? #$page_config_value = yaml::does_key_exist($this->site_name, 'pages_config', $page_name); # parse custom page sass file if it exists. $page_sass = $this->assets->themes_dir("{$this->theme}/pages/{$page_id}.sass"); if (file_exists($page_sass)) { echo Kosass::factory('compact')->compile(file($page_sass)); } # load custom tool css files $db = new Database(); # get all tools that are added to this page. $tool_data = $db->query("\n SELECT *, LOWER(system_tools.name) AS name, tools.id AS guid\n FROM pages_tools \n JOIN tools ON pages_tools.tool_id = tools.id\n JOIN system_tools ON tools.system_tool_id = system_tools.id\n WHERE (page_id BETWEEN 1 AND 5 OR page_id = '{$page_id}')\n AND pages_tools.fk_site = '{$this->site_id}'\n ORDER BY pages_tools.container, pages_tools.position\n "); $tool_dir = $this->assets->themes_dir("{$this->theme}/tools"); foreach ($tool_data as $tool) { # get the type and the view from the system. # TODO: try and optimize this later. $table = ORM::factory($tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id); $custom_file = "{$tool_dir}/{$tool->name}/{$tool->parent_id}/{$table->type}_{$table->view}.css"; if (file_exists($custom_file)) { readfile($custom_file); } } # cache the full result as the live global css file. file_put_contents("{$this->cache_dir}/{$page_id}.css", ob_get_clean()); return TRUE; }
public static function _generate_tool_css($toolname, $parent_id, $type, $view, $site_name, $theme, $return_contents = FALSE) { $tools_folder = DATAPATH . "{$site_name}/themes/{$theme}/tools"; $theme_file = "{$tools_folder}/{$toolname}/{$type}/{$view}.sass"; $stock_file = MODPATH . "{$toolname}/views/public_{$toolname}/{$type}/{$view}.sass"; $place_file = "{$tools_folder}/{$toolname}/{$parent_id}/{$type}_{$view}.css"; $return = FALSE; # --- folder checks --- # is this theme tools folder created? if (!is_dir($tools_folder)) { mkdir($tools_folder); } # is this specific toolname folder created? if (!is_dir("{$tools_folder}/{$toolname}")) { mkdir("{$tools_folder}/{$toolname}"); } # is this specific tool_id folder created? if (!is_dir("{$tools_folder}/{$toolname}/{$parent_id}")) { mkdir("{$tools_folder}/{$toolname}/{$parent_id}"); } ob_start(); if (file_exists($theme_file)) { $file = file($theme_file); $file[1] = "#{$toolname}_wrapper_{$parent_id}"; echo Kosass::factory('compact')->compile($file); } elseif (file_exists($stock_file)) { $file = file($stock_file); $file[1] = "#{$toolname}_wrapper_{$parent_id}"; echo Kosass::factory('compact')->compile($file); } else { echo '/* No css available for this tool. */'; } $source_contents = self::replace_tokens(ob_get_clean(), $site_name, $theme); if (file_put_contents($place_file, $source_contents)) { $return = TRUE; } if ($return_contents) { return $source_contents; } return $return; }
private function load_page_css_cache() { # if we don't have a file, build it with $this->page_css; if ($this->reset_css_cache or !file_exists("{$this->css_cache_dir}/{$this->page_id}.css")) { $css_path = $this->assets->themes_dir("{$this->theme}/pages"); # parse custom page sass file if it exists. if (file_exists("{$css_path}/{$this->page_id}.sass")) { $this->page_css = Kosass::factory('compact')->compile(file("{$css_path}/{$this->page_id}.sass")); } elseif (file_exists("{$css_path}/{$this->page_id}.css")) { $this->page_css = file_get_contents("{$css_path}/{$this->page_id}.css"); } $this->build_page_css = TRUE; return TRUE; } $this->build_page_css = FALSE; return FALSE; }