Skip to content

Instantly share code, notes, and snippets.

@Xiphe
Last active December 30, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xiphe/7751306 to your computer and use it in GitHub Desktop.
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.
##### 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
@Xiphe
Copy link
Author

Xiphe commented Dec 2, 2013

Issue: when sources are identical, the .gitignore will be emptied but the on_stylesheet_saved callback won't be executed.

@Xiphe
Copy link
Author

Xiphe commented Dec 4, 2013

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