diff --git a/doc-src/content/reference/compass/helpers/constants.haml b/doc-src/content/reference/compass/helpers/constants.haml new file mode 100644 index 00000000..b619dfe4 --- /dev/null +++ b/doc-src/content/reference/compass/helpers/constants.haml @@ -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 diff --git a/frameworks/compass/stylesheets/compass/css3/_gradient.scss b/frameworks/compass/stylesheets/compass/css3/_gradient.scss index fb78563d..d5f996a2 100644 --- a/frameworks/compass/stylesheets/compass/css3/_gradient.scss +++ b/frameworks/compass/stylesheets/compass/css3/_gradient.scss @@ -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)); } diff --git a/lib/compass/sass_extensions/functions.rb b/lib/compass/sass_extensions/functions.rb index cc827748..0641b79c 100644 --- a/lib/compass/sass_extensions/functions.rb +++ b/lib/compass/sass_extensions/functions.rb @@ -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? diff --git a/lib/compass/sass_extensions/functions/constants.rb b/lib/compass/sass_extensions/functions/constants.rb new file mode 100644 index 00000000..4f3e34f8 --- /dev/null +++ b/lib/compass/sass_extensions/functions/constants.rb @@ -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 diff --git a/lib/compass/sass_extensions/functions/gradient_support.rb b/lib/compass/sass_extensions/functions/gradient_support.rb index 16b3b8b4..90112c04 100644 --- a/lib/compass/sass_extensions/functions/gradient_support.rb +++ b/lib/compass/sass_extensions/functions/gradient_support.rb @@ -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)