Created
January 31, 2011 21:31
-
-
Save tj/804854 to your computer and use it in GitHub Desktop.
opposite.styl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
foo: bottom; | |
foo: right; | |
foo: bottom right; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Compass::SassExtensions::Functions::Constants | |
# returns the opposite position of a side or corner. | |
def opposite_position(position) | |
opposite = position.value.split(/ +/).map do |pos| | |
case pos | |
when "top" then "bottom" | |
when "bottom" then "top" | |
when "left" then "right" | |
when "right" then "left" | |
when "center" then "center" | |
else | |
raise Sass::SyntaxError, "Cannot determine the opposite of #{pos}" | |
end | |
end | |
Sass::Script::String.new(opposite.join(" "), position.type) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
opposite-position(pos) | |
if pos == top | |
bottom | |
else if pos == bottom | |
top | |
else if pos == left | |
right | |
else if pos == right | |
left | |
else | |
error('Invalid position ' + pos) | |
opposite(positions) | |
for pos in positions | |
pos = opposite-position(pos) | |
ret = ret is defined ? ret pos : pos | |
body | |
foo opposite(top) | |
foo opposite(left) | |
foo opposite(top left) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment