Skip to content

Commit

Permalink
Adding _rules mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Apr 6, 2015
1 parent 9734980 commit c866f45
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scss/api/_declare.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
/// @output The declarations as CSS property-value pairs.
/// @example scss
/// .foo {
/// $rules: ('height': 50px, 'padding': 1rem 5rem);
/// $foo-declarations: ('height': 50px, 'padding': 1rem 5rem);
///
/// @include _declare($rules);
/// @include _declare($foo-declarations);
/// }
///
/// // Output CSS:
Expand Down
1 change: 1 addition & 0 deletions scss/api/_module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
@import 'result';
@import 'rest';
@import 'reverse';
@import 'rules';
@import 'sample';
@import 'shuffle';
@import 'size';
Expand Down
55 changes: 55 additions & 0 deletions scss/api/_rules.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@


@mixin __rules($rules: ()) {
@if not __is-map($rules)
or not __every($rules, '__is-map') {
@error 'Rules for _rules mixin must be key-value pairs, where value is a declaration map.';
} @else {
@each $selector, $declarations in $rules {
#{$selector} {
@include __declare($declarations);
}
}
}

@content;
}


///
/// Includes a ruleset for each selector-declarations pair in the map.
///
///
/// @access public
/// @group Map
/// @param {Map} $rules [()] The rules map.
/// @output The rulesets for each selector key.
/// @example scss
/// $test-rules: (
/// '.foo': (
/// 'height': 50px,
/// 'padding': 1rem 5rem
/// ),
/// '.bar .baz': (
/// 'width': 50px,
/// 'margin': 2rem 6rem
/// )
/// );
///
/// @include _rules($test-rules);
///
/// // Output CSS:
/// .foo {
/// height: 50px;
/// padding: 1rem 5rem;
/// }
///
/// .bar .baz {
/// width: 50px;
/// margin: 2rem 6rem;
/// }

@mixin _rules($args...) {
@include __rules($args...);
}

0 comments on commit c866f45

Please sign in to comment.