Beispiel #1
0
 def __init__(self, *a, **kw):
     try:
         import json
     except ImportError:
         import simplejson as json
     self.json = json
     self.storage = ManifestStaticFilesStorage()
     self._load_manifest()
Beispiel #2
0
    class DjangoManifest(Manifest):
        """Stores version data in Django's ManifestStaticFileStorage.

        Requires Django 1.7 or later.
        """

        id = 'django'

        def __init__(self, *a, **kw):
            try:
                import json
            except ImportError:
                import simplejson as json
            self.json = json
            self.storage = ManifestStaticFilesStorage()
            self._load_manifest()

        def remember(self, bundle, ctx, version):
            output_filename = bundle.resolve_output(ctx, version=version)
            output_filename = os.path.relpath(output_filename, ctx.directory)
            source_filename = self.name_without_hash(bundle.output)

            self.storage.hashed_files[source_filename] = output_filename
            self._save_manifest()

        def query(self, bundle, ctx):
            if ctx.auto_build:
                self._load_manifest()

            source_filename = self.name_without_hash(bundle.output)
            output = self.storage.hashed_files.get(source_filename, None)
            if output:
                # foo.hash.js
                name_with_hash, ext = os.path.splitext(output)
                output = os.path.splitext(name_with_hash)[1]

            return output

        def name_without_hash(self, filename):
            name_with_hash, ext = os.path.splitext(filename)
            name = os.path.splitext(name_with_hash)[0]
            return name + ext

        def _load_manifest(self):
            self.storage.load_manifest()

        def _save_manifest(self):
            self.storage.save_manifest()
Beispiel #3
0
 def __init__(self, *a, **kw):
     try:
         import json
     except ImportError:
         import simplejson as json
     self.json = json
     self.storage = ManifestStaticFilesStorage()
     self._load_manifest()
Beispiel #4
0
    class DjangoManifest(Manifest):
        """Stores version data in Django's ManifestStaticFileStorage.
        """

        id = 'django'

        def __init__(self, *a, **kw):
            try:
                import json
            except ImportError:
                import simplejson as json
            self.json = json
            self.storage = ManifestStaticFilesStorage()
            self._load_manifest()

        def remember(self, bundle, ctx, version):
            output_filename = bundle.resolve_output(ctx, version=version)
            output_filename = os.path.relpath(output_filename, ctx.directory)
            source_filename = self.name_without_hash(bundle.output)

            self.storage.hashed_files[source_filename] = output_filename
            self._save_manifest()

        def query(self, bundle, ctx):
            if ctx.auto_build:
                self._load_manifest()

            source_filename = self.name_without_hash(bundle.output)
            output = self.storage.hashed_files.get(source_filename, None)
            if output:
                # foo.hash.js
                name_with_hash, ext = os.path.splitext(output)
                output = os.path.splitext(name_with_hash)[1].strip('.')

            return output

        def name_without_hash(self, filename):
            name_with_hash, ext = os.path.splitext(filename)
            name = os.path.splitext(name_with_hash)[0]
            return name + ext

        def _load_manifest(self):
            self.storage.load_manifest()

        def _save_manifest(self):
            self.storage.save_manifest()