Haml and Sass have been used in Ruby for sometime to simplify templates (Haml) and make CSS more intelligent, flexible and manageable (Sass). This extension brings Haml and Sass to Yii.
It's kind of two extensions in one as you can use Haml and Sass independently of each other.
Included is PHamlP, a port of Haml and Sass to PHP. This is Haml/Sass V3.x compliant.
Haml is based on one primary principle. Markup should be beautiful.
Haml is a markup language that’s used to cleanly and simply describe the XHTML of any web document, without the use of inline code. It avoids the need for explicitly coding XHTML into the template, because it is actually an abstract description of the XHTML, with some code to generate dynamic content.
PHamlP also provides some [helper methods][http://code.google.com/p/phamlp/wiki/HelperMethods] that can be used from your template, and you can extend the class and define your own.
PHamlP supports for, if, elseif, else, foreach, do, and while blocks.
Read the Haml tutorial then try it for yourself; you probably won't want to go back;
See http://haml-lang.com for details on Haml.
Sass is a meta-language on top of CSS that’s used to describe the style of a document cleanly and structurally, with more power than flat CSS allows.
It features include nested rules, variables, mixins, and more to make CSS powerful, manageable and DRY.
The extension supports SASS and SCSS syntaxes.
The extension includes Compass.
See http://sass-lang.com/ for details on Sass.
See http://compass-style.orgm/ for details on Compass.
NOTE: Sass is primarily a development tool and is not intended for production use. You should link to the compiled stylesheets in production for performance.
The PHamlP Wiki has detailed description of options for Haml and Sass.
Declare PHamlP's Haml as your the viewRender component in your configuration.
'viewRenderer'=>array( 'class'=>'ext.phamlp.Haml', // delete options below in production 'ugly' => false, 'style' => 'nested', 'debug' => 0, 'cache' => false, ),
In the demo folder there are Haml templates for a new Yii project. Copy them into the appropriate locations in the views directory.
As of R0014 and greater the extension supports the use of both Haml and PHP view files and layouts in the same application.
Yii 1.1.2 and 1.0.13 support this feature natively.
For use with earlier versions of Yii the extension contains the AppController file in the Yii directory. This has a new resolveViewFile() method that must override CCcontroller::resolveViewFile(). This is done either by extending your application's controllers from AppController (Yii must be able to find it, so either move it from the extension into application.components or edit your configuration file to import it), or copy AppCcontroller::resolveViewFile() method into your application's own base controller.
Note: Prior to R0014 all views must be Haml
In order to make the handling of Sass files as transparent as possible the extension has an enhanced asset manager. This must be declared as the assetManager component in your configuration file.
'assetManager' => array( 'class' => 'PBMAssetManager', 'parsers' => array( 'sass' => array( // key == the type of file to parse 'class' => 'ext.phamlp.Sass', // path alias to the parser 'output' => 'css', // the file type it is parsed to 'options' => array(<Parser specific options>) ), ) ),
Publishing a Sass file is the same as publishing any other asset, i.e.:
$publishedAsset = Yii::app()->getAssetMananger()->publish(Yii::getPathOfAlias('allias.to.asset.directory'). DIRECTORY_SEPARATOR . 'asset.sass');
If you are using the Markdown filter you must now provide the path alias in your configuration to the directory containing the Yii specific version. The Yii specific version is included in the extension.
'viewRenderer'=>array( 'class'=>'ext.haml.Haml', 'filterPathAlias'=>'ext.haml.filters' },