Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jul 5, 2010
2 parents 952aeb1 + ebf202c commit 66120fe
Show file tree
Hide file tree
Showing 22 changed files with 777 additions and 620 deletions.
67 changes: 39 additions & 28 deletions README.markdown
Expand Up @@ -41,11 +41,15 @@ and enable plugin in your ProjectConfigurations class.


## Usage ## ## Usage ##


### Prepare ###

After installation, you need to create directory `web/less`. Any LESS file placed in this directory, including subdirectories, will After installation, you need to create directory `web/less`. Any LESS file placed in this directory, including subdirectories, will
automatically be parsed through LESS and saved as a corresponding CSS file in `web/css`. Example: automatically be parsed through LESS and saved as a corresponding CSS file in `web/css`. Example:


web/less/clients/screen.less => web/css/clients/screen.css web/less/clients/screen.less => web/css/clients/screen.css


### Style partials ###

If you prefix a file with an underscore, it is considered to be a partial, and will not be parsed unless included in another file. Example: If you prefix a file with an underscore, it is considered to be a partial, and will not be parsed unless included in another file. Example:


<file: web/less/clients/partials/_form.less> <file: web/less/clients/partials/_form.less>
Expand All @@ -65,41 +69,41 @@ sfLESSPlugin can use 2 workflows to manage your *.less files:
1. Compile on browser side by `less.js`; 1. Compile on browser side by `less.js`;
2. Compile on server side by `lessc`. 2. Compile on server side by `lessc`.


### Update your layout files ### ### prepare: Update layout ###


Update your layout php files (at least the ones using less stylesheets): For both flows, you need to update your layout files (at least the ones using less stylesheets):


* include the less css helper: * include the less css helper:


<?php use_helper('LessCss'); ?> <?php use_helper('LESS'); ?>


* update the way stylesheets are included by changing `<?php include_stylesheets() ?>` for `<?php include_less_stylesheets() ?>` * update the way stylesheets are included by changing `<?php include_stylesheets() ?>` for `<?php include_less_stylesheets() ?>`


### Compile on browser side ### ### 1st way: Compile on browser side ###


This is default plugin behaviour. In this behaviour, all stylesheets ending with `.less`, added: This is default plugin behaviour. In this behaviour, all stylesheets ending with `.less`, added in:


* in your `view.yml` configs: * your `view.yml` configs:


stylesheets: [header/main.less] stylesheets: [header/main.less]

* in a template view file:


<?php use_stylesheet('header/main.less') ?> * a template view file:


In this case, it will be automatically changed from something like <?php use_stylesheet('header/main.less') ?>

In this case, it will be automatically changed from something like:


<link href="/css/header/main.less" media="screen" rel="stylesheet" type="text/css" /> <link href="/css/header/main.less" media="screen" rel="stylesheet" type="text/css" />


to to link like:


<link href="/less/header/main.less" media="screen" rel="stylesheet/less" type="text/css" /> <link href="/less/header/main.less" media="screen" rel="stylesheet/less" type="text/css" />


and will add link to `less.js` into javascripts list. and will add link to `less.js` into javascripts list.


This will cause browser to parse your linked less files on the fly. This will cause browser to parse your linked less files on the fly through `less.js`.


### Compile on server side ### ### 2nd way: Compile on server side ###


In details, sfLESSPlugin server side compiler does the following: In details, sfLESSPlugin server side compiler does the following:


Expand All @@ -109,51 +113,57 @@ In details, sfLESSPlugin server side compiler does the following:


You have to install 2 packages: You have to install 2 packages:


1. `node.js`; 1. `node.js` - server side interp., based on Google V8 JS engine;
2. `less.js`. 2. `less.js` - `LESS2`. You can install this with Node Package Manager (`npm install less`).


After that, enable server behavior & disable browser behavior in `app.yml`: After that, enable server behavior & disable browser behavior in `app.yml`:


sf_less_plugin: sf_less_plugin:
compile: true compile: true
use_js: false use_js: false


