[Core] Rename the grad-opposite-position() helper to opposite-position() and expose it as part of the core library.

This commit is contained in:
Chris Eppstein 2010-07-09 17:53:22 -07:00
parent c60cf4fda5
commit fe056d6597
5 changed files with 51 additions and 18 deletions

View File

@ -0,0 +1,31 @@
---
title: Compass Constant Helpers
crumb: Constants
framework: compass
meta_description: Helper functions for working with constants.
layout: core
classnames:
- reference
- core
- helpers
---
%h1 Compass Constant Helpers
:markdown
These helpers manipulate CSS Constants.
#opposite-position.helper
%h3
%a(href="#opposite-position")
opposite-position($position)
.details
:markdown
Returns the opposition position for the position given. Examples:
Input Output
------------------------------- ------------
opposite-position(left) => right
opposite-position(top) => bottom
opposite-position(center) => center
opposite-position(top left) => bottom right
opposite-position(center right) => center left

View File

@ -37,7 +37,7 @@
$background: unquote("");
@if $image { $background : $image + unquote(", "); }
$start: unquote($start);
$end: grad-opposite-position($start);
$end: opposite-position($start);
@if $experimental-support-for-webkit {
background-image: #{$background}-webkit-gradient(linear, grad-point($start), grad-point($end), grad-color-stops($color-stops));
}

View File

@ -1,7 +1,7 @@
module Compass::SassExtensions::Functions
end
%w(selectors enumerate urls display inline_image image_size gradient_support font_files).each do |func|
%w(selectors enumerate urls display inline_image image_size gradient_support font_files constants).each do |func|
require "compass/sass_extensions/functions/#{func}"
end
@ -14,6 +14,7 @@ module Sass::Script::Functions
include Compass::SassExtensions::Functions::ImageSize
include Compass::SassExtensions::Functions::GradientSupport::Functions
include Compass::SassExtensions::Functions::FontFiles
include Compass::SassExtensions::Functions::Constants
end
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?

View File

@ -0,0 +1,17 @@
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

View File

@ -36,22 +36,6 @@ module Compass::SassExtensions::Functions::GradientSupport
end
module Functions
# returns the opposite position of a side or corner.
def grad_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(" "))
end
# returns color-stop() calls for use in webkit.
def grad_color_stops(color_list)
assert_list(color_list)