Skip to content

Commit

Permalink
Fix #148: Passing content blocks to a mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Nov 17, 2012
1 parent c6abf31 commit 4f3aeb2
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 59 deletions.
75 changes: 51 additions & 24 deletions build/cli/csscomb.php
@@ -1,13 +1,17 @@
<?php
/**
* CSScomb
* @version: 2.11 (build 4d71dea-1210271349)
* @author: Vyacheslav Oliyanchuk (miripiruni)
* @web: http://csscomb.com/
*
* Tool for sorting CSS properties in specific order
*
* @version 2.11 (build c6abf31-1211171628)
* @author Vyacheslav Oliyanchuk (miripiruni) <mail@csscomb.com>
* @license MIT
* @web http://csscomb.com/
*/

error_reporting(E_ALL);

class csscomb{

var $sort_order = Array(),
Expand Down Expand Up @@ -127,18 +131,18 @@ class csscomb{
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-top-left-radius",
"-moz-border-top-left-radius",
"border-top-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
Expand Down Expand Up @@ -631,18 +635,18 @@ class csscomb{
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-top-left-radius",
"-moz-border-top-left-radius",
"border-top-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
Expand Down Expand Up @@ -723,11 +727,25 @@ class csscomb{

/**
* @param string css
* @param boolean debug
* @param json custom_sort_order JSON expected
* @return string
* @param boolean debug, OPTIONAL
* @param json custom_sort_order JSON expected, OPTIONAL
* @return string|false
*
* @TODO: https://github.com/miripiruni/CSScomb/issues/21
*
* Example:
*
* <code>
* require_once 'PATH_TO_CSScomb/csscomb.php';
*
* $c = new csscomb();
* $result_code = $c->csscomb(
* 'div {margin-top:0; color: red; display: inline;}',
* false,
* $MY_JSON_SORT_ORDER
* );
* </code>
*
*/
function csscomb($css = '', $debug = false, $custom_sort_order = null) {
$this->output = $debug ? true : false;
Expand Down Expand Up @@ -1103,6 +1121,7 @@ function parse_root($css = '') {
*
*/
function parse_child($value = '') {
$block_imports = array();
// 1. Ищем «детей» (вложенные селекторы)
preg_match_all('@
[^};]*?
Expand All @@ -1115,10 +1134,18 @@ function parse_child($value = '') {
}
@ismx', $value, $nested);

// Удаляем «детей» из общей строки
// TODO: возможно, вынести отдельной функцией, т.к. часто повторяется
foreach ($nested[0] as &$nest) {
foreach ($nested[0] as $key => &$nest) {
$value = str_replace($nest, '', $value);
if(strpos(trim($nest), '@include') === 0) {
$value = str_replace($nest, '', $value);
$old_nest = $nested[1][$key];
$new_nest = $this->parse_child($nested[1][$key]);
$nest = str_replace($old_nest, $new_nest, $nest);
$block_imports[] = $nest;
unset($nested[0][$key]);
unset($nested[1][$key]);
}
}

// Сохраняем всех «детей» в строку для последующей замены
Expand Down Expand Up @@ -1187,7 +1214,7 @@ function parse_child($value = '') {

// 6. Склеиваем всё обратно в следующем порядке:
// переменные, включения, простые свойства, вложенные {}
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $props).$nested_string.$value;
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $block_imports).implode('', $props).$nested_string.$value;
return $value;
}

Expand Down Expand Up @@ -1608,7 +1635,7 @@ class tool {
function man(){
?>

CSSComb 2.11 (build 4d71dea-1210271349) Command line tool for resort CSS code.
CSSComb 2.11 (build c6abf31-1211171628) Command line tool for resort CSS code.

SYNOPSIS
$ php <?php echo $this->argv[0]; ?> -s <file with JSON array> -i <path to input css file> -o <path to result css file>
Expand Down
2 changes: 1 addition & 1 deletion src/cli.php
Expand Up @@ -16,7 +16,7 @@ class tool {
function man(){
?>

CSSComb 2.11 (build 4d71dea-1210271349) Command line tool for resort CSS code.
CSSComb 2.11 (build c6abf31-1211171628) Command line tool for resort CSS code.

SYNOPSIS
$ php <?php echo $this->argv[0]; ?> -s <file with JSON array> -i <path to input css file> -o <path to result css file>
Expand Down
17 changes: 13 additions & 4 deletions src/csscomb.php
Expand Up @@ -4,7 +4,7 @@
*
* Tool for sorting CSS properties in specific order
*
* @version 2.11 (build 4d71dea-1210271349)
* @version 2.11 (build c6abf31-1211171628)
* @author Vyacheslav Oliyanchuk (miripiruni) <mail@csscomb.com>
* @license MIT
* @web http://csscomb.com/
Expand Down Expand Up @@ -1121,6 +1121,7 @@ function parse_root($css = '') {
*
*/
function parse_child($value = '') {
$block_imports = array();
// 1. Ищем «детей» (вложенные селекторы)
preg_match_all('@
[^};]*?
Expand All @@ -1133,10 +1134,18 @@ function parse_child($value = '') {
}
@ismx', $value, $nested);

// Удаляем «детей» из общей строки
// TODO: возможно, вынести отдельной функцией, т.к. часто повторяется
foreach ($nested[0] as &$nest) {
foreach ($nested[0] as $key => &$nest) {
$value = str_replace($nest, '', $value);
if(strpos(trim($nest), '@include') === 0) {
$value = str_replace($nest, '', $value);
$old_nest = $nested[1][$key];
$new_nest = $this->parse_child($nested[1][$key]);
$nest = str_replace($old_nest, $new_nest, $nest);
$block_imports[] = $nest;
unset($nested[0][$key]);
unset($nested[1][$key]);
}
}

// Сохраняем всех «детей» в строку для последующей замены
Expand Down Expand Up @@ -1205,7 +1214,7 @@ function parse_child($value = '') {

// 6. Склеиваем всё обратно в следующем порядке:
// переменные, включения, простые свойства, вложенные {}
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $props).$nested_string.$value;
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $block_imports).implode('', $props).$nested_string.$value;
return $value;
}

Expand Down
Expand Up @@ -2,7 +2,7 @@
<?php
/**
* CSScomb
* @version: 2.11 (build 4d71dea-1210271349)
* @version: 2.11 (build c6abf31-1211171628)
* @author: Vyacheslav Oliyanchuk (miripiruni)
* @web: http://csscomb.com/
*/
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/csscomb.sugar/Scripts/inline-csscomb.php
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
/**
* CSScomb 2.11 (build 4d71dea-1210271349)
* CSScomb 2.11 (build c6abf31-1211171628)
* http://CSScomb.com
* http://twitter.com/CSScomb
*/
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/csscomb.tmbundle/Commands/CSScomb.tmCommand
Expand Up @@ -8,7 +8,7 @@
<string>#!/usr/bin/env php
&lt;?php
/**
* CSScomb 2.11 (build 4d71dea-1210271349)
* CSScomb 2.11 (build c6abf31-1211171628)
* http://CSScomb.com
* http://twitter.com/CSScomb
*/
Expand Down
Expand Up @@ -2,7 +2,7 @@
<?php
/**
* CSScomb
* @version: 2.11 (build 4d71dea-1210271349)
* @version: 2.11 (build c6abf31-1211171628)
* @author: Vyacheslav Oliyanchuk (miripiruni)
* @web: http://csscomb.com/
*/
Expand Down
73 changes: 50 additions & 23 deletions www/src/csscomb.php
@@ -1,13 +1,17 @@
<?php
/**
* CSScomb
* @version: 2.11 (build 4d71dea-1210271349)
* @author: Vyacheslav Oliyanchuk (miripiruni)
* @web: http://csscomb.com/
*
* Tool for sorting CSS properties in specific order
*
* @version 2.11 (build c6abf31-1211171628)
* @author Vyacheslav Oliyanchuk (miripiruni) <mail@csscomb.com>
* @license MIT
* @web http://csscomb.com/
*/

error_reporting(E_ALL);

class csscomb{

var $sort_order = Array(),
Expand Down Expand Up @@ -127,18 +131,18 @@ class csscomb{
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-top-left-radius",
"-moz-border-top-left-radius",
"border-top-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
Expand Down Expand Up @@ -631,18 +635,18 @@ class csscomb{
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-top-left-radius",
"-moz-border-top-left-radius",
"border-top-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
Expand Down Expand Up @@ -723,11 +727,25 @@ class csscomb{

/**
* @param string css
* @param boolean debug
* @param json custom_sort_order JSON expected
* @return string
* @param boolean debug, OPTIONAL
* @param json custom_sort_order JSON expected, OPTIONAL
* @return string|false
*
* @TODO: https://github.com/miripiruni/CSScomb/issues/21
*
* Example:
*
* <code>
* require_once 'PATH_TO_CSScomb/csscomb.php';
*
* $c = new csscomb();
* $result_code = $c->csscomb(
* 'div {margin-top:0; color: red; display: inline;}',
* false,
* $MY_JSON_SORT_ORDER
* );
* </code>
*
*/
function csscomb($css = '', $debug = false, $custom_sort_order = null) {
$this->output = $debug ? true : false;
Expand Down Expand Up @@ -1103,6 +1121,7 @@ function parse_root($css = '') {
*
*/
function parse_child($value = '') {
$block_imports = array();
// 1. Ищем «детей» (вложенные селекторы)
preg_match_all('@
[^};]*?
Expand All @@ -1115,10 +1134,18 @@ function parse_child($value = '') {
}
@ismx', $value, $nested);

// Удаляем «детей» из общей строки
// TODO: возможно, вынести отдельной функцией, т.к. часто повторяется
foreach ($nested[0] as &$nest) {
foreach ($nested[0] as $key => &$nest) {
$value = str_replace($nest, '', $value);
if(strpos(trim($nest), '@include') === 0) {
$value = str_replace($nest, '', $value);
$old_nest = $nested[1][$key];
$new_nest = $this->parse_child($nested[1][$key]);
$nest = str_replace($old_nest, $new_nest, $nest);
$block_imports[] = $nest;
unset($nested[0][$key]);
unset($nested[1][$key]);
}
}

// Сохраняем всех «детей» в строку для последующей замены
Expand Down Expand Up @@ -1187,7 +1214,7 @@ function parse_child($value = '') {

// 6. Склеиваем всё обратно в следующем порядке:
// переменные, включения, простые свойства, вложенные {}
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $props).$nested_string.$value;
$value = implode('', $vars[0]).implode('', $first_imports[0]).implode('', $imports[1]).implode('', $imports[2]).implode('', $block_imports).implode('', $props).$nested_string.$value;
return $value;
}

Expand Down

0 comments on commit 4f3aeb2

Please sign in to comment.