コード例 #1
0
ファイル: core.py プロジェクト: sdcooke/django_bundles
    def __init__(self, filename, files_root, url_root, media, bundle_type, precompile_in_debug, extra=None):
        # basic settings
        self.bundle_type = bundle_type
        self.file_path = os.path.join(files_root, filename)
        self.file_url = os.path.join(url_root, filename)
        self.precompile_in_debug = precompile_in_debug
        if self.precompile_in_debug:
            self.precompile_url = os.path.join(url_root, '%s.%s' % (os.path.splitext(filename)[0], self.bundle_type))
            self.precompile_path = '%s.%s' % (os.path.splitext(self.file_path)[0], self.bundle_type)
        self.media = media

        # file_type (or take from extension)
        if extra and 'type' in extra:
            self.file_type = extra['type']
        else:
            self.file_type = os.path.splitext(filename)[1][1:]

        # Lint setting and default
        if bundle_type in bundles_settings.BUNDLES_LINTING:
            self.lint = bundles_settings.BUNDLES_LINTING[bundle_type].get('default', False)
            if extra and 'lint' in extra:
                self.lint = extra['lint']
        else:
            self.lint = False

        # Preprocessors or get defaults
        if extra and 'processors' in extra:
            self.processors = processor_library.get_processors(extra['processors'])
        else:
            self.processors = processor_library.get_default_preprocessors_for(self.file_type)
コード例 #2
0
ファイル: core.py プロジェクト: theospears/django_bundles
    def __init__(self, filename, files_root, url_root, media, bundle_type, extra=None):
        # basic settings
        self.file_path = os.path.join(files_root, filename)
        self.file_url = os.path.join(url_root, filename)
        self.media = media

        # file_type (or take from extension)
        if extra and 'type' in extra:
            self.file_type = extra['type']
        else:
            self.file_type = os.path.splitext(filename)[1][1:]

        # Lint setting and default
        if bundle_type in bundles_settings.BUNDLES_LINTING:
            self.lint = bundles_settings.BUNDLES_LINTING[bundle_type].get('default', False)
            if extra and 'lint' in extra:
                self.lint = extra['lint']
        else:
            self.lint = False

        # Preprocessors or get defaults
        if extra and 'processors' in extra:
            self.processors = processor_library.get_processors(extra['processors'])
        else:
            self.processors = processor_library.get_default_preprocessors_for(self.file_type)
コード例 #3
0
ファイル: core.py プロジェクト: sdcooke/django_bundles
    def __init__(self, conf):
        """
        Initialize a bundle and it's BundleFiles based on a conf dict
        """
        self.name = conf[0]

        conf_dict = conf[1]

        # Basic settings and defaults
        self.bundle_type = conf_dict['type']
        self.files_url_root = conf_dict.get('files_url_root', settings.MEDIA_URL)
        self.files_root = conf_dict.get('files_root', settings.MEDIA_ROOT)
        self.uglify_command = conf_dict.get('uglify_command')
        self.source_map_file_root = conf_dict.get('source_map_file_root')
        self.source_map_url_root = conf_dict.get('source_map_url_root')
        self.source_map_files_url_root = conf_dict.get('source_map_files_url_root') or self.files_url_root
        self.media = conf_dict.get('media')
        self.bundle_url_root = conf_dict.get('bundle_url_root') or self.files_url_root
        self.bundle_file_root = conf_dict.get('bundle_file_root') or self.files_root
        self.bundle_filename = conf_dict.get('bundle_filename') or self.name
        self.precompile_in_debug = False if bundles_settings.GLOBAL_PRECOMPILE_DISABLE else conf_dict.get('precompile_in_debug', False)
        self.fixed_bundle_url = conf_dict.get('bundle_url')
        self.fixed_bundle_file_path = conf_dict.get('bundle_file_path')

        # Build the list of BundleFiles
        self.files = []
        self._bundle_files = {}

        for fileconf in list(conf_dict['files']):
            path, extra = fileconf, None
            # Each file definition can be a string or tuple containing the path and the conf dict
            if isinstance(fileconf, (tuple, list)):
                path = fileconf[0]
                extra = fileconf[1]

            # Expand *s in filenames
            try:
                for filename in expand_file_names(path, self.files_root):
                    bundle_file = BundleFile(filename, self.files_root, self.files_url_root, self.media, self.bundle_type, self.precompile_in_debug, extra=extra)
                    self.files.append(bundle_file)
                    self._bundle_files[bundle_file.file_path] = bundle_file
            except OSError:
                raise ImproperlyConfigured("Bundle %s - could not find file(s): %s" % (self.name, path))

        # Get the processors or use the default list
        if 'processors' in conf_dict:
            self.processors = processor_library.get_processors(conf_dict['processors'])
        else:
            self.processors = processor_library.get_default_postprocessors_for(self.bundle_type)
コード例 #4
0
ファイル: core.py プロジェクト: theospears/django_bundles
    def __init__(self, conf):
        """
        Initialize a bundle and it's BundleFiles based on a conf dict
        """
        self.name = conf[0]

        conf_dict = conf[1]

        # Basic settings and defaults
        self.bundle_type = conf_dict['type']
        self.files_url_root = conf_dict.get('files_url_root', settings.MEDIA_URL)
        self.files_root = conf_dict.get('files_root', settings.MEDIA_ROOT)
        self.uglify_command = conf_dict.get('uglify_command')
        self.source_map_file_root = conf_dict.get('source_map_file_root')
        self.source_map_url_root = conf_dict.get('source_map_url_root')
        self.source_map_files_url_root = conf_dict.get('source_map_files_url_root') or self.files_url_root
        self.media = conf_dict.get('media')
        self.bundle_url_root = conf_dict.get('bundle_url_root') or self.files_url_root
        self.bundle_file_root = conf_dict.get('bundle_file_root') or self.files_root
        self.bundle_filename = conf_dict.get('bundle_filename') or self.name
        self.create_debug = conf_dict.get('debug', False)

        # Build the list of BundleFiles
        self.files = []
        self._bundle_files = {}

        for fileconf in list(conf_dict['files']):
            path, extra = fileconf, None
            # Each file definition can be a string or tuple containing the path and the conf dict
            if isinstance(fileconf, (tuple, list)):
                path = fileconf[0]
                extra = fileconf[1]

            # Expand *s in filenames
            try:
                for filename in expand_file_names(path, self.files_root):
                    bundle_file = BundleFile(filename, self.files_root, self.files_url_root, self.media, self.bundle_type, extra=extra)
                    self.files.append(bundle_file)
                    self._bundle_files[bundle_file.file_path] = bundle_file
            except OSError:
                raise ImproperlyConfigured("Bundle %s - could not find file(s): %s" % (self.name, path))

        # Get the processors or use the default list
        if 'processors' in conf_dict:
            self.processors = processor_library.get_processors(conf_dict['processors'])
        else:
            self.processors = processor_library.get_default_postprocessors_for(self.bundle_type)