Skip to content

Commit

Permalink
Add semantic top-level page classes for use in theming.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromakode authored and spladug committed Mar 6, 2012
1 parent a70236f commit 36f48e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions r2/r2/controllers/front.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def GET_comments(self, article, comment, context, sort, limit, depth):

res = LinkInfoPage(link = article, comment = comment,
content = displayPane,
page_classes = ['comments-page'],
subtitle = subtitle,
subtitle_buttons = subtitle_buttons,
nav_menus = [CommentSortMenu(default = sort)],
Expand Down Expand Up @@ -787,6 +788,7 @@ def GET_submit(self, url, title, then):

return FormPage(_("submit"),
show_sidebar = True,
page_classes=['submit-page'],
content=NewLink(url=url or '',
title=title or '',
subreddits = sr_names,
Expand Down
2 changes: 2 additions & 0 deletions r2/r2/controllers/listingcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ListingController(RedditController):

#extra parameters to send to the render_cls constructor
render_params = {}
extra_page_classes = ['listing-page']

@property
def menus(self):
Expand All @@ -104,6 +105,7 @@ def build_listing(self, num, after, reverse, count):
content = self.content()

res = self.render_cls(content = content,
page_classes = self.extra_page_classes,
show_sidebar = self.show_sidebar,
nav_menus = self.menus,
title = self.title(),
Expand Down
24 changes: 23 additions & 1 deletion r2/r2/lib/pages/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ class Reddit(Templated):
site_tracking = True
show_firsttext = True
additional_css = None
extra_page_classes = None

def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
infotext = '', content = None, short_description='', title = '', robots = None,
show_sidebar = True, footer = True, srbar = True,
show_sidebar = True, footer = True, srbar = True, page_classes = None,
**context):
Templated.__init__(self, **context)
self.title = title
Expand All @@ -141,6 +142,7 @@ def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
self.space_compress = space_compress and not g.template_debug
# instantiate a footer
self.footer = RedditFooter() if footer else None
self.supplied_page_classes = page_classes or []

#put the sort menus at the top
self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None
Expand Down Expand Up @@ -391,6 +393,23 @@ def content(self):
"""returns a Wrapped (or renderable) item for the main content div."""
return self.content_stack((self.infobar, self.nav_menu, self._content))

def page_classes(self):
classes = set()
if c.user_is_loggedin:
classes.add('loggedin')
if not isinstance(c.site, FakeSubreddit):
if c.site.is_subscriber(c.user):
classes.add('subscriber')
if c.site.is_moderator(c.user):
classes.add('moderator')
if c.cname:
classes.add('cname')
if self.extra_page_classes:
classes.update(self.extra_page_classes)
if self.supplied_page_classes:
classes.update(self.supplied_page_classes)
return classes

class AccountActivityBox(Templated):
def __init__(self):
super(AccountActivityBox, self).__init__()
Expand Down Expand Up @@ -745,6 +764,7 @@ class OAuth2Authorization(Templated):
class SearchPage(BoringPage):
"""Search results page"""
searchbox = False
extra_page_classes = ['search-page']

def __init__(self, pagename, prev_search, elapsed_time,
num_results, search_params = {},
Expand Down Expand Up @@ -810,6 +830,7 @@ class LinkInfoPage(Reddit):
"""

create_reddit_box = False
extra_page_classes = ['single-page']

def __init__(self, link = None, comment = None,
link_title = '', subtitle = None, duplicates = None,
Expand Down Expand Up @@ -1131,6 +1152,7 @@ class ProfilePage(Reddit):
searchbox = False
create_reddit_box = False
submit_box = False
extra_page_classes = ['profile-page']

def __init__(self, user, *a, **kw):
self.user = user
Expand Down
3 changes: 2 additions & 1 deletion r2/r2/templates/reddit.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
%>
<%namespace file="login.html" import="login_panel, login_form"/>
<%namespace file="framebuster.html" import="framebuster"/>
<%namespace file="utils.html" import="tags"/>
<%inherit file="base.html"/>

<%def name="Title()">
Expand Down Expand Up @@ -124,7 +125,7 @@
</%def>

<%def name="bodyHTML()">
<body>
<body ${tags(_class=' '.join(thing.page_classes()))}>
<%include file="redditheader.html"/>

%if thing.show_sidebar:
Expand Down

0 comments on commit 36f48e5

Please sign in to comment.