def resolve(self, context={}): """We allow variables to be used for all arguments; this function resolves all data against a given context; This is a separate method as the management command must have the ability to check if the tag can be resolved without a context. """ def resolve_var(x): if x is None: return None else: try: return template.Variable(x).resolve(context) except template.VariableDoesNotExist: # Django seems to hide those; we don't want to expose # them either, I guess. raise def resolve_bundle(name): # If a bundle with that name exists, use it. Otherwise, # assume a filename is meant. try: return get_env()[name] except KeyError: return name return self.BundleClass( *[resolve_bundle(resolve_var(f)) for f in self.files], **{'output': resolve_var(self.output), 'filters': resolve_var(self.filters), 'debug': parse_debug_value(resolve_var(self.debug))})
def resolve(self, context={}): """We allow variables to be used for all arguments; this function resolves all data against a given context; This is a separate method as the management command must have the ability to check if the tag can be resolved without a context. """ def resolve_var(x): if x is None: return None else: try: return template.Variable(x).resolve(context) except template.VariableDoesNotExist: # Django seems to hide those; we don't want to expose # them either, I guess. raise def resolve_bundle(name): # If a bundle with that name exists, use it. Otherwise, # assume a filename is meant. try: return get_env()[name] except KeyError: return name return self.BundleClass( *[resolve_bundle(resolve_var(f)) for f in self.files], **{ 'output': resolve_var(self.output), 'filters': resolve_var(self.filters), 'debug': parse_debug_value(resolve_var(self.debug)) })
def parse_debug_value(value): """Django templates do not know what a boolean is, and anyway we need to support the 'merge' option.""" try: from webassets.env import parse_debug_value return parse_debug_value(value) except ValueError: raise template.TemplateSyntaxError( '"debug" argument must be one of the strings ' '"true", "false" or "merge", not "%s"' % value)
def resolve(self, context={}): """We allow variables to be used for all arguments; this function resolves all data against a given context. This is a separate method as the management command must have the ability to check if the tag can be resolved without a context. """ def resolve_var(x): if x is None: return None else: try: return template.Variable(x).resolve(context) except template.VariableDoesNotExist: # Django seems to hide those; we don't want to expose # them either, I guess. raise def resolve_depends(x): # Adapter to parse django template tags for depends. # into a webassets compabitble list if multiple depends is passed. # Django templates support depends in a (comma delimited form. e.g., # # {% assets filters="jsmin", output="path/to/file.js", depends="watchfile.js,second/watch/file.js" "projectfile.js" %} value = resolve_var(x) if isinstance(value, six.text_type): value = value.split(',') return value def resolve_bundle(name): # If a bundle with that name exists, use it. Otherwise, # assume a filename is meant. try: return get_env()[name] except KeyError: return name return self.BundleClass( *[resolve_bundle(resolve_var(f)) for f in self.files], **{'output': resolve_var(self.output), 'filters': resolve_var(self.filters), 'depends': resolve_depends(self.depends), 'debug': parse_debug_value(resolve_var(self.debug))})