Ver Fonte

Refactoring: new API utils::GetCSSFromSASS

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4018 a333f486-631f-4898-b8df-5754b55c2be0
romainq há 9 anos atrás
pai
commit
0c3fbf5de9
2 ficheiros alterados com 39 adições e 27 exclusões
  1. 26 0
      application/utils.inc.php
  2. 13 27
      application/webpage.class.inc.php

+ 26 - 0
application/utils.inc.php

@@ -1197,4 +1197,30 @@ class utils
 		$sText = str_replace("\r", "\n", $sText);
 		return str_replace("\n", '<br/>', htmlentities($sText, ENT_QUOTES, 'UTF-8'));
 	}
+
+	/**
+	 * Eventually compiles the SASS (.scss) file into the CSS (.css) file
+	 *
+	 * @param string $sSaasRelPath Relative path to the SCSS file (must have the extension .scss)
+	 * @return string Relative path to the CSS file (<name>.css)
+	 */
+	static public function GetCSSFromSASS($sSaasRelPath)
+	{
+		$sSaasPath = APPROOT.$sSaasRelPath;
+		$sCssRelPath = preg_replace('/\.scss$/', '.css', $sSaasRelPath);
+		$sCssPath = APPROOT.$sCssRelPath;
+		clearstatcache();
+		if (!file_exists($sCssPath) || (is_writable($sCssPath) && (filemtime($sCssPath) < filemtime($sSaasPath))))
+		{
+			// Rebuild the CSS file from the Saas file
+			if (file_exists(APPROOT.'lib/sass/sass/SassParser.php'))
+			{
+				require_once(APPROOT.'lib/sass/sass/SassParser.php'); //including Sass libary (Syntactically Awesome Stylesheets)
+				$oParser = new SassParser(array('style'=>'expanded'));
+				$sCss = $oParser->toCss($sSaasPath);
+				file_put_contents($sCssPath, $sCss);
+			}
+		}
+		return $sCssRelPath;
+	}
 }

+ 13 - 27
application/webpage.class.inc.php

@@ -270,33 +270,19 @@ class WebPage implements Page
     {
         $this->a_linked_stylesheets[] = array( 'link' => $s_linked_stylesheet, 'condition' => $s_condition);
     }
-    
-    public function add_saas($sSaasRelPath)
-    {
-    	$sSaasPath = APPROOT.$sSaasRelPath;
-    	$sCssRelPath = preg_replace('/\.scss$/', '.css', $sSaasRelPath);
-    	$sCssPath = APPROOT.$sCssRelPath;
-    	clearstatcache();
-    	if (!file_exists($sCssPath) || (is_writable($sCssPath) && (filemtime($sCssPath) < filemtime($sSaasPath))))
-    	{
-    		// Rebuild the CSS file from the Saas file
-    		if (file_exists(APPROOT.'lib/sass/sass/SassParser.php'))
-    		{
-    			require_once(APPROOT.'lib/sass/sass/SassParser.php'); //including Sass libary (Syntactically Awesome Stylesheets)
-    			$oParser = new SassParser(array('style'=>'expanded'));
-    			$sCss = $oParser->toCss($sSaasPath);
-    			file_put_contents($sCssPath, $sCss);
-    		}
-    	}
-    	$sRootUrl =  utils::GetAbsoluteUrlAppRoot();
-    	if ($sRootUrl === '')
-    	{
-    		// We're running the setup of the first install...
-    		$sRootUrl = '../';
-    	}
-    	$sCSSUrl = $sRootUrl.$sCssRelPath;
-    	$this->add_linked_stylesheet($sCSSUrl);
-    }
+
+	public function add_saas($sSaasRelPath)
+	{
+		$sCssRelPath = utils::GetCSSFromSASS($sSaasRelPath);
+		$sRootUrl =  utils::GetAbsoluteUrlAppRoot();
+		if ($sRootUrl === '')
+		{
+			// We're running the setup of the first install...
+			$sRootUrl = '../';
+		}
+		$sCSSUrl = $sRootUrl.$sCssRelPath;
+		$this->add_linked_stylesheet($sCSSUrl);
+	}
 	/**
 	 * Add some custom header to the page
 	 */