From 700b5048952839640e00b63859b817e82ab1f509 Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Fri, 15 Jan 2016 19:54:34 +0300 Subject: [PATCH] add media cache http://kizu.ru/en/issues/new-stylus-features/#result --- ShortCSS.styl | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ShortCSS.styl b/ShortCSS.styl index a03baa7..99946c7 100644 --- a/ShortCSS.styl +++ b/ShortCSS.styl @@ -301,4 +301,37 @@ _h24 = 'h2,h3,h4' _h36 = 'h3,h4,h5,h6' _h35 = 'h3,h4,h5' -imp = !important \ No newline at end of file +imp = !important + +//From kizu.ru +// Define the cache and the aliases +$media_cache = {} +$media_aliases = { + palm: '(max-width: 480px)' + lap: '(min-width: 481px) and (max-width: 1023px)' + lap-and-up: '(min-width: 481px)' + portable: '(max-width: 1023px)' + desk: '(min-width: 1024px)' + desk-wide: '(min-width: 1200px)' +} + +// Mixin for caching the blocks with the given conditions +media($condition) + helper($condition) + unless $media_cache[$condition] + $media_cache[$condition] = () + push($media_cache[$condition], block) + + +helper($condition) + {selector() + ''} + {block} + +// Function we would use to call all the cached styles +apply_media_cache() + for $media, $blocks in $media_cache + $media = unquote($media_aliases[$media] || $media) + $media = '(%s)' % $media unless match('\(', $media) + $media = 'only screen and %s' % $media + @media $media + for $block in $blocks + {$block}