This gem supports refactoring of css/less stylefiles. As of now it mainly extracts variables. Variables are recognized by a pattern:
- length : number followed by 'px' or 'em'
- color : #xxxxxx or #xxx
Add this line to your application's Gemfile:
gem 'lessFactor'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lessFactor
-
run
lessfactor varfile.less infile.less
It generates two new files:
<infile>.refactored.less - the refactored lessfile <infile>.refactored_vars.less - the new variables file
-
identify the semantics of the variables, e.g. by comparing 'infile.refactored.less' with 'infile.less'
-
rename the variables in the variables file to reflect the semantics
-
rerun lessfactor to get the new variable names
-
merge the refactored files back into your project
- find ambiguous variable names by "__@"
- investigate the highest occurrences first
This is a very first shot. Areas of improvements:
- more robust parser
- option to ignore particular literals from being refactored - no idea how to achieve that
- do not create a new variables file but patch the existing one
- apply the same for sass
- now forward comments on the variables
- expose the lines of occurrence for extracted variables
- concatenate the variable names in case of ambiguity
- fixed usage screen
- initial version
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request