Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev: (21 commits)
  Fixed History for 0.54.0
  History up
  Evaluate variables in current-media function. Fixes #2128
  Undesired spaces with partial reference selector using ranges. Fixes #2133
  Slightly clarified an issue with combinators at ranges in partial references, re: #2134
  Validate regexp flags for match function
  Fix bug with evaluating default arguments
  Undesired spaces with partial reference selector using ranges. Fixes #2133
  Fixed bug with selectors() function. Closes #2130
  Don't parse empty imports
  Wrong errors with --include-css and --resolve-url used concurrently. Fixes #2125
  misc fixes
  Docs and History up
  SelectorParser: Added initial reference selector
  BIFs: expose "url" function by "embedurl"
  Updated history
  Bump version
  BIFs: Added "index" function
  Updated docs that where merged incorrectly
  added a slice function
  ...
  • Loading branch information
kizu committed Mar 5, 2016
2 parents 3404059 + c806bcf commit 26e04d8
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 27 deletions.
4 changes: 2 additions & 2 deletions History.md
@@ -1,10 +1,10 @@
0.54.0 / 2016-02-13
===================
0.54.0 / 2016-03-05

* Feature: Added initial reference selector.
* Feature: New `embedurl()` bif with optional utf8 uncoding support for SVG.
* Feature: New `index()` bif.
* Feature: New `percentage()` bif.
* Feature: New `slice()` bif, #2115.
* Feature: Support for UTF-8 encoding of urls, #2084.
* Feature: Added `global` flag to `define()` function.
* Feature: `match()` bif now returns the matched values instead of a boolean, #2109.
Expand Down
105 changes: 80 additions & 25 deletions docs/bifs.md
Expand Up @@ -238,31 +238,6 @@ Convert a `num` to a percentage.
percentage(4 / 100)
// => 4%

## match(pattern, string[, flags])

Retrieves the matches when matching a `val`(string) against a `pattern`(regular expression).

match('^(height|width)?([<>=]{1,})(.*)', 'height>=1024px')
// => 'height>=1024px' 'height' '>=' '1024px'

match('^foo(?:bar)?', 'foo')
// => 'foo'

match('^foo(?:bar)?', 'foobar')
// => 'foobar'

match('^foo(?:bar)?', 'bar')
// => null

match('ain', 'The rain in SPAIN stays mainly in the plain')
// => 'ain'

match('ain', 'The rain in SPAIN stays mainly in the plain', g)
// => 'ain' 'ain' 'ain'

match('ain', 'The rain in SPAIN stays mainly in the plain', 'gi')
// => 'ain' 'AIN' 'ain' 'ain'

## abs(unit)

abs(-5px)
Expand Down Expand Up @@ -413,6 +388,43 @@ Returns a `Literal` `num` converted to the provided `base`, padded to `width` wi
// => 101010


## match(pattern, string[, flags])

Retrieves the matches when matching a `val`(string) against a `pattern`(regular expression).

match('^(height|width)?([<>=]{1,})(.*)', 'height>=1024px')
// => 'height>=1024px' 'height' '>=' '1024px'

match('^foo(?:bar)?', 'foo')
// => 'foo'

match('^foo(?:bar)?', 'foobar')
// => 'foobar'

match('^foo(?:bar)?', 'bar')
// => null

match('ain', 'The rain in SPAIN stays mainly in the plain')
// => 'ain'

match('ain', 'The rain in SPAIN stays mainly in the plain', g)
// => 'ain' 'ain' 'ain'

match('ain', 'The rain in SPAIN stays mainly in the plain', 'gi')
// => 'ain' 'AIN' 'ain' 'ain'


## replace(pattern, replacement, val)

Returns string with all matches of `pattern` replaced by `replacement` in given `val`

replace(i, e, 'griin')
// => 'green'

replace(i, e, griin)
// => #008000


## join(delim, vals...)

Join the given `vals` with `delim`.
Expand All @@ -432,6 +444,49 @@ Returns a `Literal` `num` converted to the provided `base`, padded to `width` wi
join(', ', 1 2, 3 4, 5 6)
// => "1 2, 3 4, 5 6"