In this case, sfLESSPlugin will try to find all your less files inside `web/less/*.less` & compile them into `web/css/*.css`, so you can link your less styles as default css stylesheets: In this case, sfLESSPlugin will try to find all your less files inside `web/less/*.less` & compile them into `web/css/*.css`, so you can link your less styles as default css stylesheets:


stylesheets: [main.css] stylesheets: [main.css]

or (best way) with:

stylesheets: [main.less]

so `include_less_stylesheets` helper will automatically change `.less` extension to `.css`, but you still will have ability to change compiler type (server side <-> browser side) on the fly with single change in `app.yml`


## Configuration ## ## Configuration ##


sfLESSPlugin server side compiler rechecks `web/less/*.less` at every routes init. To prevent this, add this in your apps/APP/config/app.yml: sfLESSPlugin server side compiler rechecks `web/less/*.less` at every routes init. To prevent this, add this in your apps/APP/config/app.yml:


prod: prod:
sf_less_plugin: sf_less_plugin:
compile: false compile: false


sfLESSPlugin server side compiler checks the dates of LESS & CSS files, and will by default compile again only if LESS file have been changed since last parsing . sfLESSPlugin server side compiler checks the dates of LESS & CSS files, and will by default compile again only if LESS file have been changed since last parsing .


When you use `@import` statements in your LESS files, you should also turn on dependencies checking in one of you app.yml: When you use `@import` statements in your LESS files to include partials (styles with `_` prefix), you should also turn on dependencies checking (because, less compiler will not rerun on partials change) in one of you app.yml:


dev: dev:
sf_less_plugin: sf_less_plugin:
check_dates: true check_dates: true
check_dependencies: true check_dependencies: true


**warning:** Checking for the dependencies will affect performances and should not be turned on in production **warning:** Checking for the dependencies will affect performances and should not be turned on in production


The safest (but probably slowest) option is to enforce everytime compiling: The safest (but probably slowest) option is to enforce everytime compiling:


dev: dev:
sf_less_plugin: sf_less_plugin:
check_dates: false check_dates: false


Also, sfLESSPlugin server side compiler has Web Debug Panel, from which you can view all styles to compile & can open them for edit in prefered editor. For that you need to configure sf_file_link_format in settings.yml. Also, sfLESSPlugin server side compiler has Web Debug Panel, from which you can view all styles to compile & can open them for edit in prefered editor. For that you need to configure `sf_file_link_format` in `settings.yml`.


Last but not least, you can enable CSS compression (remove of whitespaces, tabs & newlines) in server side compiler with: Last but not least, you can enable CSS compression (remove of whitespaces, tabs & newlines) in server side compiler with:


all: all:
sf_less_plugin: sf_less_plugin:
use_compression: true use_compression: true


## Tasks ## ## Tasks ##


