Skip to content

Commit

Permalink
Merge pull request #46 from maximkoretskiy/drop-lodash-templatest
Browse files Browse the repository at this point in the history
Drop lodash templates
  • Loading branch information
maximkoretskiy authored Apr 14, 2021
2 parents bc8f1f6 + 725f076 commit ff9aa1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3,113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
npm-debug.log
.vscode/
yarn.lock
25 changes: 15 additions & 10 deletions lib/rules-fabric.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
var template = require('lodash.template');
var decls = require('./decls.json');

function template(string, data) {
return string.replace(/\$\{([\w\-\.]*)\}/g, function (_str, key) {
var v = data[key];
return typeof v !== 'undefined' && v !== null ? v : '';
});
}

/*
Rules legend:
- combined - if rule is combined it will be rendered with template
Expand All @@ -23,8 +29,7 @@ function _compileDecls(inputDecls) {
var templateVars = _getRulesMap(inputDecls);
return inputDecls.map(function (decl) {
if (decl.combined && decl.initial) {
var t = template(decl.initial.replace(/\-/g, ''));
decl.initial = t(templateVars);
decl.initial = template(decl.initial.replace(/\-/g, ''), templateVars);
}
return decl;
});
Expand All @@ -33,8 +38,8 @@ function _compileDecls(inputDecls) {
function _getRequirements(inputDecls) {
return inputDecls.reduce(function (map, decl) {
if (!decl.contains) return map;
return decl.contains.reduce(function (mapInner, dependensy) {
mapInner[dependensy] = decl;
return decl.contains.reduce(function (mapInner, dependency) {
mapInner[dependency] = decl;
return mapInner;
}, map);
}, {});
Expand All @@ -46,11 +51,11 @@ function _expandContainments(inputDecls) {
.filter(function (decl) {
return !decl.contains;
}).map(function (decl) {
var dependensy = requiredMap[decl.prop];
if (dependensy) {
decl.requiredBy = dependensy.prop;
decl.basic = decl.basic || dependensy.basic;
decl.inherited = decl.inherited || dependensy.inherited;
var dependency = requiredMap[decl.prop];
if (dependency) {
decl.requiredBy = dependency.prop;
decl.basic = decl.basic || dependency.basic;
decl.inherited = decl.inherited || dependency.inherited;
}
return decl;
});
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"type": "git",
"url": "https://github.com/maximkoretskiy/postcss-initial.git"
},
"dependencies": {
"lodash.template": "^4.5.0"
},
"dependencies": {},
"peerDependencies": {
"postcss": "^8.0.0"
},
Expand Down
Loading

0 comments on commit ff9aa1c

Please sign in to comment.