You don't need JASS to do that because it is fairly simple. The World Editor is not available to me right now but I'll try my best.
(Gains mana when attacked)
Event: -(Specific Unit) is attacked Condition: None Action: -Set mana for (specific unit) to (specific unit's mana) + (the amount you want gained)
(Gains mana when he attacks)
Event: -A unit is attacked Condition: -(Attacking unit) equal to (specific unit) Action: -Set mana for (attacking unit) to (attacking unit's mana) + (the amount you want gained)
I will look in the World Editor later and if that is incorrect I will post again right away.
Make a custom ability based off of the Devotion Aura ability. Set the armor bonus to zero and the name and tooltip for whatever you want and the buff of the aura (the blue cross that points outward of the Hero) to whatever you want for the "Mana Gain" ability. Or you could make it nothing, it's your ability.
Give that to the Hero and pretend it's called "Mana Gain". Add those triggers in the trigger editor that I put in my last post. And there you go. If you want "Mana Gain" to have multiple levels then post again.
Yeah I just figured out how to make the Unit - Set mana of (triggering unit) to ((Mana of (Triggering Unit)) + whatever)) action. Funny thing though, I had to figure out how it worked through JASS before I saw how simple it actually was.