Plugin Directory

Changeset 458803


Ignore:
Timestamp:
11/02/2011 10:35:54 PM (14 years ago)
Author:
briteweb
Message:

1.5.3 update

Location:
bw-less-css/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bw-less-css/trunk/bw_less_css.php

    r456453 r458803  
    33Plugin Name: #BW LESS-CSS
    44Plugin URI: http://support.briteweb.com/plugins/bw-less-css/
    5 Version: 1.5.2
     5Version: 1.5.3
    66Description: Helper plugin to compile and include LESS CSS files.
    77Author: #BRITEWEB
     
    1212
    1313define( 'BW_LESSCSS_SETTINGS_OPTION', 'bw_lesscss' );
    14 define( 'BW_LESSCSS_DB_VERSION', "1.5.2" );
     14define( 'BW_LESSCSS_DB_VERSION', "1.5.3" );
    1515
    1616global $mobile_devices, $bw_options;
     
    6464            if ( $style['active'] ) {
    6565                $media = ( !empty( $style['cmedia'] ) ) ? $style['cmedia'] : $style['media'];
    66                 bw_less_css( $style['file'], $media, $style['minify'], $style['mobile'] );
     66                if ( $style['mobile'] && empty( $style['cmedia'] ) ) $media = false;
     67                bw_less_css( $style['file'], array( 'media' => $media, 'minify' => $style['minify'], 'mobile' => $style['mobile'] ) );
    6768            }
    6869        }
     
    7778
    7879$detect = new Mobile_Detect( $bw_options['mobile_devices'] );
    79 global $bw_mobile;
    8080$bw_mobile = $detect->isMobile();
     81define( 'BW_LESSCSS_IS_MOBILE', $bw_mobile );
     82
     83function bw_is_mobile() {
     84    return BW_LESSCSS_IS_MOBILE;
     85}
    8186
    8287/* ========| LESS INCLUDE |======== */
    8388
    84 function bw_less_css( $less = "", $media = "all", $minify = false, $mobile = false ) {
    85 
    86     global $bw_mobile;
    87     if ( $mobile && !$bw_mobile ) return;
    88 
     89function bw_less_css( $less = "", $args = array() ) {
     90
     91    $defaults = array( 'media' => 'all', 'minify' => false, 'mobile' => $false );
     92    extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
     93
     94    if ( $mobile && ! BW_LESSCSS_IS_MOBILE && !$media ) return;
     95   
     96   
    8997    if ( !is_admin() && !empty( $less ) ) {
    9098       
     
    104112            file_put_contents( STYLESHEETPATH . '/' . $output_name, $css );
    105113        }
     114       
     115        if ( BW_LESSCSS_IS_MOBILE ) $media = "all";
    106116       
    107117        $name = str_replace( '.', '', $less ) . "_css";
  • bw-less-css/trunk/lessc.inc.php

    r455616 r458803  
    22
    33/**
    4  * lessphp v0.2.1
     4 * lessphp v0.3.0
    55 * http://leafo.net/lessphp
    66 *
     
    4848    public $mPrefix = '$'; // prefix of abstract blocks
    4949    public $imPrefix = '!'; // special character to add !important
    50     public $selfSelector = '&';
     50    public $parentSelector = '&';
    5151
    5252    static protected $precedence = array(
     
    473473        }
    474474
     475        // unquote string
     476        if ($this->literal("~") && $this->string($value, $d)) {
     477            $value = array("keyword", $value);
     478            return true;
     479        } else {
     480            $this->seek($s);
     481        }
     482
    475483        return false;
    476484    }
     
    632640
    633641    // consume a list of property values delimited by ; and wrapped in ()
    634     function argumentValues(&$args, $delim = ';') {
     642    function argumentValues(&$args, $delim = ',') {
    635643        $s = $this->seek();
    636644        if (!$this->literal('(')) return false;
     
    638646        $values = array();
    639647        while (true) {
    640             if ($this->propertyValue($value)) $values[] = $value;
     648            if ($this->expressionList($value)) $values[] = $value;
    641649            if (!$this->literal($delim)) break;
    642650            else {
     
    657665    // consume an argument definition list surrounded by ()
    658666    // each argument is a variable name with optional value
    659     function argumentDef(&$args, $delim = ';') {
     667    function argumentDef(&$args, $delim = ',') {
    660668        $s = $this->seek();
    661669        if (!$this->literal('(')) return false;
     
    664672        while ($this->variable($vname)) {
    665673            $arg = array($vname);
    666             if ($this->assign() && $this->propertyValue($value)) {
     674            if ($this->assign() && $this->expressionList($value)) {
    667675                $arg[] = $value;
    668676                // let the : slide if there is no value
     
    702710            // whitespace?
    703711            if ($this->match('', $_)) $value .= $_[0];
     712
     713            // escape parent selector
     714            $value = str_replace($this->parentSelector, "&&", $value);
    704715            return true;
    705716        }
     
    911922        foreach ($parents as $ptag) {
    912923            foreach ($current as $tag) {
    913                 $tags[] = trim($ptag.
    914                     ($tag{0} == $this->selfSelector || $tag{0} == ':'
    915                         ? ltrim($tag, $this->selfSelector) : ' '.$tag));
     924                // inject parent in place of parent selector, ignoring escaped valuews
     925                $count = 0;
     926                $parts = explode("&&", $tag);
     927
     928                foreach ($parts as $i => $chunk) {
     929                    $parts[$i] = str_replace($this->parentSelector, $ptag, $chunk, $c);
     930                    $count += $c;
     931                }
     932               
     933                $tag = implode("&", $parts);
     934
     935                if ($count > 0) {
     936                    $tags[] = trim($tag);
     937                } else {
     938                    $tags[] = trim($ptag . ' ' . $tag);
     939                }
    916940            }
    917941        }
     
    10551079            // search for inline variables to replace
    10561080            $replace = array();
    1057             if (preg_match_all('/{('.$this->preg_quote($this->vPrefix).'[\w-_][0-9\w-_]*?)}/', $value[1], $m)) {
     1081            if (preg_match_all('/'.$this->preg_quote($this->vPrefix).'\{([\w-_][0-9\w-_]*)\}/', $value[1], $m)) {
    10581082                foreach ($m[1] as $name) {
    10591083                    if (!isset($replace[$name]))
    1060                         $replace[$name] = $this->compileValue($this->reduce(array('variable', $name)));
     1084                        $replace[$name] = $this->compileValue($this->reduce(array('variable', $this->vPrefix . $name)));
    10611085                }
    10621086            }
     1087
    10631088            foreach ($replace as $var=>$val) {
    1064                 // strip quotes
    1065                 if (preg_match('/^(["\']).*?(\1)$/', $val)) {
     1089                if ($this->quoted($val)) {
    10661090                    $val = substr($val, 1, -1);
    10671091                }
    1068                 $value[1] = str_replace('{'.$var.'}', $val, $value[1]);
     1092                $value[1] = str_replace($this->vPrefix. '{'.$var.'}', $val, $value[1]);
    10691093            }
    10701094
     
    11031127    }
    11041128
    1105     function lib_quote($arg) {
    1106         return '"'.$this->compileValue($arg).'"';
    1107     }
    1108 
    1109     function lib_unquote($arg) {
    1110         $out = $this->compileValue($arg);
    1111         if ($this->quoted($out)) $out = substr($out, 1, -1);
    1112         return $out;
    1113     }
    1114 
    1115     // alias for unquote
     1129    // utility func to unquote a string
    11161130    function lib_e($arg) {
    1117         return $this->lib_unquote($arg);
     1131        switch ($arg[0]) {
     1132            case "list":
     1133                $items = $arg[2];
     1134                if (isset($items[0])) {
     1135                    return $this->lib_e($items[0]);
     1136                }
     1137                return "";
     1138            case "string":
     1139                return substr($arg[1], 1, -1);
     1140            default:
     1141                return $this->compileValue($arg);
     1142        }
    11181143    }
    11191144
     
    16761701    }
    16771702
    1678     protected function parseTree($str = null) {
    1679         $this->prepareParser($str ? $str : $this->buffer);
     1703    // parse code and return intermediate tree
     1704    public function parseTree($str = null) {
     1705        $this->prepareParser(is_null($str) ? $this->buffer : $str);
    16801706        while (false !== $this->parseChunk());
    16811707
     
    17211747    function throwParseError($msg = 'parse error') {
    17221748        $line = $this->line + substr_count(substr($this->buffer, 0, $this->count), "\n");
    1723         if ($this->fileName) {
     1749        if (isset($this->fileName)) {
    17241750            $loc = $this->fileName.' on line '.$line;
    17251751        } else {
     
    18981924}
    18991925
     1926?>
  • bw-less-css/trunk/readme.txt

    r456453 r458803  
    2222    3a. Specify files relative to your theme root (eg. style.less for a file in the root) 
    2323    3b. If using a specialty stylesheets (eg. for print), select the media type 
    24     3c. To minify the compiled CSS, check the minify checkbox
     24    3c. To target mobile devices, check the mobile checkbox (see FAQ below)
     25    3d. To minify (compress) the compiled CSS, check the minify checkbox
    2526
    2627Manually include .less files:
    2728
    28 To hard-code a .less file into a template, use `<?php bw_less_css( $file, $media, $minify ) ?>` in a template file, called by after_setup_theme action.
     29To hard-code a .less file into a template, use `<?php bw_less_css( $file, $args = array() ) ?>` in a template file, called by after_setup_theme action.
    2930
    3031`<?php
     
    3334function lesscss_include() {
    3435    bw_less_css( 'style.css' );
    35     bw_less_css( 'css/print.css', 'print', true );
     36    bw_less_css( 'css/print.css', array( 'media' => 'print', 'minify' => 'true', 'mobile' => 'false' );
    3637}
    3738
     
    4041Files are relative to the theme root, and the less compiler will save the .css to the same path as the .less file.
    4142
     43== Frequently Asked Questions ==
     44
     45= How do I include mobile stylesheets? =
     46
     47The 'mobile' checkbox marks a file as mobile, meaning it will only be included when your website is viewed on the devices checked under 'Detect mobile for.' If you also specify custom media for a mobile stylesheet, that file will be included on non-mobile devices, for the purpose of responsive design.
     48
     49You can specify which devices you want to serve mobile to under 'Detect mobile for'
     50
     51= Can I use the plugin's mobile detection elsewhere in my site? =
     52
     53Yes. To make use of the mobile detection, including device-specific detection under 'Detect mobile for', call bw_is_mobile(), which will return a boolean (true or false).
     54
    4255== Screenshots ==
    4356
     
    4558
    4659== Changelog ==
     60
     61= 1.5.3 =
     62* Updated LESS compiler to add support for additional LESS features
     63* Revised how mobile inclusion works (see FAQ)
     64* Modified 'bw_less_css' function parameters (see instructions)
     65* Added bw_is_mobile() function to allow developers to detect mobile devices outside of the plugin
    4766
    4867= 1.5.2 =
     
    6988== Upgrade Notice ==
    7089
     90= 1.5.3 =
     91* Updated LESS compiler to add support for additional LESS features
     92
    7193= 1.5.1 =
    7294*  IMPORTANT UPDATE: added update script for 1.5+
Note: See TracChangeset for help on using the changeset viewer.