mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
Add utility for sending wrapped things in js_preload.
This commit is contained in:
@@ -232,3 +232,14 @@ def wrap_links(links, wrapper = default_thing_wrapper(),
|
||||
return l.listing()
|
||||
|
||||
|
||||
def wrap_things(*things):
|
||||
"""Instantiate Wrapped for each thing, calling add_props if available."""
|
||||
if not things:
|
||||
return []
|
||||
|
||||
wrapped = [Wrapped(thing) for thing in things]
|
||||
if hasattr(things[0], 'add_props'):
|
||||
# assume all things are of the same type and use the first thing's
|
||||
# add_props to process the list.
|
||||
things[0].add_props(c.user, wrapped)
|
||||
return wrapped
|
||||
|
||||
@@ -168,6 +168,12 @@ class JSPreload(js.DataSource):
|
||||
def set(self, url, data):
|
||||
self.data[url] = data
|
||||
|
||||
def set_wrapped(self, url, wrapped):
|
||||
from r2.lib.pages.things import wrap_things
|
||||
if not isinstance(wrapped, Wrapped):
|
||||
wrapped = wrap_things(wrapped)[0]
|
||||
self.data[url] = wrapped.render_nocache('', style='api').finalize()
|
||||
|
||||
def use(self):
|
||||
hooks.get_hook("js_preload.use").call(js_preload=self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user