Refactored constraints_layout.rb to reduce duplicated code.

I created a single method that works for most of the constraints. `above`, `below`, `before`, `after` are somewhat different so I didn't refactor those. They could probably be moved into another common method as well, but probably not worth it.