diff --git a/lib/compass/_polyfills.scss b/lib/compass/_polyfills.scss index 331ede7..15fbc20 100644 --- a/lib/compass/_polyfills.scss +++ b/lib/compass/_polyfills.scss @@ -206,3 +206,49 @@ $_digits-to-numbers: ("0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7 @function _linear-gradient($angle, $arguments...) { @return #{'linear-gradient(#{$angle}, #{$arguments})'}; } + +/// Returns a comma delimited string for all the elements according to their +/// default css3 display value. +/// +/// (see compass/core/sass_extensions/functions/display.rb) +@function elements-of-type($display) { + $tags: ( + block: ( + 'address', 'article', 'aside', 'blockquote', 'center', 'dir', 'div', 'dd', + 'details', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'form', + 'footer', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'header', + 'hgroup', 'isindex', 'menu', 'nav', 'noframes', 'noscript', 'ol', 'p', + 'pre', 'section', 'summary', 'ul', + ), + inline:( + 'a', 'abbr', 'acronym', 'audio', 'b', 'basefont', 'bdo', 'big', 'br', + 'canvas', 'cite', 'code', 'command', 'datalist', 'dfn', 'em', 'embed', + 'font', 'i', 'img', 'input', 'keygen', 'kbd', 'label', 'mark', 'meter', + 'output', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'select', + 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'textarea', 'time', + 'tt', 'u', 'var', 'video', 'wbr', + ), + inline-block:('img'), + table: ('table'), + list-item:('li'), + table-row-group:('tbody'), + table-header-group:('thead'), + table-footer-group:('tfoot'), + table-row:('tr'), + table-cell:('th', 'td'), + html5-block:( + 'article', 'aside', 'details', 'figcaption', 'figure', 'footer', 'header', + 'hgroup', 'menu', 'nav', 'section', 'summary' + ), + html5-inline:( + 'audio', 'canvas', 'command', 'datalist', 'embed', 'keygen', 'mark', + 'meter', 'output', 'progress', 'rp', 'rt', 'ruby', 'time', 'video', 'wbr' + ) + ); + $htmlTags: join(map-get($tags, html5-block), map-get($tags, html5-inline)); + $tags: map-merge($tags, (html: $htmlTags)); + @if map-has-key($tags, $display) { + @return map-get($tags, $display); + } + @error 'element-of-type does not handle `#{$display}` display.'; +} diff --git a/test/compass/polyfills_test.dart b/test/compass/polyfills_test.dart index 06913b3..7cb3636 100644 --- a/test/compass/polyfills_test.dart +++ b/test/compass/polyfills_test.dart @@ -216,6 +216,182 @@ main() async { useSassC: useSassC); }); + group('elements-of-type', () { + const { + 'block': [ + 'address', + 'article', + 'aside', + 'blockquote', + 'center', + 'dir', + 'div', + 'dd', + 'details', + 'dl', + 'dt', + 'fieldset', + 'figcaption', + 'figure', + 'form', + 'footer', + 'frameset', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'hr', + 'header', + 'hgroup', + 'isindex', + 'menu', + 'nav', + 'noframes', + 'noscript', + 'ol', + 'p', + 'pre', + 'section', + 'summary', + 'ul', + ], + 'inline': [ + 'a', + 'abbr', + 'acronym', + 'audio', + 'b', + 'basefont', + 'bdo', + 'big', + 'br', + 'canvas', + 'cite', + 'code', + 'command', + 'datalist', + 'dfn', + 'em', + 'embed', + 'font', + 'i', + 'img', + 'input', + 'keygen', + 'kbd', + 'label', + 'mark', + 'meter', + 'output', + 'progress', + 'q', + 'rp', + 'rt', + 'ruby', + 's', + 'samp', + 'select', + 'small', + 'span', + 'strike', + 'strong', + 'sub', + 'sup', + 'textarea', + 'time', + 'tt', + 'u', + 'var', + 'video', + 'wbr', + ], + 'inline-block': ['img'], + 'table': ['table'], + 'list-item': ['li'], + 'table-row-group': ['tbody'], + 'table-header-group': ['thead'], + 'table-footer-group': ['tfoot'], + 'table-row': ['tr'], + 'table-cell': ['th', 'td'], + 'html5-block': [ + 'article', + 'aside', + 'details', + 'figcaption', + 'figure', + 'footer', + 'header', + 'hgroup', + 'menu', + 'nav', + 'section', + 'summary' + ], + 'html5-inline': [ + 'audio', + 'canvas', + 'command', + 'datalist', + 'embed', + 'keygen', + 'mark', + 'meter', + 'output', + 'progress', + 'rp', + 'rt', + 'ruby', + 'time', + 'video', + 'wbr' + ], + 'html': [ + 'article', + 'aside', + 'details', + 'figcaption', + 'figure', + 'footer', + 'header', + 'hgroup', + 'menu', + 'nav', + 'section', + 'summary', + 'audio', + 'canvas', + 'command', + 'datalist', + 'embed', + 'keygen', + 'mark', + 'meter', + 'output', + 'progress', + 'rp', + 'rt', + 'ruby', + 'time', + 'video', + 'wbr' + ], + }.forEach((display, tags) { + test('replaces $display with its tags', () async { + var cssTags = tags.join(', '); + await _expectSassOutput( + "@import 'compass/css3/filter';\n" + '#{elements-of-type($display)} {\n' + ' color: white;\n' + '}\n', + '$cssTags {\n' + ' color: white; }\n', + useSassC: useSassC); + }); + }); + }); + test('support filter', () async { await _expectSassOutput( r'''