Skip to content

Instantly share code, notes, and snippets.

@ShivrajRath
Created May 22, 2017 22:47
Show Gist options
  • Save ShivrajRath/142e9371cefdcb9f17fa5bc61cd0e11e to your computer and use it in GitHub Desktop.
Save ShivrajRath/142e9371cefdcb9f17fa5bc61cd0e11e to your computer and use it in GitHub Desktop.
Generates a utility of padding, margins, width and font sizes
/ ............................................................
// .for
.for(@i, @n) {.-each(@i)}
.for(@n) when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n) {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
}
// ............................................................
// .for-each
.for(@array) when (default()) {.for-impl_(length(@array))}
.for-impl_(@i) when (@i > 1) {.for-impl_((@i - 1))}
.for-impl_(@i) when (@i > 0) {.-each(extract(@array, @i))}
// Margin all classes
.m {
.for(0 1 5 10 15 20 25 30 35 40 50 55 60 65 70 75 80 85 90 95 100); .-each(@name) {
&@{name} {
margin: ~"@{name}px"
}
&t@{name} {
margin-top: ~"@{name}px"
}
&b@{name} {
margin-bottom: ~"@{name}px"
}
&l@{name} {
margin-left: ~"@{name}px"
}
&r@{name} {
margin-right: ~"@{name}px"
}
}
}
// Auto margins
.m {
.for(auto); .-each(@name) {
&@{name} {
margin: ~"@{name}"
}
&t@{name} {
margin-top: ~"@{name}"
}
&b@{name} {
margin-bottom: ~"@{name}"
}
&l@{name} {
margin-left: ~"@{name}"
}
&r@{name} {
margin-right: ~"@{name}"
}
&lr@{name} {
margin-left: ~"@{name}";
margin-right: ~"@{name}";
}
}
}
// Padding All Classes
.p {
.for(0 1 5 10 15 20 25 30 35 40 50 55 60 65 70 75 80 85 90 95 100); .-each(@name) {
&@{name} {
padding: ~"@{name}px"
}
&t@{name} {
padding-top: ~"@{name}px"
}
&b@{name} {
padding-bottom: ~"@{name}px"
}
&l@{name} {
padding-left: ~"@{name}px"
}
&r@{name} {
padding-right: ~"@{name}px"
}
}
}
// All widths
.w {
.for(0 5 10 15 20 25 30 35 40 50 55 60 65 70 75 80 85 90 95 100); .-each(@name) {
&per@{name} {
width: ~"@{name}%"
}
&px@{name} {
width: ~"@{name}px"
}
}
}
//Font sizes
.fs {
.for(0 5 10 15 20 25 30 35 40 50 55 60 65 70 75 80 85 90 95 100); .-each(@name) {
&@{name} {
font-size: ~"@{name}px"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment