Skip to content

Instantly share code, notes, and snippets.

@lewang
Created March 29, 2014 21:07
Show Gist options
  • Save lewang/9863040 to your computer and use it in GitHub Desktop.
Save lewang/9863040 to your computer and use it in GitHub Desktop.
Debugging map returned by layout function. http://hugogiraudel.com/2013/10/21/sass-debug/
// ----
// Sass (v3.3.4)
// Compass (v1.0.0.alpha.18)
// Susy (v2.1.1)
// ----
@import "compass";
@import "compass/reset";
@import "susy";
// Returns $list as a string
// -------------------------------------------------------------------------------
// @documentation http://sassylists.com/documentation/#debug
// -------------------------------------------------------------------------------
// @example debug(a b c d e) => [ a, b, c, d, e ]
// @example debug(a b (c d e)) => [ a, b, [ c, d, e ] ]
// -------------------------------------------------------------------------------
// @param $list [List] : list
// @param $pre [Boolean] : enable/disable variables type and proper indentation
// @param $level [Number] : internal variable for recursivity
// -------------------------------------------------------------------------------
// @return [String]
@function debug($list, $pre: false, $level: 1) {
$tab: " ";
$indent: "";
$break: if($pre, "\A ", "");
@if length($list) == 0 {
@return "( )";
}
@if length($list) == 1 {
@return if($pre, "(" + type-of($list) + ") ", "") + $list;
}
@for $i from 1 to $level {
$indent: $indent + $tab;
}
$result: "[" + $break;
@for $i from 1 through length($list) {
$item: nth($list, $i);
$result: $result + if($pre, $indent + $tab, " ");
@if length($item) > 1 {
$result: $result
+ if($pre, "(list: " + length($item) + ") ", "")
+ debug($item, $pre, $level + 1);
}
@else {
@if $pre {
$result: $result + "(" + type-of($item) + ") ";
}
@if length($item) == 0 {
$result: $result + "( )";
}
@else if type-of($item) == string {
$result: $result + quote($item);
}
@else if $item == null {
$result: $result + "null";
}
@else {
$result: $result + $item;
}
}
@if $i != length($list) {
$result: $result + "," + $break;
}
}
$result: $result + $break + if($pre, if($level > 1, $indent, ""), " ") + "]";
@return quote($result);
}
// Mixin displaying clean debug
// -------------------------------------------------------------------------------
// @param $list [List] : list
@mixin debug($list) {
body:before {
content: debug($list, true) !important;
display: block !important;
margin: 1em !important;
padding: .5em !important;
background: #EFEFEF !important;
border: 1px solid #DDD !important;
border-radius: .2em !important;
color: #333 !important;
font: .75em/1.5 "Courier New", monospace !important;
text-shadow: 0 1px white !important;
white-space: pre-wrap !important;
}
}
/**
* Here is a cute list
*/
$list: (a #BADA55 42, (false (yummy cupcake)), 14px, "gloubiboulga", (), null);
$map: layout(24 1/4 fluid float inside);
/**
* Awesome debug mixin is awesome
*/
// @include debug($list);
@include debug($map);
/**
* Simple debug function
*/
body:after {
display: block;
content: debug($map);
}
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
}
html {
line-height: 1;
}
ol, ul {
list-style: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
vertical-align: middle;
}
q, blockquote {
quotes: none;
}
q:before, q:after, blockquote:before, blockquote:after {
content: "";
content: none;
}
a img {
border: none;
}
article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
display: block;
}
/**
* Here is a cute list
*/
/**
* Awesome debug mixin is awesome
*/
body:before {
content: "[\A (list: 2) [\A (string) math,\A (string) fluid\A ],\A (list: 2) [\A (string) output,\A (string) float\A ],\A (list: 2) [\A (string) gutter-position,\A (string) inside\A ],\A (list: 2) [\A (string) columns,\A (number) 24\A ],\A (list: 2) [\A (string) gutters,\A (number) 0.25\A ]\A ]" !important;
display: block !important;
margin: 1em !important;
padding: .5em !important;
background: #EFEFEF !important;
border: 1px solid #DDD !important;
border-radius: .2em !important;
color: #333 !important;
font: .75em/1.5 "Courier New", monospace !important;
text-shadow: 0 1px white !important;
white-space: pre-wrap !important;
}
/**
* Simple debug function
*/
body:after {
display: block;
content: "[ [ math, fluid ], [ output, float ], [ gutter-position, inside ], [ columns, 24 ], [ gutters, 0.25 ] ]";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment