Skip to content

Instantly share code, notes, and snippets.

@tj
Created January 31, 2011 21:31
Show Gist options
  • Save tj/804854 to your computer and use it in GitHub Desktop.
Save tj/804854 to your computer and use it in GitHub Desktop.
opposite.styl
body {
foo: bottom;
foo: right;
foo: bottom right;
}
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
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