Generalized Homogenization Theory and its Application to Porous Rechargeable Lithium-ion Batteries