Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added better support and tests for keyframes

  • Loading branch information...
commit d2fe07eaa79b1357ca7ad1cf6e710e9b6b58ec72 1 parent 40d57a5
@alexkalderimis alexkalderimis authored
Showing with 96 additions and 1 deletion.
  1. +10 −1 prefix.coffee
  2. +86 −0 test/keyframes.coffee
View
11 prefix.coffee
@@ -108,7 +108,15 @@ exports.css = css = (input, text, blacklist=['html', 'body']) ->
parser.addListener 'startkeyframes', (event) ->
nlIfNeeded event
- output.push "@#{ event.prefix }keyframes #{ event.name } {"
+ vendorPref = if event.prefix then "-#{ event.prefix }-" else ''
+ output.push "@#{ vendorPref }keyframes #{ event.name } {"
+
+ parser.addListener 'startkeyframerule', (event) ->
+ onNewLine = nlIfNeeded event
+ offset = event.col
+ indent = if onNewLine then new Array(offset).join(' ') else ' '
+ output.push "#{indent}#{event.keys.join(' ')} {"
+
parser.addListener 'startrule', (event) ->
nlIfNeeded event
@@ -126,6 +134,7 @@ exports.css = css = (input, text, blacklist=['html', 'body']) ->
parser.addListener 'endpage', closeBrace
parser.addListener 'endfontface', closeBrace
parser.addListener 'endrule', closeBrace
+ parser.addListener 'endkeyframerule', closeBrace
parser.addListener 'property', (event) ->
onNewLine = nlIfNeeded event
View
86 test/keyframes.coffee
@@ -0,0 +1,86 @@
+should = require "should"
+prefix = require "../prefix"
+
+input =
+"""
+div, article { display:block; }
+@-webkit-keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;
+ }
+ to {
+ background-position: 0 0;
+ }
+}
+
+@-moz-keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;
+ }
+ to {
+ background-position: 0 0;
+ }
+}
+
+@-ms-keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;
+ }
+ to {
+ background-position: 0 0;
+ }
+}
+
+@-o-keyframes progress-bar-stripes {
+ from {
+ background-position: 0 0;
+ }
+ to {
+ background-position: 40px 0;
+ }
+}
+
+@keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;
+ }
+ to {
+ background-position: 0 0;
+ }
+}
+"""
+
+expected =
+"""
+.bootstrap div, .bootstrap article {display:block;}
+@-webkit-keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;}
+ to {
+ background-position: 0 0;}}
+@-moz-keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;}
+ to {
+ background-position: 0 0;}}
+@-o-keyframes progress-bar-stripes {
+ from {
+ background-position: 0 0;}
+ to {
+ background-position: 40px 0;}}
+@keyframes progress-bar-stripes {
+ from {
+ background-position: 40px 0;}
+ to {
+ background-position: 0 0;}}
+"""
+
+# TODO: when parserlib is updated, put the ms stanza back in.
+
+describe "when running on a file with key frame definitions", ->
+
+ result = prefix.css input, '.bootstrap', []
+
+ it "should preserve the keyframe info", ->
+
+ result.should.equal expected
Please sign in to comment.
Something went wrong with that request. Please try again.