[Core] Rename the grad-opposite-position() helper to opposite-position() and expose it as part of the core library.
This commit is contained in:
parent
c60cf4fda5
commit
fe056d6597
31
doc-src/content/reference/compass/helpers/constants.haml
Normal file
31
doc-src/content/reference/compass/helpers/constants.haml
Normal 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
|
@ -37,7 +37,7 @@
|
|||||||
$background: unquote("");
|
$background: unquote("");
|
||||||
@if $image { $background : $image + unquote(", "); }
|
@if $image { $background : $image + unquote(", "); }
|
||||||
$start: unquote($start);
|
$start: unquote($start);
|
||||||
$end: grad-opposite-position($start);
|
$end: opposite-position($start);
|
||||||
@if $experimental-support-for-webkit {
|
@if $experimental-support-for-webkit {
|
||||||
background-image: #{$background}-webkit-gradient(linear, grad-point($start), grad-point($end), grad-color-stops($color-stops));
|
background-image: #{$background}-webkit-gradient(linear, grad-point($start), grad-point($end), grad-color-stops($color-stops));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Compass::SassExtensions::Functions
|
module Compass::SassExtensions::Functions
|
||||||
end
|
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}"
|
require "compass/sass_extensions/functions/#{func}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ module Sass::Script::Functions
|
|||||||
include Compass::SassExtensions::Functions::ImageSize
|
include Compass::SassExtensions::Functions::ImageSize
|
||||||
include Compass::SassExtensions::Functions::GradientSupport::Functions
|
include Compass::SassExtensions::Functions::GradientSupport::Functions
|
||||||
include Compass::SassExtensions::Functions::FontFiles
|
include Compass::SassExtensions::Functions::FontFiles
|
||||||
|
include Compass::SassExtensions::Functions::Constants
|
||||||
end
|
end
|
||||||
|
|
||||||
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
||||||
|
17
lib/compass/sass_extensions/functions/constants.rb
Normal file
17
lib/compass/sass_extensions/functions/constants.rb
Normal 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
|
@ -36,22 +36,6 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Functions
|
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.
|
# returns color-stop() calls for use in webkit.
|
||||||
def grad_color_stops(color_list)
|
def grad_color_stops(color_list)
|
||||||
assert_list(color_list)
|
assert_list(color_list)
|
||||||
|
Loading…
Reference in New Issue
Block a user