1 from types import StringTypes, ListType
5 """A class for collecting dependencies on js/css files or fragments"""
7 keys=[ 'js_files','css_files','js_chunks', 'css_chunks' ]
9 # it's tempting to use sets but sets are not ordered..
16 def _normalize (input):
17 if isinstance (input, ListType): return input
18 elif isinstance (input, StringTypes): return [ input ]
19 else: return list (input)
21 def add_js_files (self, x):
22 for i in Prelude._normalize (x):
23 if i not in self.js_files: self.js_files.append(i)
24 def add_css_files (self, x):
25 for i in Prelude._normalize (x):
26 if i not in self.css_files: self.css_files.append(i)
27 def add_js_chunks (self, x):
28 self.js_chunks += Prelude._normalize (x)
29 def add_css_chunks (self, x):
30 self.css_chunks += Prelude._normalize (x)
32 def render_env (self):
34 env['js_files']= self.js_files
35 env['css_files']= self.css_files
36 env['js_chunks']= '\n'.join(self.js_chunks)
37 env['css_chunks']='\n'.join(self.css_chunks)