Expand Down Expand Up @@ -191,6 +201,7 @@ less.js is maintained by Alexis Sellier [http://github.com/cloudhead](http://git


### github latest ### ### github latest ###


* updated readme & some refactorings
* dependency check improvements * dependency check improvements
* [client side] less.js updated to version 1.0.31 * [client side] less.js updated to version 1.0.31


Expand Down
2 changes: 1 addition & 1 deletion config/sfLESSPluginConfiguration.class.php
Expand Up @@ -29,7 +29,7 @@ public function initialize()
// Register listener to routing.load_configuration event // Register listener to routing.load_configuration event
$this->dispatcher->connect( $this->dispatcher->connect(
'context.load_factories', 'context.load_factories',
array('sfLESS', 'findAndCompile') array('sfLESSListeners', 'findAndCompile')
); );


// If app_sf_less_plugin_toolbar in app.yml is set to true (by default) // If app_sf_less_plugin_toolbar in app.yml is set to true (by default)
Expand Down
121 changes: 121 additions & 0 deletions lib/config/LESSConfig.class.php
@@ -0,0 +1,121 @@
<?php

/*
* This file is part of the sfLESSPlugin.
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* sfLESSConfig is configuration manager.
*
* @package sfLESSPlugin
* @subpackage lib
* @author Konstantin Kudryashov <ever.zet@gmail.com>
* @version 1.0.0
*/
class sfLESSConfig
{
/**
* Do we need to check dates before compile
*
* @var boolean
*/
protected $checkDates;

/**
* Do we need compression for CSS files
*
* @var boolean
*/
protected $useCompression;

/**
* Creates config instance
*
* @param boolean $checkDates whether we check dates before compile
* @param boolean $useCompression whether we compress result styles
*/
public function __construct($checkDates = true, $useCompression = false)
{
$this->checkDates = $checkDates;
$this->useCompression = $useCompression;
}

/**
* Do we need to check dates before compile
*
* @return boolean
*/
public function isCheckDates()
{
return $this->checkDates;
}

/**
* Set need of check dates before compile
*
* @param boolean $checkDates Do we need to check dates before compile
*/
public function setIsCheckDates($checkDates)
{
$this->checkDates = $checkDates;
}

/**
* Do we need compression for CSS files
*
* @return boolean
*/
public function isUseCompression()
{
return $this->useCompression;
}

/**
* Set need of compression for CSS files
*
* @param boolean $useCompression Do we need compression for CSS files
*/
public function setIsUseCompression($useCompression)
{
$this->useCompression = $useCompression;
}

/**
* Returns paths to CSS files
*
* @return string a path to CSS files directory
*/
public function getCssPaths()
{
return 'web/css/';
}

/**
* Returns paths to LESS files
*
* @return string a path to LESS files directories
*/
public function getLessPaths()
{
return 'web/less/';
}

/**
* Returns debug info of the current state
*
* @return array state
*/
public function getDebugInfo()
{
return array(
'dates' => var_export($this->isCheckDates(), true),
'compress' => var_export($this->isUseCompression(), true),
'less' => $this->getLessPaths(),
'css' => $this->getCssPaths()
);
}
}
52 changes: 52 additions & 0 deletions lib/config/sfLESSConfig.class.php
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the sfLESSPlugin.
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* sfLESS is helper class to provide LESS compiling in symfony projects.
*
* @package sfLESSPlugin
* @subpackage lib
* @author Konstantin Kudryashov <ever.zet@gmail.com>
* @version 1.0.0
*/
class sfLESSConfig extends LESSConfig
{
/**
* @see LESSConfig
*/
public function isCheckDates()
{
return sfConfig::get('app_sf_less_plugin_check_dates', parent::isCheckDates());
}

/**
* @see LESSConfig
*/
public function isUseCompression()
{
return sfConfig::get('app_sf_less_plugin_use_compression', parent::isUseCompression());
}

/**
* @see LESSConfig
*/
public function getCssPaths()
{
return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/css/';
}

/**
* @see LESSConfig
*/
public function getLessPaths()
{
return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/less/';
}
}
File renamed without changes.
5 changes: 4 additions & 1 deletion lib/helper/LessCssHelper.php → lib/helper/LESSHelper.php
Expand Up @@ -14,6 +14,7 @@
* @package sfLESSPlugin * @package sfLESSPlugin
* @subpackage helper * @subpackage helper
* @author Victor Berchet <victor@suumit.com> * @author Victor Berchet <victor@suumit.com>
* @author Konstantin Kudryashov <ever.zet@gmail.com>
* @version 1.0.0 * @version 1.0.0
*/ */
use_helper('Asset'); use_helper('Asset');
Expand All @@ -32,7 +33,9 @@ function get_less_stylesheets()
$response = sfContext::getInstance()->getResponse(); $response = sfContext::getInstance()->getResponse();
sfConfig::set('symfony.asset.stylesheets_included', true); sfConfig::set('symfony.asset.stylesheets_included', true);


sfLESS::findAndFixContentLinks($response, sfConfig::get('app_sf_less_plugin_use_js', false)); sfLESSListeners::findAndFixContentLinks(
$response, sfConfig::get('app_sf_less_plugin_use_js', false)
);


$html = ''; $html = '';
foreach ($response->getStylesheets() as $file => $options) foreach ($response->getStylesheets() as $file => $options)
Expand Down

0 comments on commit 66120fe

Please sign in to comment.