Sha256: 61957c16c8af806de07da182eb57f9f334c553aa19b2943ea069e8ec118e6f80

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

// -----------------------------------------------------------------------------
// 11. Hack constructor
// -----------------------------------------------------------------------------

/// Hack namespace prepended to the selector
$hack-namespace: '_' !default;

/// Find the last simple selector in a selector
@function _last-simple-selector($selector) {
    $parsed: selector-parse($selector);

    @if length($parsed) > 1 {
        @if $bem-throw-errors {
            @error '`#{$selector}` contains #{length($parsed)} selectors and the `_last-simple-selector()`function accepts only 1.';
        }
        @return false;
    }
    $last-simple-selector: nth(nth($parsed, 1), -1);

    @return $last-simple-selector;
}

@function _hack() {

    // You may not hack a hack
    $recursive-check: should-not-be-called-recursively('hack');

    $selector: ();
    $namespace: if($bem-use-namespaces, $hack-namespace, '');

    // Check if we are hacking an element modified by a block modifier
    $is-hack-element: not not map-get($_bem-current-context, 'modifies-element');
    $selectors: if($is-hack-element, map-get(map-get($_bem-current-context, 'modifies-element'), 'selector'), &);

    // @todo refactor the following code to something more readab
    @each $s in $selectors {
        $selector-to-str: inspect(if($is-hack-element, _last-simple-selector($s), nth($s, 1)));
        $selector-without-dot: str-slice($selector-to-str, 2, -1);
        $new-selector: '.' + $namespace + $selector-without-dot;
        $sl: selector-replace($s, if($is-hack-element, $selector-to-str, nth($s, 1)), $new-selector);
        $selector: append($selector, $sl, 'comma');
    }

    $set-current: set-current-context('hack', 'some-hack', $selector);

    @return $selector;

}

@mixin hack() {

    @at-root #{_hack()} {
        @content;
    }

    $unset-current: unset-current-context('hack');

}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bem-constructor-0.5.0 stylesheets/_hack.scss
bem-constructor-0.4.0 stylesheets/_hack.scss
bem-constructor-0.3.2 stylesheets/_hack.scss