## split(delim, val)

The `split()`` method splits a string/ident into an array of strings by separating the string into substrings.

split(_, bar1_bar2_bar3)
// => bar1 bar2 bar3

split(_, 'bar1_bar2_bar3')
// => 'bar1' 'bar2' 'bar3'


## substr(val, start, length)

The `substr()` method returns the characters in a string beginning at the specified location through the specified number of characters.

substr(ident, 1, 2)
// => de

substr('string', 1, 2)
// => 'tr'

val = dredd
substr(substr(val, 1), 0, 3)
// => #f00


## slice(val, start[, end])

The `slice()` method extracts a section of a string/list and returns a new string/list.

slice('lorem' 'ipsum' 'dolor', 1, 2)
slice('lorem' 'ipsum' 'dolor', 1, -1)
// => 'ipsum'

slice('lorem ipsum', 1, 5)
// => 'orem'
slice(rredd, 1, -1)
// => #f00

slice(1px solid black, 1)
// => solid #000

## hsla(color | h,s,l,a)

Convert the given `color` to an `HSLA` node,
Expand Down
1 change: 1 addition & 0 deletions lib/functions/index.js
Expand Up @@ -55,6 +55,7 @@ exports.selectors = require('./selectors');
exports.shift = require('./shift');
exports.split = require('./split');
exports.substr = require('./substr');
exports.slice = require('./slice');
exports.tan = require('./tan');
exports.trace = require('./trace');
exports.transparentify = require('./transparentify');
Expand Down
28 changes: 28 additions & 0 deletions lib/functions/slice.js
@@ -0,0 +1,28 @@
var utils = require('../utils'),
nodes = require('../nodes');

/**
* This is a heler function for the slice method
*
* @param {String|Ident} vals
* @param {Unit} start [0]
* @param {Unit} end [vals.length]
* @return {String|Literal|Null}
* @api public
*/
(module.exports = function slice(val, start, end) {
start = start && start.nodes[0].val;
end = end && end.nodes[0].val;

val = utils.unwrap(val).nodes;

if (val.length > 1) {
return utils.coerce(val.slice(start, end), true);
}

var result = val[0].string.slice(start, end);

return val[0] instanceof nodes.Ident
? new nodes.Ident(result)
: new nodes.String(result);
}).raw = true;
19 changes: 19 additions & 0 deletions test/cases/bifs.slice.css
@@ -0,0 +1,19 @@
.string {
test0: 'ipsum';
test1: 'orem ipsum';
test2: 'm';
test3: 'orem ipsum';
test4: 'orem ipsu';
}
.list {
test0: 'ipsum';
test1: 'ipsum';
test2: 'ipsum' 'dolor' 'sit' 'amet,' 'consectetur' 'adipisicing' 'elit';
test3: 'elit';
test4: 'ipsum' 'dolor' 'sit' 'amet,' 'consectetur' 'adipisicing';
test5: 'ipsum' 'dolor' 'sit';
}
.ident {
test0: #f00;
test1: solid #000;
}
22 changes: 22 additions & 0 deletions test/cases/bifs.slice.styl
@@ -0,0 +1,22 @@
// string
str_short = 'lorem ipsum'
str_long = 'lorem ipsum dolor sit amet, consectetur adipisicing elit'

.string
test0 slice('lorem ipsum', 6)
test1 slice(str_short, 1)
test2 slice(str_short, -1)
test3 slice(str_short, 1, 11)
test4 slice(str_short, 1, -1)

.list
test0 slice(split(' ', str_short), 1)
test1 slice(split(' ', str_short), -1)
test2 slice(split(' ', str_long), 1)
test3 slice(split(' ', str_long), -1)
test4 slice(split(' ', str_long), 1, -1)
test5 slice(split(' ', str_long), 1, 4)

.ident
test0 slice(rredd, 1, -1)
test1 slice(1px solid black, 1)

0 comments on commit 26e04d8

Please sign in to comment.