Skip to content

Instantly share code, notes, and snippets.

@paulrobertlloyd
Last active August 29, 2015 14:05
Show Gist options
  • Save paulrobertlloyd/d74a56e5273df4256ea1 to your computer and use it in GitHub Desktop.
Save paulrobertlloyd/d74a56e5273df4256ea1 to your computer and use it in GitHub Desktop.
Rake task to concatenate CSS files
destination = 'public'
source = 'source'
desc "Concatenate CSS files"
task :concatenate_css do
files = FileList["#{source}/**/*.css"]
concatenated_filename = "#{destination}/stylesheets/styles.css"
File.open(concatenated_filename, "w") do |output|
files.each do |input|
puts "Reading #{input}"
output.write(File.read(input))
output.write("\n")
end
end
end
@tylergaw
Copy link

Just a guess here, but I wonder if you need to use write near line 12? Something like:

output.write(input)

@tylergaw
Copy link

or maybe output.write(File.read(input))

@paulrobertlloyd
Copy link
Author

Neither of these work… it appears as if files are being read, but their content is ignored. Hmmm.

@ifduyue
Copy link

ifduyue commented Aug 15, 2014

      puts "Reading #{input}"
      output.write(File.read(input))
      output.write("\n")

And file assignment is unnecessary.

@paulrobertlloyd
Copy link
Author

Have updated code with what I believe are the suggested changes, but this still doesn’t work! Output of the file is still a series of line breaks.

@ifduyue
Copy link

ifduyue commented Aug 15, 2014

It works fine on my laptop. Delete the destination file and try again? Make sure you are not opening another file instead of the destination file.

@paulrobertlloyd
Copy link
Author

Okay, sounds like I may be doing something stupid my end…!

@paulrobertlloyd
Copy link
Author

I can confirm, I was doing something stupid! At some point during implementing these suggestions, the content in each of the source files was deleted. All working now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment