Permalink
Browse files

Configurable output path for coffee scripts

 - check app.yml for a app_sf_coffeescript_plugin_javascripts_dirs
   array for output paths. Must match app_sf_coffeescript_plugin_coffeecripts_dirs
   array size ortherwise the first or if empty the default path will be used.
  • Loading branch information...
1 parent af13153 commit 31f66ad000fd60694d2e86bd763a1efaba79425b Ludovic Danigo committed May 18, 2011
Showing with 63 additions and 20 deletions.
  1. +54 −11 lib/sfCoffeeScript.class.php
  2. +9 −9 lib/sfWebDebugPanelCoffeeScript.class.php
@@ -24,6 +24,8 @@ class sfCoffeeScript {
**/
protected static $results = array();
+ protected static $csfileDirs = array();
+
/**
* Errors of compiler
*
@@ -163,7 +165,7 @@ public function setIsUseCompression($useCompression) {
* @return string a path to JS files directory
*/
static public function getJsPaths() {
- return self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/js';
+ return array_unique(array_values(self::$csfileDirs));
}
/**
@@ -211,17 +213,57 @@ static public function isJsCsCompiled($dir, $entry) {
*/
static public function getCsPaths() {
- $csPaths = array();
- $defaultCsPath = self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/coffee/';
- $userCsPaths = sfConfig::get('app_sf_coffeescript_plugin_scripts_dirs',
- array($defaultCsPath));
+ if(empty(self::$csfileDirs)) {
+
+ $csPaths = array();
+
+ $defaultCsPath = self::getProjectRelativePath(
+ self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/coffee'
+ );
+ $defaultJsPath = self::getProjectRelativePath(
+ self::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/js'
+ );
+
+ $userCsPaths = sfConfig::get(
+ 'app_sf_coffeescript_plugin_coffeescripts_dirs',
+ array($defaultCsPath)
+ );
+ $userJsPaths = sfConfig::get(
+ 'app_sf_coffeescript_plugin_javascripts_dirs',
+ array($defaultJsPath)
+ );
+
+ if(count($userCsPaths) === count($userJsPaths)) {
+
+ for($idx=0, $end=count($userCsPaths); $idx < $end; $idx++) {
- foreach ($userCsPaths as $path) {
- $path = str_replace("%", "*", $path);
- $csPaths = array_merge($csPaths, glob($path));
+ $pathPattern = str_replace("%", "*", $userCsPaths[$idx]);
+
+ foreach (glob($pathPattern) as $path) {
+
+ self::$csfileDirs[$path] = self::getProjectRelativePath(
+ $userJsPaths[$idx]
+ );
+ }
+ }
+
+ } else {
+
+ foreach($userCsPaths as $userCsPath) {
+
+ $pathPattern = str_replace("%", "*", $userCsPath);
+
+ foreach (glob($pathPattern) as $path) {
+
+ self::$csfileDirs[$path] = self::getProjectRelativePath(
+ $userJsPaths[0]
+ );
+ }
+ }
+ }
}
- return $csPaths;
+ return array_keys(self::$csfileDirs);
}
/**
@@ -245,9 +287,10 @@ static public function findCsFiles() {
* @return string JS file path
*/
static public function getJsPathOfCs($csFile) {
+ $csPath = self::getProjectRelativePath(dirname($csFile));
return str_replace(
- array(dirname($csFile), '.coffee'),
- array(self::getJsPaths(), '.js'),
+ array($csPath, '.coffee'),
+ array(self::$csfileDirs[$csPath], '.js'),
$csFile
);
}
@@ -74,13 +74,13 @@ protected function getConfigurationContent() {
foreach ($csHelper->getDebugInfo() as $name => $value)
{
$debugInfo .= sprintf('<dt style="float:left; width: 100px"><strong>%s:</strong></dt>
- <dd>%s</dd>', $name, $value);
+ <dd>%s</dd>', $name, $value);
}
$debugInfo .= '</dl>';
return sprintf(<<<EOF
- <h2>configuration %s</h2>
- %s<br/>
+ <h2>configuration %s</h2>
+ %s<br/>
EOF
, $this->getToggler('coffeescript_debug', 'Toggle debug info')
, $debugInfo
@@ -119,12 +119,12 @@ protected function getInfoContent($info, $error = false) {
// Generating info rows
$infoRows = sprintf(<<<EOF
- <tr style="%s">
- <td class="sfWebDebugLogType">%s</td>
- <td class="sfWebDebugLogType">%s</td>
- <td class="sfWebDebugLogNumber" style="text-align:center;">%.2f</td>
- </tr>
- <tr id="cs_error_%s" style="display:none;background-color:#f18c89;">
+ <tr style="%s">
+ <td class="sfWebDebugLogType">%s</td>
+ <td class="sfWebDebugLogType">%s</td>
+ <td class="sfWebDebugLogNumber" style="text-align:center;">%.2f</td>
+ </tr>
+ <tr id="cs_error_%s" style="display:none;background-color:#f18c89;">
<td style="padding-left:15px" colspan="2">%s<td></tr>
EOF
, $trStyle

0 comments on commit 31f66ad

Please sign in to comment.