Skip to content

Commit

Permalink
Created a function called css2-fallback($value, $css2-value) that wil…
Browse files Browse the repository at this point in the history
…l use the $css2-value in a css2 context and the $value in other contexts.
  • Loading branch information
chriseppstein committed Mar 30, 2011
1 parent da57adc commit f2ceec4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion doc-src/content/CHANGELOG.markdown
Expand Up @@ -14,7 +14,11 @@ The Documentation for the [latest stable release](http://compass-style.org/docs/

The Documentation for the [latest preview release](http://beta.compass-style.org/)

0.11.beta.5 (UNRELEASED)
0.11.beta.6 (3/27/2011)
------------------------
* Added opera prefix support for linear and radial gradients.

0.11.beta.5 (03/27/2011)
------------------------

### Compass Sprites
Expand Down
1 change: 1 addition & 0 deletions doc-src/content/reference/compass/helpers.haml
Expand Up @@ -24,6 +24,7 @@ layout: core
* [append-selector()](/reference/compass/helpers/selectors/#append-selector)
* [color-stops()](/reference/compass/helpers/color-stops/)
* [cos()](/reference/compass/helpers/trig/#cos)
* [css2-fallback()](/reference/compass/helpers/cross-browser/#css2-fallback)
* [elements-of-type()](/reference/compass/helpers/display/)
* [enumerate()](/reference/compass/helpers/selectors/#enumerate)
* [font-files()](/reference/compass/helpers/font-files/)
Expand Down
11 changes: 11 additions & 0 deletions doc-src/content/reference/compass/helpers/cross-browser.haml
Expand Up @@ -112,3 +112,14 @@ documented_functions:
It is a kind of hack to sanitize the output of experimental code
into a form that can be parsed by a css2.1 compliant parser.
Usually this results in causing some functions to be omitted.
#css2-fallback.helper
%h3
%a(href="#css2-fallback")
css2-fallback(<span class="arg">$value</span>, <span class="arg">$css2-value</span>)
.details
%p
This function returns a value that is normally <code>$value<code>,
but is <code>$css2-value</code> when passed through the <code>-css2()</code>
helper function. Many of the compass css3 mixins will create a css2 fallback
value if the arguments have a css2 representation (gradients have a null css2
representation).
31 changes: 31 additions & 0 deletions lib/compass/sass_extensions/functions/cross_browser_support.rb
@@ -1,4 +1,31 @@
module Compass::SassExtensions::Functions::CrossBrowserSupport

class CSS2FallbackValue < Sass::Script::Literal
attr_accessor :value, :css2_value
def children
[value, css2_value]
end
def initialize(value, css2_value)
self.value = value
self.css2_value = css2_value
end
def inspect
to_s
end
def to_s(options = self.options)
value.to_s(options)
end
def supports?(aspect)
aspect == "css2"
end
def has_aspect?
true
end
def to_css2(options = self.options)
css2_value
end
end

# Check if any of the arguments passed require a vendor prefix.
def prefixed(prefix, *args)
aspect = prefix.value.sub(/^-/,"")
Expand Down Expand Up @@ -36,4 +63,8 @@ def prefix(prefix, *objects)
end
end

def css2_fallback(value, css2_value)
CSS2FallbackValue.new(value, css2_value)
end

end
6 changes: 6 additions & 0 deletions test/sass_extensions_test.rb
Expand Up @@ -89,6 +89,12 @@ def test_blank
assert_equal "true", evaluate("blank(-compass-space-list(' '))")
end

def test_css2_fallback
assert_equal "css3", evaluate("css2-fallback(css3, css2)")
assert_equal "css2", evaluate("-css2(css2-fallback(css3, css2))")
assert_equal "true", evaluate("prefixed(-css2, css2-fallback(css3, css2))")
end

protected
def evaluate(value)
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
Expand Down

0 comments on commit f2ceec4

Please sign in to comment.