Exemple #1
0
 /**
  *
  * Loads a template script for execution (does not execute the script).
  * 
  * This will optionally compile the template source into a PHP script
  * if a compiler object has been passed into Savant2.
  * 
  * Also good for including templates from the template paths within
  * another template, like so:
  *
  * include $this->loadTemplate('template.tpl.php');
  * 
  * @access public
  *
  * @param string $tpl The template source name to look for.
  * 
  * @param bool $setScript Default false; if true, sets the $this->_script
  * property to the resulting script path (or null on error).  Normally,
  * only $this->fetch() will need to set this to true.
  * 
  * @return string The full path to the compiled template script.
  * 
  * @throws object An error object with a SAVANT2_ERROR_NOTEMPLATE code.
  * 
  */
 function loadTemplate($tpl = null, $setScript = false)
 {
     // set to default template if none specified.
     if (is_null($tpl)) {
         $tpl = $this->_template;
     }
     // find the template source.
     $file = $this->findFile('template', $tpl);
     if (!$file) {
         return $this->error(SAVANT2_ERROR_NOTEMPLATE, array('template' => $tpl));
     }
     // are we compiling source into a script?
     if (is_object($this->_compiler)) {
         // compile the template source and get the path to the
         // compiled script (will be returned instead of the
         // source path)
         $script = $this->_compiler->compile($file);
     } else {
         // no compiling requested, return the source path
         $script = $file;
     }
     // is there a script from the compiler?
     if (!$script || $this->isError($script)) {
         if ($setScript) {
             $this->_script = null;
         }
         return $this->error(SAVANT2_ERROR_NOSCRIPT, array('template' => $tpl));
     } else {
         if ($setScript) {
             $this->_script = $script;
         }
         return $script;
     }
 }
Exemple #2
0
 /**
  * 执行编译.
  *
  * @author Seven Du <*****@*****.**>
  **/
 protected function compile()
 {
     foreach ($this->getInputDirFiles() as $file) {
         $output = $this->output . $file;
         $input = $this->input . $file;
         $output = dirname($output) . DIRECTORY_SEPARATOR . pathinfo($output, PATHINFO_FILENAME) . $this->css;
         $md5 = md5($input . md5_file($input));
         if (file_exists($this->lock . DIRECTORY_SEPARATOR . $md5) and file_exists($output)) {
             continue;
         }
         $code = file_get_contents($input);
         try {
             $code = $this->compiler->compile($code);
         } catch (Exception $e) {
             self::getInstance()->show($e->getMessage(), true);
             continue;
         } catch (ParserException $e) {
             throw new Exception($e->getMessage());
         } catch (CompilerException $e) {
             throw new Exception($e->getMessage());
         } catch (ServerException $e) {
             throw new Exception($e->getMessage());
         }
         $this->rw($output, $code);
         $this->rw($this->lock . DIRECTORY_SEPARATOR . $md5, $md5);
         $message = date('Y-m-d H:i:s', time()) . '    ';
         $message .= $input . ' -> ';
         $message .= $output;
         $this->show($message, true);
     }
 }
Exemple #3
0
 /**
  * Compile SCSS file and convert it to CSS file
  * @author Howard <*****@*****.**>
  * @param string $input
  * @param string $output
  * @return boolean
  */
 public function compile_file($input, $output)
 {
     if (!trim($input) or !wpl_file::exists($input)) {
         return false;
     }
     if (!trim($output)) {
         return false;
     }
     $CSS = $this->scssc->compile(wpl_file::read($input));
     wpl_file::write($output, $CSS);
     return $CSS;
 }
Exemple #4
0
 /**
  * Build css from provided scss file in template assets
  */
 public function buildSCSS()
 {
     /* Generate SCSS variables from properties */
     $properties = $this->getProperties();
     foreach ($properties as $key => $value) {
         if (is_string($value) && trim($value) != '') {
             $this->addSCSS('$' . $key . ": '" . $value . "';");
         }
     }
     if (class_exists('scssc')) {
         $this->_css = $this->_scssphp->compile($this->_scss . "\n\r" . $this->_extraSCSS);
     }
     /* Do compress if required */
     $config = CFactory::getConfig();
     if ($config->get('compiler_css_compress', 0) == 1) {
         $cssMinFile = CFactory::getPath('jomsocial://libraries/vendor/cssmin/cssmin.php');
         if ($cssMinFile) {
             require_once $cssMinFile;
             $cssMin = new CSSmin();
             $this->_css = $cssMin->run($this->_css);
         }
     }
     return $this;
 }
 function _renderHtml(&$ret)
 {
     $this->_flexy->compile($this->_html);
     $ret->html = $this->_flexy->bufferedOutputObject($ret);
 }
 /**
  * Compile
  *
  * @param string  $fullFilePath Fully qualified filename to compile.
  * @param string  $outputFile   Filename for generated css.
  * @param boolean $lUseScssphp  Whether to use scssphp compiler.
  *
  * @return void
  */
 public function compile($fullFilePath, $outputFile, $lUseScssphp)
 {
     $output = null;
     if (!$lUseScssphp) {
         try {
             $output = $this->executeCommand($fullFilePath, $outputFile);
             if ($this->failonerror && $output[0] !== 0) {
                 throw new BuildException("Result returned as not 0. Result: {$output[0]}", Project::MSG_INFO);
             }
         } catch (Exception $e) {
             if ($this->failonerror) {
                 throw $e;
             } else {
                 $this->log("Result: {$output[0]}", Project::MSG_INFO);
             }
         }
     } else {
         $this->log(sprintf("Compiling '%s' via scssphp", $fullFilePath), Project::MSG_INFO);
         $input = file_get_contents($fullFilePath);
         try {
             $out = $this->scssCompiler->compile($input, $fullFilePath);
             if ($out !== '') {
                 $success = file_put_contents($outputFile, $out);
                 if ($success) {
                     $this->log(sprintf("'%s' compiled and written to '%s'", $fullFilePath, $outputFile), Project::MSG_VERBOSE);
                 }
             } else {
                 $this->log('Compilation resulted in empty string');
             }
         } catch (Exception $ex) {
             if ($this->failonerror) {
                 throw new BuildException($ex->getMessage());
             } else {
                 $this->log($ex->getMessage(), Project::MSG_ERR);
             }
         }
     }
 }