Changeset 458803
- Timestamp:
- 11/02/2011 10:35:54 PM (14 years ago)
- Location:
- bw-less-css/trunk
- Files:
-
- 4 edited
-
bw_less_css.php (modified) (5 diffs)
-
lessc.inc.php (modified) (14 diffs)
-
readme.txt (modified) (5 diffs)
-
screenshot-1.png (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
bw-less-css/trunk/bw_less_css.php
r456453 r458803 3 3 Plugin Name: #BW LESS-CSS 4 4 Plugin URI: http://support.briteweb.com/plugins/bw-less-css/ 5 Version: 1.5. 25 Version: 1.5.3 6 6 Description: Helper plugin to compile and include LESS CSS files. 7 7 Author: #BRITEWEB … … 12 12 13 13 define( 'BW_LESSCSS_SETTINGS_OPTION', 'bw_lesscss' ); 14 define( 'BW_LESSCSS_DB_VERSION', "1.5. 2" );14 define( 'BW_LESSCSS_DB_VERSION', "1.5.3" ); 15 15 16 16 global $mobile_devices, $bw_options; … … 64 64 if ( $style['active'] ) { 65 65 $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'] ) ); 67 68 } 68 69 } … … 77 78 78 79 $detect = new Mobile_Detect( $bw_options['mobile_devices'] ); 79 global $bw_mobile;80 80 $bw_mobile = $detect->isMobile(); 81 define( 'BW_LESSCSS_IS_MOBILE', $bw_mobile ); 82 83 function bw_is_mobile() { 84 return BW_LESSCSS_IS_MOBILE; 85 } 81 86 82 87 /* ========| LESS INCLUDE |======== */ 83 88 84 function bw_less_css( $less = "", $media = "all", $minify = false, $mobile = false ) { 85 86 global $bw_mobile; 87 if ( $mobile && !$bw_mobile ) return; 88 89 function 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 89 97 if ( !is_admin() && !empty( $less ) ) { 90 98 … … 104 112 file_put_contents( STYLESHEETPATH . '/' . $output_name, $css ); 105 113 } 114 115 if ( BW_LESSCSS_IS_MOBILE ) $media = "all"; 106 116 107 117 $name = str_replace( '.', '', $less ) . "_css"; -
bw-less-css/trunk/lessc.inc.php
r455616 r458803 2 2 3 3 /** 4 * lessphp v0. 2.14 * lessphp v0.3.0 5 5 * http://leafo.net/lessphp 6 6 * … … 48 48 public $mPrefix = '$'; // prefix of abstract blocks 49 49 public $imPrefix = '!'; // special character to add !important 50 public $ selfSelector = '&';50 public $parentSelector = '&'; 51 51 52 52 static protected $precedence = array( … … 473 473 } 474 474 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 475 483 return false; 476 484 } … … 632 640 633 641 // consume a list of property values delimited by ; and wrapped in () 634 function argumentValues(&$args, $delim = ' ;') {642 function argumentValues(&$args, $delim = ',') { 635 643 $s = $this->seek(); 636 644 if (!$this->literal('(')) return false; … … 638 646 $values = array(); 639 647 while (true) { 640 if ($this-> propertyValue($value)) $values[] = $value;648 if ($this->expressionList($value)) $values[] = $value; 641 649 if (!$this->literal($delim)) break; 642 650 else { … … 657 665 // consume an argument definition list surrounded by () 658 666 // each argument is a variable name with optional value 659 function argumentDef(&$args, $delim = ' ;') {667 function argumentDef(&$args, $delim = ',') { 660 668 $s = $this->seek(); 661 669 if (!$this->literal('(')) return false; … … 664 672 while ($this->variable($vname)) { 665 673 $arg = array($vname); 666 if ($this->assign() && $this-> propertyValue($value)) {674 if ($this->assign() && $this->expressionList($value)) { 667 675 $arg[] = $value; 668 676 // let the : slide if there is no value … … 702 710 // whitespace? 703 711 if ($this->match('', $_)) $value .= $_[0]; 712 713 // escape parent selector 714 $value = str_replace($this->parentSelector, "&&", $value); 704 715 return true; 705 716 } … … 911 922 foreach ($parents as $ptag) { 912 923 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 } 916 940 } 917 941 } … … 1055 1079 // search for inline variables to replace 1056 1080 $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)) { 1058 1082 foreach ($m[1] as $name) { 1059 1083 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))); 1061 1085 } 1062 1086 } 1087 1063 1088 foreach ($replace as $var=>$val) { 1064 // strip quotes 1065 if (preg_match('/^(["\']).*?(\1)$/', $val)) { 1089 if ($this->quoted($val)) { 1066 1090 $val = substr($val, 1, -1); 1067 1091 } 1068 $value[1] = str_replace( '{'.$var.'}', $val, $value[1]);1092 $value[1] = str_replace($this->vPrefix. '{'.$var.'}', $val, $value[1]); 1069 1093 } 1070 1094 … … 1103 1127 } 1104 1128 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 1116 1130 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 } 1118 1143 } 1119 1144 … … 1676 1701 } 1677 1702 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); 1680 1706 while (false !== $this->parseChunk()); 1681 1707 … … 1721 1747 function throwParseError($msg = 'parse error') { 1722 1748 $line = $this->line + substr_count(substr($this->buffer, 0, $this->count), "\n"); 1723 if ( $this->fileName) {1749 if (isset($this->fileName)) { 1724 1750 $loc = $this->fileName.' on line '.$line; 1725 1751 } else { … … 1898 1924 } 1899 1925 1926 ?> -
bw-less-css/trunk/readme.txt
r456453 r458803 22 22 3a. Specify files relative to your theme root (eg. style.less for a file in the root) 23 23 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 25 26 26 27 Manually include .less files: 27 28 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.29 To 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. 29 30 30 31 `<?php … … 33 34 function lesscss_include() { 34 35 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' ); 36 37 } 37 38 … … 40 41 Files are relative to the theme root, and the less compiler will save the .css to the same path as the .less file. 41 42 43 == Frequently Asked Questions == 44 45 = How do I include mobile stylesheets? = 46 47 The '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 49 You 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 53 Yes. 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 42 55 == Screenshots == 43 56 … … 45 58 46 59 == 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 47 66 48 67 = 1.5.2 = … … 69 88 == Upgrade Notice == 70 89 90 = 1.5.3 = 91 * Updated LESS compiler to add support for additional LESS features 92 71 93 = 1.5.1 = 72 94 * IMPORTANT UPDATE: added update script for 1.5+
Note: See TracChangeset
for help on using the changeset viewer.