ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

LessCss port to php, and now also to Codeigniter

August 18, 2010 1:27pm

Subscribe [13]
  • #1 / Aug 18, 2010 1:27pm

    georgeh

    1 posts

    The original LessCss for ruby: http://lesscss.org/

    The port to php called LessPhp : http://leafo.net/lessphp/docs/

    And now, the Codeigniter library wrapper for LessPhp (alpha):

    (download the attached zip file)

    EDIT: I accidentally put the documentation from the non-CI version in the topic ($less = new LessCss(); ). I updated it. Now it is the CI version ($this->lesscss->... ).


    Usage

    //figure out the paths to our folders relative to codeigniter index.php
    
    //where test.less is
    $relativePath_less = 'someSubfolder/css/less';      
    
    //where you want to put the converted test.css file
    $relativePath_css = 'someSubfolder/css';     
    
    //where Less.php is
    $relativePath_lessphp = "someSubfolder/css/LessCss/LessCss.php"; 
    
    
    //load the LessCss library:
    $this->load->library('LessCss/lesscss');
             
    
    //tell it where the folders are:
    $this->lesscss->init($relativePath_less,$relativePath_css);
    
    //OR set them in the codeigniter main config file:
    $config['less_css_dir_dot_less'] = "css";
    $config['less_css_dir_dot_css']    = "css/less";
    
    //if no errors, then the output of this code should be 'test.css':
    echo $this->lesscss->compile('test.less'); 
      
    //output:
    test.css
    
    //so typical usage is:
    <link type="text/css" href="css/<?php echo $this->lesscss->compile('myStyle.less'); ?>" rel="stylesheet">
    
    //this will output:
    <link type="text/css" href="css/myStyle.css" rel="stylesheet">
    
    //in the background, $this->lesscss->compile() has: 
        //checked if 'myStyle.less' needs to be compiled, 
        //and compiled it if necesary, so 'myStyle.css' is always up to date
  • #2 / Aug 18, 2010 1:43pm

    WanWizard

    4475 posts

    Why not make it CI standard, and convert it into a library, so you can do

    $this->load->library('lesscss');
    $this->lesscss->init();
  • #3 / Aug 18, 2010 4:57pm

    georgeh

    1 posts

    @WanWizard

    That’s how it acually works. I put the documentation from the non-CI version by accident.

    Updated it now.

  • #4 / Oct 07, 2010 12:07pm

    wascko

    5 posts

    nice one, thanx!
    I just started using .less and loving it !
    still trying to find a way to do something like:

    background-image: url(@site_url'my_images/back.jpg');
  • #5 / Oct 13, 2010 11:11am

    Shaun Andrews

    10 posts

    This is interesting. I use lesscss everyday, and it’s become a valuable tool. Does this check the less file on each page load for changes? What about cacheing?

  • #6 / Oct 13, 2010 11:33am

    wascko

    5 posts

    @shaun
    as far as i understand this only builds the css file if the .less file is newer than the latest generated css-file.
    Someone told me to be carefull about the caching of the css file though.
    You could ad a variable to the css path to be sure the css is not cached.
    I am using:

    <link type="text/css" href="<?=site_url()?>css/<?php echo $this->lesscss->compile('style.less');?>?<?$cssinfo = get_file_info(site_url('css/style.css'));echo $cssinfo["date"];?>" rel="stylesheet" >

    not sure if this is a good way to use it, but it works for me.

  • #7 / Mar 03, 2011 1:08pm

    @georgeh

    I’m getting this:

    #header {
    background: @navy;
    font-style: italic;
    height: 43px;
    line-height: 43px;

    a {
    text-decoration: none;
    i {
    color: @blue;
    }
      }
    }

    Compiles to:

    #header a i { color:#007dc4; }
    #header a { text-decoration:none; }
    #header {
    background:#33566a;
    font-style:italic;
    height:43px;
    line-height:43px;
    }

    It’s is the wrong order. Am I doing something wrong or what’s happening?

  • #8 / Mar 03, 2011 1:51pm

    darrentaytay

    100 posts

    Doesn’t seem to be anything wrong with that Gregory?

  • #9 / Mar 03, 2011 6:25pm

    It’s in the wrong order. The order is very important in CSS.

    #header a i { color:#007dc4; }
    #header a { text-decoration:none; }
    #header {
    background:#33566a;
    font-style:italic;
    height:43px;
    line-height:43px;
    }

    should be:

    #header {
    background:#33566a;
    font-style:italic;
    height:43px;
    line-height:43px;
    }
    #header a { text-decoration:none; }
    #header a i { color:#007dc4; }

  • #10 / Mar 03, 2011 6:34pm

    darrentaytay

    100 posts

    Umm, the order doesn’t make a difference in CSS as far as I am aware.

  • #11 / Mar 03, 2011 7:05pm

    DjLeChuck

    12 posts

    The parent <—> child is important, not the order in the file. 😊

  • #12 / Mar 04, 2011 3:13am

    The order in the file is important. Selectors lower in the css file overwrite selectors prior to it.

    Outside of this, in the example files of the script (and in every LESS example on other websites as well) the css also comes out the other way around.

    So I assume something is wrong.

  • #13 / Mar 04, 2011 6:01am

    On the demo page of the original lessphp you can see that the css returns in a different order: http://leafo.net/lessphp/

  • #14 / Mar 04, 2011 6:04am

    DjLeChuck

    12 posts

    I see…
    I haven’t time to see the file now but later if nobody respond

  • #15 / Jun 30, 2011 10:44am

    C. Jiménez

    16 posts

    .

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases