Created
July 13, 2012 11:15
-
-
Save karlbright/3104345 to your computer and use it in GitHub Desktop.
Page Classes for ApplicationHelper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def page_classes | |
classes = [] | |
# Get our path along with action name | |
path = controller.controller_path.split('/') << controller.action_name | |
# Add appropriate class based on namespace | |
if path[0] != 'admin' | |
classes << 'public' | |
end | |
# Add class based on whether or not sidebar content is provided | |
if content_for?(:sidebar) || content_for?(:contextual_sidebar_nav) | |
classes << "has-sidebar" | |
else | |
classes << "no-sidebar" | |
end | |
# Add path components | |
classes << path.length.times.map { |length| path[0..length].join('-') }.join(' ') | |
# Add classes for controller and action name | |
classes << "#{controller.controller_name}-controller" | |
classes << "#{controller.action_name}-action" | |
# Return classes as space seperated string | |
return classes.join(' ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment