mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
Prepare for new subreddit stylesheet system.
This adds the necessary URL-generation stuff so that subreddits cut over to the new stylesheet system will be rendered properly.
This commit is contained in:
@@ -407,9 +407,12 @@ class FrontController(RedditController, OAuth2ResourceController):
|
||||
|
||||
if c.site.stylesheet_is_static:
|
||||
# TODO: X-Private-Subreddit?
|
||||
return redirect_to(c.site.stylesheet_url)
|
||||
redirect_to(Reddit.get_subreddit_stylesheet_url())
|
||||
else:
|
||||
stylesheet_contents = c.site.stylesheet_contents
|
||||
if not c.secure:
|
||||
stylesheet_contents = c.site.stylesheet_contents
|
||||
else:
|
||||
stylesheet_contents = c.site.stylesheet_contents_secure
|
||||
|
||||
if stylesheet_contents:
|
||||
c.allow_loggedin_cache = True
|
||||
|
||||
@@ -246,6 +246,23 @@ class Reddit(Templated):
|
||||
)
|
||||
|
||||
self.toolbars = self.build_toolbars()
|
||||
self.subreddit_stylesheet_url = self.get_subreddit_stylesheet_url()
|
||||
|
||||
@staticmethod
|
||||
def get_subreddit_stylesheet_url():
|
||||
if c.can_apply_styles and c.allow_styles:
|
||||
if c.secure:
|
||||
if c.site.stylesheet_url_https:
|
||||
return c.site.stylesheet_url_https
|
||||
elif c.site.stylesheet_contents_secure:
|
||||
return c.site.stylesheet_url
|
||||
else:
|
||||
if c.site.stylesheet_url_http:
|
||||
return c.site.stylesheet_url_http
|
||||
elif c.site.stylesheet_is_static:
|
||||
return c.site.legacy_static_stylesheet_url
|
||||
elif c.site.stylesheet_contents:
|
||||
return c.site.stylesheet_url
|
||||
|
||||
def wiki_actions_menu(self, moderator=False):
|
||||
buttons = []
|
||||
|
||||
@@ -167,15 +167,17 @@ class BaseSite(object):
|
||||
".css"))
|
||||
|
||||
@property
|
||||
def stylesheet_url(self):
|
||||
from r2.lib.template_helpers import static, get_domain
|
||||
def legacy_static_stylesheet_url(self):
|
||||
from r2.lib.template_helpers import static
|
||||
assert self.stylesheet_is_static
|
||||
return static(self.static_stylesheet_name, kind='sr_stylesheet')
|
||||
|
||||
if self.stylesheet_is_static:
|
||||
return static(self.static_stylesheet_name, kind='sr_stylesheet')
|
||||
else:
|
||||
return "http://%s/stylesheet.css?v=%s" % (get_domain(cname=False,
|
||||
subreddit=True),
|
||||
self.stylesheet_hash)
|
||||
@property
|
||||
def stylesheet_url(self):
|
||||
from r2.lib.template_helpers import get_domain
|
||||
return "//%s/stylesheet.css?v=%s" % (get_domain(cname=False,
|
||||
subreddit=True),
|
||||
self.stylesheet_hash)
|
||||
|
||||
|
||||
class SubredditExists(Exception): pass
|
||||
@@ -188,7 +190,10 @@ class Subreddit(Thing, Printable, BaseSite):
|
||||
_defaults = dict(BaseSite._defaults,
|
||||
stylesheet_rtl=None,
|
||||
stylesheet_contents='',
|
||||
stylesheet_contents_secure='',
|
||||
stylesheet_modified=None,
|
||||
stylesheet_url_http="",
|
||||
stylesheet_url_https="",
|
||||
header_size=None,
|
||||
allow_top=False, # overridden in "_new"
|
||||
reported=0,
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
toolbar = new toolbar_p("${panel_size('expanded')}", "${panel_size('collapsed')}");
|
||||
</%def>
|
||||
|
||||
<%def name="sr_stylesheets()">
|
||||
</%def>
|
||||
|
||||
<%def name="bodyContent()">
|
||||
<div class="preload">
|
||||
## everything in here will get rendered off screen for pre-fetching purposes.
|
||||
|
||||
@@ -71,9 +71,9 @@
|
||||
</%def>
|
||||
|
||||
<%def name="sr_stylesheets()">
|
||||
%if c.can_apply_styles and c.allow_styles and c.site.stylesheet_hash:
|
||||
%if thing.subreddit_stylesheet_url:
|
||||
<link rel="stylesheet"
|
||||
href="${c.site.stylesheet_url}"
|
||||
href="${thing.subreddit_stylesheet_url}"
|
||||
title="applied_subreddit_stylesheet"
|
||||
type="text/css">
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user