An attacker can't take ALL of your resources, so I'm not sure what you're talking about. The amount that can be taken is a sliding scale depending upon your TH level and your opponents TH level. The most that can be taken from you is 20%. If you want more information about this and other CoC details, go here:
http://clashofclans.wikia.com/wiki/Clash_of_Clans_Wiki
For more specific info regarding raiding and loot, go here:
http://clashofclans.wikia.com/wiki/Raids
Lastly, when you raid, make sure you raid enough in one sitting to cover at least a 20% lost due to someone raiding you when you log off.