-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTidy.js
49 lines (41 loc) · 1.37 KB
/
Tidy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const Columns = require('./Columns');
const getLocalOptions = require('./src/getLocalOptions');
const cleanClone = require('./lib/cleanClone');
/**
* Tidy class
* Collect rule-specific settings and properties; instantiate a new Columns instance.
*
* @param {Object} rule The current CSS rule.
* @param {Object} globalOptions The global plugin options.
*/
class Tidy {
constructor(rule, globalOptions) {
this.rule = rule;
// Bind class methods.
this.initRule = this.initRule.bind(this);
// Merge global and local options.
const currentOptions = getLocalOptions(this.rule, globalOptions);
// Remove the `breakpoint` property that results from merging in the breakpoint config.
if (Object.prototype.hasOwnProperty.call(currentOptions, 'breakpoint')) {
delete currentOptions.breakpoint;
}
// Instantiate Columns based on the merged options.
this.columns = new Columns(currentOptions);
}
/**
* Set up rule-specific properties.
*/
initRule() {
// The media query's selector to which conditional declarations will be appended.
this.fullWidthRule = cleanClone(this.rule);
}
/**
* Save the declaration's source value for use in other scripts.
*
* @param {Object} decl The current declaration.
*/
captureDeclarationSource(decl) {
this.declarationSource = decl.source;
}
}
module.exports = Tidy;