def register(self, name, *args, **kwargs): """Register a bundle with the given name. There are two possible ways to call this: - With a single ``Bundle`` instance argument: register('jquery', jquery_bundle) - With one or multiple arguments, automatically creating a new bundle inline: register('all.js', jquery_bundle, 'common.js', output='packed.js') """ if len(args) == 0: raise TypeError("at least two arguments are required") else: if len(args) == 1 and not kwargs and isinstance(args[0], Bundle): bundle = args[0] else: bundle = Bundle(*args, **kwargs) if name in self._named_bundles: if self._named_bundles[name] == bundle: pass # ignore else: raise RegisterError( "Another bundle is already registered " + 'as "%s": %s' % (name, self._named_bundles[name]) ) else: self._named_bundles[name] = bundle bundle.env = self # take ownership return bundle
def register(self, name, *args, **kwargs): """Register a bundle with the given name. There are two possible ways to call this: - With a single ``Bundle`` instance argument: register('jquery', jquery_bundle) - With one or multiple arguments, automatically creating a new bundle inline: register('all.js', jquery_bundle, 'common.js', output='packed.js') """ if len(args) == 0: raise TypeError('at least two arguments are required') else: if len(args) == 1 and not kwargs and isinstance(args[0], Bundle): bundle = args[0] else: bundle = Bundle(*args, **kwargs) if name in self._named_bundles: if self._named_bundles[name] == bundle: pass # ignore else: raise RegisterError( 'Another bundle is already registered ' + 'as "%s": %s' % (name, self._named_bundles[name])) else: self._named_bundles[name] = bundle bundle.env = self # take ownership return bundle
def register(self, name, *args, **kwargs): """Register a :class:`Bundle` with the given ``name``. This can be called in multiple ways: - With a single :class:`Bundle` instance:: env.register('jquery', jquery_bundle) - With a dictionary, registering multiple bundles at once: bundles = {'js': js_bundle, 'css': css_bundle} env.register(bundles) .. note:: This is a convenient way to use a :doc:`loader <loaders>`: env.register(YAMLLoader('assets.yaml').load_bundles()) - With many arguments, creating a new bundle on the fly:: env.register('all_js', jquery_bundle, 'common.js', filters='rjsmin', output='packed.js') """ # Register a dict if isinstance(name, dict) and not args and not kwargs: for name, bundle in name.items(): self.register(name, bundle) return if len(args) == 0: raise TypeError("at least two arguments are required") else: if len(args) == 1 and not kwargs and isinstance(args[0], Bundle): bundle = args[0] else: bundle = Bundle(*args, **kwargs) if name in self._named_bundles: if self._named_bundles[name] == bundle: pass # ignore else: raise RegisterError( "Another bundle is already registered " + 'as "%s": %s' % (name, self._named_bundles[name]) ) else: self._named_bundles[name] = bundle bundle.env = self # take ownership return bundle
def register(self, name, *args, **kwargs): """Register a :class:`Bundle` with the given ``name``. This can be called in multiple ways: - With a single :class:`Bundle` instance:: env.register('jquery', jquery_bundle) - With a dictionary, registering multiple bundles at once: bundles = {'js': js_bundle, 'css': css_bundle} env.register(bundles) .. note:: This is a convenient way to use a :doc:`loader <loaders>`: env.register(YAMLLoader('assets.yaml').load_bundles()) - With many arguments, creating a new bundle on the fly:: env.register('all_js', jquery_bundle, 'common.js', filters='rjsmin', output='packed.js') """ # Register a dict if isinstance(name, dict) and not args and not kwargs: for name, bundle in name.items(): self.register(name, bundle) return if len(args) == 0: raise TypeError('at least two arguments are required') else: if len(args) == 1 and not kwargs and isinstance(args[0], Bundle): bundle = args[0] else: bundle = Bundle(*args, **kwargs) if name in self._named_bundles: if self._named_bundles[name] == bundle: pass # ignore else: raise RegisterError( 'Another bundle is already registered ' + 'as "%s": %s' % (name, self._named_bundles[name])) else: self._named_bundles[name] = bundle bundle.env = self # take ownership return bundle