Haml and Sass Extension

Wow Chrish, many thanks for your quick answer!! I’ll try your new version and will report the test comments.

I would like aks a question in relation with sass (I’m not using it yet). Is it possible to pass variables from php (controller or view files) to the sass files using sass variables? In such a case could you give me a short example?

By the moment, I’m using style files like “mycss.php” with text/css header (you know, the old trick) with some php variables for colour and such things inside.

Off topic:

What kind of human being could even think in understand this regexp?:


[b][b]const REGEX_HAML = '/(?m)^([ \x09]*)((?:<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />\w*))?(?:%(\w*))?(?:\.((?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />?:[-_:a-zA-Z]|#\{.+?\})+(?:[-:\w]|#\{.+?\})*(?:\.?))*))?(?:#((?:[_:a-zA-Z]|#\{.+?\})+(?:[-:\w]|#\{.+?\})*))?(?:\[(.+)\])?(?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />\()((?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />?:html_attrs\(.*?\)|data[\t ]*=[\t ]*\{.+?\}|(?:[_:a-zA-Z]+[-:\w]*)[\t ]*=[\t ]*.+)[\t ]*)+\)))?(?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />\{)((?:<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />?:html_attrs\(.*?\)|data[\t ]*=>[\t ]*\{.+?\}|(?:[_:a-zA-Z]+[-:\w]*)[\t ]*=>?[\t ]*.+)(?:,?[\t ]*)?)+\}))?(\|?>?\|?<?) *((?:\?#)|!!!|\/\/|\/|-#|!=|&=|!|&|=|-|~|\\\\\\\\)? *(.*?)(?:\s(\|)?)?)$/'; [/b][/b]

Are you sure u are human? Not robot? :P

Many thanks again,

Alex

First bug I encountered:

Whatever the reason, if I have a helper function like this:


public static function lnk_img($block, $alt, $url) {

            $image = CHtml::image($block, $alt);

            return CHtml::link($image, $url);

    }

I can use it as:


=lnk_img('Alt Text', 'site/contact') image.png

But if I use it with an array like this:


=lnk_img('Alt Text', array('site/contact')) image.png

It complains saying: Parse error: syntax error, unexpected ‘;’ in …

And in deed it is generating something like this:




<?php echo HamlHelpers::lnk_img('image.png','Alt Text', array('site/contact'); ?>

So it’s not inserting the last “)” parenthesis due to the helper function already has some parenthesis im $image variable. I think it’s something related with parsing the regexp of helpers. (I have another helper function not using parenthesis and it works fine passing arrays).

Regards,

Alex

Hello Chrish, could you check this issue with the helper functions?

Thanks in advance, Alex

Just back, so I’ll take a look at this.

Can I ask that bugs are reported through the project page http://code.google.com/p/phamlp/issues - it helps to have all the issues in one place. TIA

Fix in SVN

How to use compass? Nothing helps.

In you application configuration (usually main.php in app.config) you need something like:




'components'=>array(

  'assetManager'=>array(

    'class'=>'common.extensions.phamlp.PBMAssetManager',

    'parsers'=>array(

      'scss'=>array(

        'class'=>'common.extensions.phamlp.Sass',

        'output'=>'css',

        'options'=>array(

             .... // other options - looking at extensions here

          'extensions'=>array(

            'compass'=>array(

              // adjust the paths to suit and see Compass docs for all options

              'project_path'=>realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'),

              'images_path'=>realpath(dirname(__FILE__).'/../assets/images'),

              'http_images_path'=>'/images/image/path',

              'relative_assets'=>false // relative assets has a bug

            )

          )

        )

      ),

    )

  ),

  .... // other components

);



Then in your sccs file import compass;




@import compass



Hello,

great extension :slight_smile: I try to figure out how to work with asset manager and @import in scss files. How do you manage many scss files? For example i would like to have one scss file per widget (And only one css file in production), but my experiments with main.scss and @import rules wasn’t successful.

Thanks

Question is: why do you need this extension?

Using Sass/Compass is just a matter of installing Ruby and the Compass gem and run ‘compass watch’ - the css output will automatically update when the source files (scss/sass) changes.

IMO, you should only use phamlp when there is no other option.

Extak: Your question is best answered elsewhere, like the Sass homepage, or by means of a Google search for Sass tutorials.

You need to make sure the load_paths directive is set up in the extension config - which is in assetManager[‘parsers’][‘sass’][‘options’] in the main config file.

Hi,

This is a great extension, I’m currently using it to convert all of my views and styles to haml and sass.

One issue I’ve come across is that css files generated by this can get cached locally on individual users browsers. This is good as it speeds thing up a little, however we regularly release new code to production. This cacheing is causing a headache as users fail to receive the new versions. Is there anyway to add a version number/letter to the name of generated css files?

Regards

Andy