@localnerve/sass-asset-functions 6.10.0-rc.1 → 6.10.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -34
- package/cjs/lib/modernAPIAsync.cjs +1 -1
- package/cjs/lib/types.cjs +18 -1
- package/lib/modernAPIAsync.js +1 -1
- package/lib/types.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,7 +87,8 @@ You can specify the paths to your resources using the following options (shown w
|
|
|
87
87
|
images_path: 'public/images', // local directory
|
|
88
88
|
fonts_path: 'public/fonts',
|
|
89
89
|
http_images_path: '/images', // web path
|
|
90
|
-
http_fonts_path: '/fonts'
|
|
90
|
+
http_fonts_path: '/fonts',
|
|
91
|
+
data: {}
|
|
91
92
|
}
|
|
92
93
|
```
|
|
93
94
|
|
|
@@ -120,39 +121,9 @@ const result = sass.compile(scss_filename, {
|
|
|
120
121
|
});
|
|
121
122
|
```
|
|
122
123
|
|
|
123
|
-
#### `
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
const result = sass.compile(scss_filename, {
|
|
127
|
-
functions: assetFunctions({
|
|
128
|
-
asset_host: (http_path, done) => {
|
|
129
|
-
done('http://assets.example.com');
|
|
130
|
-
// or use the supplied path to calculate a host
|
|
131
|
-
done(`http://assets${http_path.length % 4}.example.com`);
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
[, options...]
|
|
135
|
-
});
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
#### `asset_cache_buster`: a function to rewrite the asset path
|
|
139
|
-
|
|
140
|
-
When this function returns a string, it's set as the query of the path. When returned an object, `path` and `query` will be used.
|
|
141
|
-
|
|
142
|
-
```js
|
|
143
|
-
const result = sass.compile(scss_filename, {
|
|
144
|
-
functions: assetFunctions({
|
|
145
|
-
asset_cache_buster: (http_path, real_path, done) => {
|
|
146
|
-
done('v=123');
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
[, options...]
|
|
150
|
-
});
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
#### `lookup`: a function to use arbitrary data in scss stylesheets
|
|
124
|
+
#### `lookup`: a function to use arbitrary data in sass stylesheets
|
|
154
125
|
|
|
155
|
-
This function retrieves arbitrary build-time data for reference in stylesheet compilation. Could be an asset name, prefix, or could be a whole list or map of things. Here's the list of javascript
|
|
126
|
+
This function retrieves arbitrary build-time data for reference in stylesheet compilation. Could be an asset name, prefix, or could be a whole list or map of things. Here's the list of javascript type mappings (everything else returns SassNull):
|
|
156
127
|
* Boolean => SassBoolean
|
|
157
128
|
* Number => SassNumber
|
|
158
129
|
* String => SassString
|
|
@@ -201,7 +172,37 @@ $nested-data: lookup('nested', 'process-map');
|
|
|
201
172
|
}
|
|
202
173
|
```
|
|
203
174
|
|
|
204
|
-
|
|
175
|
+
#### `asset_host`: a function which completes with a string used as asset host.
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
const result = sass.compile(scss_filename, {
|
|
179
|
+
functions: assetFunctions({
|
|
180
|
+
asset_host: (http_path, done) => {
|
|
181
|
+
done('http://assets.example.com');
|
|
182
|
+
// or use the supplied path to calculate a host
|
|
183
|
+
done(`http://assets${http_path.length % 4}.example.com`);
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
[, options...]
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### `asset_cache_buster`: a function to rewrite the asset path
|
|
191
|
+
|
|
192
|
+
When this function returns a string, it's set as the query of the path. When returned an object, `path` and `query` will be used.
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
const result = sass.compile(scss_filename, {
|
|
196
|
+
functions: assetFunctions({
|
|
197
|
+
asset_cache_buster: (http_path, real_path, done) => {
|
|
198
|
+
done('v=123');
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
[, options...]
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
##### A more advanced example of `asset_cache_buster`:
|
|
205
206
|
|
|
206
207
|
Here we include the file's hexdigest in the path, using the [`hexdigest`](https://github.com/koenpunt/node-hexdigest) module.
|
|
207
208
|
|
|
@@ -118,8 +118,8 @@ function modernAPIAsync(sass, processor) {
|
|
|
118
118
|
let result = sass.sassNull;
|
|
119
119
|
processor.lookup(keys, value => {
|
|
120
120
|
result = (0, _types.convertToSassTypesModern)(sass, value);
|
|
121
|
+
resolve(result);
|
|
121
122
|
});
|
|
122
|
-
resolve(result);
|
|
123
123
|
} catch (err) {
|
|
124
124
|
reject(err);
|
|
125
125
|
}
|
package/cjs/lib/types.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var _immutable = require("immutable");
|
|
|
9
9
|
/**
|
|
10
10
|
* Convert javascript types to sass types.
|
|
11
11
|
*
|
|
12
|
-
* Supported:
|
|
12
|
+
* Supported Mappings:
|
|
13
13
|
* Boolean => Sass.Boolean
|
|
14
14
|
* Number => Sass.Number
|
|
15
15
|
* String => Sass.String
|
|
@@ -28,6 +28,14 @@ var _immutable = require("immutable");
|
|
|
28
28
|
* Licensed under the MIT license.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Convert a javascript value to a sass value of corresponding type.
|
|
33
|
+
* Modern Sass version.
|
|
34
|
+
*
|
|
35
|
+
* @param {Sass} sass - Sass javascript API
|
|
36
|
+
* @param {*} value - A javascript value
|
|
37
|
+
* @returns {SassType} - A Sass typed value for the given javascript value
|
|
38
|
+
*/
|
|
31
39
|
function convertToSassTypesModern(sass, value) {
|
|
32
40
|
switch (typeof value) {
|
|
33
41
|
case 'boolean':
|
|
@@ -66,6 +74,15 @@ function convertToSassTypesModern(sass, value) {
|
|
|
66
74
|
return sass.sassNull;
|
|
67
75
|
}
|
|
68
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Convert a javascript value to a sass value of corresponding type.
|
|
80
|
+
* Legacy Sass version.
|
|
81
|
+
*
|
|
82
|
+
* @param {Sass} sass - Sass javascript API
|
|
83
|
+
* @param {*} value - A javascript value
|
|
84
|
+
* @returns {SassType} - A Sass typed value for the given javascript value
|
|
85
|
+
*/
|
|
69
86
|
function convertToSassTypesLegacy(sass, value) {
|
|
70
87
|
switch (typeof value) {
|
|
71
88
|
case 'boolean':
|
package/lib/modernAPIAsync.js
CHANGED
|
@@ -104,8 +104,8 @@ export default function modernAPIAsync (sass, processor) {
|
|
|
104
104
|
let result = sass.sassNull;
|
|
105
105
|
processor.lookup(keys, value => {
|
|
106
106
|
result = convertToSassTypesModern(sass, value);
|
|
107
|
+
resolve(result);
|
|
107
108
|
});
|
|
108
|
-
resolve(result);
|
|
109
109
|
} catch (err) {
|
|
110
110
|
reject(err);
|
|
111
111
|
}
|
package/lib/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Convert javascript types to sass types.
|
|
3
3
|
*
|
|
4
|
-
* Supported:
|
|
4
|
+
* Supported Mappings:
|
|
5
5
|
* Boolean => Sass.Boolean
|
|
6
6
|
* Number => Sass.Number
|
|
7
7
|
* String => Sass.String
|
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { OrderedMap } from 'immutable';
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Convert a javascript value to a sass value of corresponding type.
|
|
26
|
+
* Modern Sass version.
|
|
27
|
+
*
|
|
28
|
+
* @param {Sass} sass - Sass javascript API
|
|
29
|
+
* @param {*} value - A javascript value
|
|
30
|
+
* @returns {SassType} - A Sass typed value for the given javascript value
|
|
31
|
+
*/
|
|
24
32
|
export function convertToSassTypesModern (sass, value) {
|
|
25
33
|
switch (typeof value) {
|
|
26
34
|
case 'boolean':
|
|
@@ -61,6 +69,14 @@ export function convertToSassTypesModern (sass, value) {
|
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Convert a javascript value to a sass value of corresponding type.
|
|
74
|
+
* Legacy Sass version.
|
|
75
|
+
*
|
|
76
|
+
* @param {Sass} sass - Sass javascript API
|
|
77
|
+
* @param {*} value - A javascript value
|
|
78
|
+
* @returns {SassType} - A Sass typed value for the given javascript value
|
|
79
|
+
*/
|
|
64
80
|
export function convertToSassTypesLegacy (sass, value) {
|
|
65
81
|
switch (typeof value) {
|
|
66
82
|
case 'boolean':
|