Permalink
Browse files

refactored sfLESS class & moved getSepFixedPath && getProjectRelative…

…Path to sfLESSUtils
  • Loading branch information...
1 parent db68c4d commit f11f6a8fd6eca1bd5f0f36884def9c7f4f92b62f @everzet committed Jul 5, 2010
Showing with 38 additions and 33 deletions.
  1. +8 −33 lib/sfLESS.class.php
  2. +30 −0 lib/sfLESSUtils.class.php
View
41 lib/sfLESS.class.php
@@ -101,34 +101,6 @@ public function getDebugInfo()
}
/**
- * Returns path with changed directory separators to unix-style (\ => /)
- *
- * @param string $path basic path
- *
- * @return string unix-style path
- */
- public static function getSepFixedPath($path)
- {
- return str_replace(DIRECTORY_SEPARATOR, '/', $path);
- }
-
- /**
- * Returns relative path from the project root dir
- *
- * @param string $fullPath full path to file
- *
- * @return string relative path from the project root
- */
- public static function getProjectRelativePath($fullPath)
- {
- return str_replace(
- self::getSepFixedPath(sfConfig::get('sf_root_dir')) . '/',
- '',
- self::getSepFixedPath($fullPath)
- );
- }
-
- /**
* Do we need to check dates before compile
*
* @return boolean
@@ -175,7 +147,7 @@ public function setIsUseCompression($useCompression)
*/
static public function getCssPaths()
{
- return self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/css/';
+ return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/css/';
}
/**
@@ -226,7 +198,7 @@ static public function isCssLessCompiled($dir, $entry)
*/
static public function getLessPaths()
{
- return self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/less/';
+ return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/less/';
}
/**
@@ -271,13 +243,16 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
foreach ($response->getStylesheets() as $file => $options)
{
- if ('.less' === substr($file, -5) && (!isset($options['rel']) || 'stylesheet/less' !== $options['rel']))
+ if (
+ '.less' === substr($file, -5) &&
+ (!isset($options['rel']) || 'stylesheet/less' !== $options['rel'])
+ )
{
$response->removeStylesheet($file);
if ($useJs)
{
$response->addStylesheet('/less/' . $file, '', array_merge($options, array('rel' => 'stylesheet/less')));
- $hasLess = true;
+ $hasLess = true;
}
else
{
@@ -290,7 +265,7 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
{
if (sfConfig::get('symfony.asset.javascripts_included', false))
{
- throw new LogicException("The stylesheets must be included before the javascript in your layout");
+ throw new LogicException("The stylesheets must be included before the javascript in your layout (less.js requirement)");
}
else
{
View
30 lib/sfLESSUtils.class.php
@@ -1,4 +1,5 @@
<?php
+
/*
* This file is part of the sfLESSPlugin.
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
@@ -13,6 +14,7 @@
* @package sfLESSPlugin
* @subpackage lib
* @author Victor Berchet <victor@suumit.com>
+ * @author Victor Berchet <victor@suumit.com>
* @version 1.0.0
*/
@@ -53,4 +55,32 @@ public static function stripLessComments($less)
$less = preg_replace('#//.*$#m', '', $less);
return $less;
}
+
+ /**
+ * Returns path with changed directory separators to unix-style (\ => /)
+ *
+ * @param string $path basic path
+ *
+ * @return string unix-style path
+ */
+ public static function getSepFixedPath($path)
+ {
+ return str_replace(DIRECTORY_SEPARATOR, '/', $path);
+ }
+
+ /**
+ * Returns relative path from the project root dir
+ *
+ * @param string $fullPath full path to file
+ *
+ * @return string relative path from the project root
+ */
+ public static function getProjectRelativePath($fullPath)
+ {
+ return str_replace(
+ self::getSepFixedPath(sfConfig::get('sf_root_dir')) . '/',
+ '',
+ self::getSepFixedPath($fullPath)
+ );
+ }
}

0 comments on commit f11f6a8

Please sign in to comment.