def handle(self, *args, **options): if len(args) == 0: raise CommandError('You need to specify a subcommand') elif len(args) > 1: raise CommandError('Invalid number of subcommands passed: %s' % ", ".join(args)) else: command = args[0] options['verbosity'] = int(options['verbosity']) if command == 'rebuild': # Start with the bundles that are defined in code. if options.get('verbosity') > 1: print "Looking for bundles defined in code..." registry.autoload() bundles = [v for k, v in registry.iter()] # If requested, search the templates too. if options.get('parse_templates'): bundles += self._parse_templates(options) else: if not bundles: raise CommandError( 'No asset bundles were found. ' 'If you are defining assets directly within your ' 'templates, you want to use the --parse-templates ' 'option.') self._rebuild_assets(options, bundles) else: raise CommandError('Unknown subcommand: %s' % command)
def handle(self, *args, **options): if len(args) == 0: raise CommandError('You need to specify a subcommand: rebuild') elif len(args) > 1: raise CommandError('Invalid number of subcommands passed: %s' % ", ".join(args)) else: command = args[0] options['verbosity'] = int(options.get('verbosity', 1)) if command == 'rebuild': # Start with the bundles that are defined in code. if options.get('verbosity') > 1: print "Looking for bundles defined in code..." registry.autoload() bundles = [v for k, v in registry.iter()] # If requested, search the templates too. if options.get('parse_templates'): bundles += self._parse_templates(options) else: if not bundles: raise CommandError('No asset bundles were found. ' 'If you are defining assets directly within your ' 'templates, you want to use the --parse-templates ' 'option.') self._rebuild_assets(options, bundles) else: raise CommandError('Unknown subcommand: %s' % command)
def _render_assets(self, filter, output, files, caller=None): # resolve bundle names registry.autoload() files = [registry.get(f) or f for f in files] result = u"" urls = Bundle(*files, **{'output': output, 'filters': filter}).urls() for f in urls: result += caller(f) return result
class AssetsNode(template.Node): def __init__(self, filter, output, files, childnodes): self.childnodes = childnodes self.output = output self.files = files self.filter = filter 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, e: # Django seems to hide those; we don't want to expose # them either, I guess. raise def resolve_bundle(x): bundle = registry.get(x) if bundle: return bundle return x registry.autoload() return Bundle(*[resolve_bundle(resolve_var(f)) for f in self.files], **{'output': resolve_var(self.output), 'filters': resolve_var(self.filter)})
def handle(self, *args, **options): valid_commands = ['rebuild', 'watch', 'clean',] if len(args) > 1: raise CommandError('Invalid number of subcommands passed: %s' % ", ".join(args)) elif len(args) == 0: raise CommandError('You need to specify a subcommand: %s' % ', '.join(valid_commands)) else: command = args[0] if not command in valid_commands: raise CommandError(('Not a supported subcommand: %s. Valid '+ 'choices are: %s') % ( command, ', '.join(valid_commands))) command = getattr(self, 'CMD_%s' % command) options['verbosity'] = int(options.get('verbosity', 1)) # Find the user's assets. # Start with the bundles that are defined in code. if options.get('verbosity') > 1: print "Looking for bundles defined in code..." registry.autoload() bundles = [v for k, v in registry.iter()] # If requested, search the templates too. if options.get('parse_templates'): bundles += self._parse_templates(options) else: if not bundles: raise CommandError('No asset bundles were found. ' 'If you are defining assets directly within your ' 'templates, you want to use the --parse-templates ' 'option.') # Run the correct subcommand command(options, bundles)