Source for file classic.php

Documentation is available at classic.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  less
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. /**
  12.  * This class is taken verbatim from:
  13.  *
  14.  * lessphp v0.3.8
  15.  * http://leafo.net/lessphp
  16.  *
  17.  * LESS css compiler, adapted from http://lesscss.org
  18.  *
  19.  * Copyright 2012, Leaf Corcoran <leafot@gmail.com>
  20.  * Licensed under MIT or GPLv3, see LICENSE
  21.  *
  22.  * @package  FrameworkOnFramework
  23.  * @since    2.0
  24.  */
  25. {
  26.     public $indentChar             = "  ";
  27.  
  28.     public $break                 = "\n";
  29.  
  30.     public $open                 = " {";
  31.  
  32.     public $close                 = "}";
  33.  
  34.     public $selectorSeparator     = ", ";
  35.  
  36.     public $assignSeparator     = ":";
  37.  
  38.     public $openSingle             = " { ";
  39.  
  40.     public $closeSingle         = " }";
  41.  
  42.     public $disableSingle         = false;
  43.  
  44.     public $breakSelectors         = false;
  45.  
  46.     public $compressColors         = false;
  47.  
  48.     /**
  49.      * Public constructor
  50.      */
  51.     public function __construct()
  52.     {
  53.         $this->indentLevel 0;
  54.     }
  55.  
  56.     /**
  57.      * Indent a string by $n positions
  58.      *
  59.      * @param   integer  $n  How many positions to indent
  60.      *
  61.      * @return  string  The indented string
  62.      */
  63.     public function indentStr($n 0)
  64.     {
  65.         return str_repeat($this->indentCharmax($this->indentLevel $n0));
  66.     }
  67.  
  68.     /**
  69.      * Return the code for a property
  70.      *
  71.      * @param   string  $name   The name of the porperty
  72.      * @param   string  $value  The value of the porperty
  73.      *
  74.      * @return  string  The CSS code
  75.      */
  76.     public function property($name$value)
  77.     {
  78.         return $name $this->assignSeparator . $value ";";
  79.     }
  80.  
  81.     /**
  82.      * Is a block empty?
  83.      *
  84.      * @param   stdClass  $block  The block to check
  85.      *
  86.      * @return  boolean  True if the block has no lines or children
  87.      */
  88.     protected function isEmpty($block)
  89.     {
  90.         if (empty($block->lines))
  91.         {
  92.             foreach ($block->children as $child)
  93.             {
  94.                 if (!$this->isEmpty($child))
  95.                 {
  96.                     return false;
  97.                 }
  98.             }
  99.  
  100.             return true;
  101.         }
  102.  
  103.         return false;
  104.     }
  105.  
  106.     /**
  107.      * Output a CSS block
  108.      *
  109.      * @param   stdClass  $block  The block definition to output
  110.      *
  111.      * @return  void 
  112.      */
  113.     public function block($block)
  114.     {
  115.         if ($this->isEmpty($block))
  116.         {
  117.             return;
  118.         }
  119.  
  120.         $inner     $pre     $this->indentStr();
  121.  
  122.         $isSingle !$this->disableSingle &&
  123.             is_null($block->type&& count($block->lines== 1;
  124.  
  125.         if (!empty($block->selectors))
  126.         {
  127.             $this->indentLevel++;
  128.  
  129.             if ($this->breakSelectors)
  130.             {
  131.                 $selectorSeparator $this->selectorSeparator . $this->break . $pre;
  132.             }
  133.             else
  134.             {
  135.                 $selectorSeparator $this->selectorSeparator;
  136.             }
  137.  
  138.             echo $pre .
  139.             implode($selectorSeparator$block->selectors);
  140.  
  141.             if ($isSingle)
  142.             {
  143.                 echo $this->openSingle;
  144.                 $inner "";
  145.             }
  146.             else
  147.             {
  148.                 echo $this->open . $this->break;
  149.                 $inner $this->indentStr();
  150.             }
  151.         }
  152.  
  153.         if (!empty($block->lines))
  154.         {
  155.             $glue $this->break . $inner;
  156.             echo $inner implode($glue$block->lines);
  157.  
  158.             if (!$isSingle && !empty($block->children))
  159.             {
  160.                 echo $this->break;
  161.             }
  162.         }
  163.  
  164.         foreach ($block->children as $child)
  165.         {
  166.             $this->block($child);
  167.         }
  168.  
  169.         if (!empty($block->selectors))
  170.         {
  171.             if (!$isSingle && empty($block->children))
  172.             {
  173.                 echo $this->break;
  174.             }
  175.  
  176.             if ($isSingle)
  177.             {
  178.                 echo $this->closeSingle . $this->break;
  179.             }
  180.             else
  181.             {
  182.                 echo $pre $this->close . $this->break;
  183.             }
  184.  
  185.             $this->indentLevel--;
  186.         }
  187.     }
  188. }

Documentation generated on Tue, 19 Nov 2013 14:55:44 +0100 by phpDocumentor 1.4.3