Permalink
Browse files

Added json view for about/stylesheet.

  • Loading branch information...
1 parent cae49da commit c946cf011eca1977efd715f18281cc45b8c1c316 @bboe bboe committed with Logan Hanks Apr 4, 2012
Showing with 25 additions and 0 deletions.
  1. +2 −0 r2/r2/config/templates.py
  2. +23 −0 r2/r2/lib/jsontemplates.py
@@ -57,4 +57,6 @@ def api(type, cls):
api('flairlist', FlairListJsonTemplate)
api('flaircsv', FlairCsvJsonTemplate)
+api('subredditstylesheet', StylesheetTemplate)
+
tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())
View
@@ -560,3 +560,26 @@ def row_to_json(row):
class FlairCsvJsonTemplate(JsonTemplate):
def render(self, thing, *a, **kw):
return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
+
+class StylesheetTemplate(ThingJsonTemplate):
+ _data_attrs_ = dict(subreddit_id = '_fullname',
+ stylesheet = 'stylesheet_contents',
+ images = '_images')
+
+ def kind(self, wrapped):
+ return 'stylesheet'
+
+ def images(self):
+ images = []
+ for name, url in c.site.get_images():
+ images.append({'name': name,
+ 'link': 'url(%%%%%s%%%%)' % name,
+ 'url': url})
+ return images
+
+ def thing_attr(self, thing, attr):
+ if attr == '_images':
+ return self.images()
+ elif attr == '_fullname':
+ return c.site._fullname
+ return ThingJsonTemplate.thing_attr(self, thing, attr)

0 comments on commit c946cf0

Please sign in to comment.