Browse Source

Provided SassScript version of some Compass Ruby functions.

master
Michael Hellein 11 years ago
parent
commit
25a172bbc3
  1. 6
      README.markdown
  2. 1
      lib/_functions.scss
  3. 53
      lib/functions/lists.scss
  4. 69
      test/functionsSpec.js

6
README.markdown

@ -1,6 +1,12 @@
# Compass SASS Stylesheets
This is a repository to pull SASS style sheets on bower, and enjoy the compass mixins by using libsass for faster compilation. I made no modifications to the original stylesheets from the [original repository](https://github.com/chriseppstein/compass.git)
# Compass Ruby Functions
This project includes reasonably similar implementations of some of the Ruby functions that Compass provides as Sass extensions. These are used in some Compass mixins, such as `@include background()`.
To make those functions available to your compass mixins, you'll want to import the included `_functions.scss` before `_compass.scss`.
## License
Copyright (c) 2008-2009 Christopher M. Eppstein<br>
All Rights Reserved.<br>

1
lib/_functions.scss

@ -0,0 +1 @@
@import "functions/lists";

53
lib/functions/lists.scss

@ -0,0 +1,53 @@
/*
* A partial implementation of the Ruby list functions from Compass:
* https://github.com/Compass/compass/blob/stable/lib/compass/sass_extensions/functions/lists.rb
*/
// compact is part of libsass
@function -compass-nth($list, $place) {
// Yep, Sass-lists are 1-indexed.
@if $place == "first" {
$place: 1;
}
@if $place == "last" {
$place: length($list);
}
@return nth($list, $place);
}
// compass_list and compass_space_list can't be implemented in sass script
@function -compass-list-size($list) {
@return length($list);
}
@function -compass-slice($list, $start, $end: false) {
@if $end == false {
$end: length($list);
}
$full: nth($list, $start);
@for $i from $start + 1 through $end {
$full: $full, nth($list, $i);
}
@return $full;
}
@function reject($list, $reject1, $reject2:null, $reject3:null, $reject4:null, $reject5:null, $reject6:null, $reject7:null, $reject8:null, $reject9:null) {
$rejects: $reject1, $reject2, $reject3, $reject4, $reject5, $reject6, $reject7, $reject8, $reject9;
$full: false;
@each $item in $list {
@if index($rejects, $item) {}
@else {
@if $full {
$full: $full, $item;
}
@else {
$full: $item;
}
}
}
@return $full;
}

69
test/functionsSpec.js

@ -0,0 +1,69 @@
var sass = require('node-sass');
var chalk = require('chalk');
var libDir = __dirname.replace(/test$/, 'lib');
var render = function(data, callback) {
sass.render({
data: '@import "'+libDir+'/functions";' + data,
outputStyle: 'compressed',
success: function(output){
callback(output);
},
error: function(err){
console.log(chalk.red("Sass error:"), err);
callback('', err);
}
});
}
var property = function(prop) {
return 'a{b:'+prop+';}';
}
describe("Functions", function () {
// This is verifying a function that's part of libsass that Compass also provided.
it("should compact a list with false values", function (done) {
render(property('compact(one,false,three)'), function(output, err) {
expect(output).toBe(property('one,three'));
done();
});
});
it("should calculate a list length", function(done) {
render('$list: one, two;' + property('-compass-list-size($list)'), function(output, err) {
expect(output).toBe(property('2'));
done();
});
});
it("should calculate a list length with a space delimiter", function(done) {
render('$list: one two;' + property('-compass-list-size($list)'), function(output, err) {
expect(output).toBe(property('2'));
done();
});
});
it("should slice a list", function(done) {
render('$list: one, two, three, four;' + property('-compass-slice($list, 2, 3)'), function(output, err) {
expect(output).toBe(property('two,three'));
done();
});
});
it("should slice a list to the end", function(done) {
render('$list: one, two, three, four;' + property('-compass-slice($list, 2)'), function(output, err) {
expect(output).toBe(property('two,three,four'));
done();
});
});
it("should reject values from a list", function(done) {
render('$list: one, two, three, four;' + property('reject($list, two, four)'), function(output, err) {
expect(output).toBe(property('one,three'));
done();
});
});
});
Loading…
Cancel
Save