Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Created November 8, 2013 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiebuilds/7365515 to your computer and use it in GitHub Desktop.
Save jamiebuilds/7365515 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function old-debug($list) {
// We open the bracket
$result: unquote("[ ");
// For each item in list
@each $item in $list {
// We test its length
// If it's more than one item long
@if length($item) > 1 {
// We deal with a nested list
$result: unquote("#{$result}#{old-debug($item)}");
}
// Else we append the item to $result
@else {
$result: unquote("#{$result}#{$item}");
}
// If we are not dealing with the last item of the list
// We add a comma and a space
@if index($list, $item) != length($list) {
$result: unquote("#{$result}, ");
}
}
// We close the bracket
// And return the string
$result: unquote("#{$result} ]");
@return quote($result);
}
@function new-debug($value, $level: 0) {
$result: '';
// We open the bracket
@if $level != 0 or type-of($value) == list {
$result: unquote("( ");
}
// For each item in list
@for $i from 1 through length($value) {
$item: nth($value, $i);
// We test its length
// If it's more than one item long
@if length($item) > 1 {
// We deal with a nested list
$result: unquote("#{$result}#{new-debug($item, $level + 1)}");
}
// Else we append the item to $result
@else {
@if $item == null {
$result: unquote("#{$result}null");
}
@else if type-of( $item ) == string {
$result: unquote("#{$result}'#{$item}'");
}
@else if $item == () {
$result: unquote("#{$result}( )");
}
@else {
$result: unquote("#{$result}#{$item}");
}
}
// If we are not dealing with the last item of the list
// We add a comma and a space
@if $i != length($value) {
$result: unquote("#{$result}, ");
}
}
// We close the bracket
// And return the string
@if $level != 0 or type-of($value) == list {
$result: unquote("#{$result} )");
}
@return quote($result);
}
normal {
normal: null;
normal: false;
normal: true;
/* normal: (); <= INVALID */
normal: (1, 2, 3);
normal: ('some', 'nice', 'text');
/* normal: (1, (2, 3), ()); <= INVALID */
normal: "";
normal: #333;
normal: "text";
/* normal: join(null, null); <= GETS REMOVED */
}
/*
* STRINGIFIED
*/
old debug {
old: old-debug( null );
old: old-debug( false );
old: old-debug( true );
old: old-debug( () );
old: old-debug( (1, 2, 3) );
old: old-debug( ('some', 'nice', 'text') );
/* old: old-debug( (1, (2, 3), ()) ); <= INVALID */
old: old-debug( "" );
old: old-debug( #333 );
old: old-debug( "text" );
old: old-debug( join(null, null) );
}
new debug {
new: new-debug( null );
new: new-debug( false );
new: new-debug( true );
new: new-debug( () );
new: new-debug( (1, 2, 3) );
new: new-debug( ('some', 'nice', 'text') );
new: new-debug( (1, (2, 3), ()) );
new: new-debug( "" );
new: new-debug( #333 );
new: new-debug( "text" );
new: new-debug( join(null, null) );
}
/*
* INTERPOLATED
*/
old debug interpolated {
old: #{old-debug( null )};
old: #{old-debug( false )};
old: #{old-debug( true )};
/* old: old-debug( () ); <= INVALID */
old: #{old-debug( (1, 2, 3) )};
/* old: old-debug( ('some', 'nice', 'text') ); <= INVALID */
/* old: old-debug( (1, (2, 3), ()) ); <= INVALID */
old: #{old-debug( "" )};
old: #{old-debug( #333 )};
old: #{old-debug( "text" )};
old: #{old-debug( join(null, null) )};
}
new debug interpolated {
new: #{new-debug( null )};
new: #{new-debug( false )};
new: #{new-debug( true )};
new: #{new-debug( () )};
new: #{new-debug( (1, 2, 3) )};
new: #{new-debug( ('some', 'nice', 'text') )};
new: #{new-debug( (1, (2, 3), ()) )};
new: #{new-debug( "" )};
new: #{new-debug( #333 )};
new: #{new-debug( "text" )};
new: #{new-debug( join(null, null) )};
}
/*
* DIFFERENCES
*/
differences {
/* doesn't wrap single items */
old: old-debug(1);
new: new-debug(1);
/* uses sass-style paranthesis */
old: old-debug( (1, 2) );
new: new-debug( (1, 2) );
/* stringifies `null` value */
old: old-debug( null );
new: new-debug( null );
/* wraps strings in quotes (makes it clear they are strings) */
old: old-debug( 'some' );
new: new-debug( 'some' );
/* doesn't display incorrectly when last value is same as earlier one */
old: old-debug( (1, 2, 1) );
new: new-debug( (1, 2, 1) );
/* shows empty lists inside lists */
/* old: old-debug( (1, 2, ()) ); <= INVALID */
new: new-debug( (1, 2, ()) );
/* shows empty strings */
old: old-debug( "" );
new: new-debug( "" );
}
normal {
normal: null;
normal: false;
normal: true;
/* normal: (); <= INVALID */
normal: 1, 2, 3;
normal: "some", "nice", "text";
/* normal: (1, (2, 3), ()); <= INVALID */
normal: "";
normal: #333;
normal: "text";
/* normal: join(null, null); <= GETS REMOVED */
}
/*
* STRINGIFIED
*/
old debug {
old: "[ ]";
old: "[ false ]";
old: "[ true ]";
old: "[ ]";
old: "[ 1, 2, 3 ]";
old: "[ some, nice, text ]";
/* old: old-debug( (1, (2, 3), ()) ); <= INVALID */
old: "[ ]";
old: "[ #333333 ]";
old: "[ text ]";
old: "[ , , ]";
}
new debug {
new: "null";
new: "false";
new: "true";
new: "( )";
new: "( 1, 2, 3 )";
new: "( 'some', 'nice', 'text' )";
new: "( 1, ( 2, 3 ), ( ) )";
new: "''";
new: "#333333";
new: "'text'";
new: "( null, null )";
}
/*
* INTERPOLATED
*/
old debug interpolated {
old: [ ];
old: [ false ];
old: [ true ];
/* old: old-debug( () ); <= INVALID */
old: [ 1, 2, 3 ];
/* old: old-debug( ('some', 'nice', 'text') ); <= INVALID */
/* old: old-debug( (1, (2, 3), ()) ); <= INVALID */
old: [ ];
old: [ #333333 ];
old: [ text ];
old: [ , , ];
}
new debug interpolated {
new: null;
new: false;
new: true;
new: ( );
new: ( 1, 2, 3 );
new: ( 'some', 'nice', 'text' );
new: ( 1, ( 2, 3 ), ( ) );
new: '';
new: #333333;
new: 'text';
new: ( null, null );
}
/*
* DIFFERENCES
*/
differences {
/* doesn't wrap single items */
old: "[ 1 ]";
new: "1";
/* uses sass-style paranthesis */
old: "[ 1, 2 ]";
new: "( 1, 2 )";
/* stringifies `null` value */
old: "[ ]";
new: "null";
/* wraps strings in quotes (makes it clear they are strings) */
old: "[ some ]";
new: "'some'";
/* doesn't display incorrectly when last value is same as earlier one */
old: "[ 1, 2, 1, ]";
new: "( 1, 2, 1 )";
/* shows empty lists inside lists */
/* old: old-debug( (1, 2, ()) ); <= INVALID */
new: "( 1, 2, ( ) )";
/* shows empty strings */
old: "[ ]";
new: "''";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment