I'm trying to write a program that replaces a scss function call and doubles the input e.g.
input
.color {
margin: spacing(1.5);
}
.test {
margin: spacing(2) spacing(3);
}
output
.color {
margin: spacing(3);
}
.test {
margin: spacing(4) spacing(6);
}
This almost works
gawk '{
line = $0
if (match(line, /spacing\(/)) {
print gensub(/spacing\(([0-9\.]+)\)/, "spacing(\\1 * 2)", "g", line)
} else {
print line
}
}' ./test.scss > ./test2.scss
// test2.scss
.color {
margin: spacing(1.5 * 2);
}
.test {
margin: spacing(2 * 2) spacing(3 * 2);
}
- Can you multiply by two rather than appending " * 2" to the match?
- How can you run on all
**/*.scss
files and replace them?
Solved.
https://gist.github.com/chriseppstein/57ca98ccefd642ce009d50f45998774d