Last active
December 30, 2015 00:39
-
-
Save Xiphe/7751306 to your computer and use it in GitHub Desktop.
Create .gitignore for parsed sass files. When using css, less and sass side by side and all css files are in the same folder (even the ones created by sass) this is a way to prevent the generated files from being checked in into your repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### automatically create a .gitignore containing all created css files inside the css folder. | |
# Absolute path to css dir | |
abs_css_dir = File.absolute_path(css_dir) + '/' | |
# .gitignore File instance | |
gitignore_file = File.open(css_dir + '/.gitignore', 'a+') | |
gitignore_lines = gitignore_file.readlines | |
# banner for gitignore file. | |
gitignore_banner = <<-eos | |
# All the css files below are parsed .sass files end thus should not be checked into our repository! | |
# This File is automatically created by `#{Dir.pwd}/config.rb` | |
.gitignore | |
eos | |
# Check if gitignore file is usable and put a ring on it. | |
if !gitignore_lines.any? | |
gitignore_file.write gitignore_banner | |
elsif gitignore_lines.first != gitignore_banner.lines.first | |
raise "`#{File.absolute_path(gitignore_file)}` can not be used to ignore parsed .sass files. Deal with it." | |
end | |
# Whenever a new stylesheet is created by compass, ensure it's ignored! | |
on_stylesheet_saved do |filename| | |
filename.slice! abs_css_dir | |
unless gitignore_lines.grep(/^#{Regexp.escape(filename)}[\s]?$/).any? | |
gitignore_file.write "\n" + filename | |
end | |
end |
fixed
Next up: Find a way to delete the whole .gitignore on compass compile --force
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue: when sources are identical, the .gitignore will be emptied but the on_stylesheet_saved callback won't be executed.