예제 #1
0
    def test_css_absolute_filter_only_url_fragment(self):
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        content = "p { background: url('#foo') }"
        filter = CssAbsoluteFilter(content)
        self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))

        with self.settings(COMPRESS_URL='http://media.example.com/'):
            filter = CssAbsoluteFilter(content)
            self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))
예제 #2
0
 def test_css_absolute_filter_relative_path(self):
     from compressor.filters.css_default import CssAbsoluteFilter
     filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
     content = "p { background: url('../../images/image.gif') }"
     output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
     filter = CssAbsoluteFilter(content)
     self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
     settings.COMPRESS_URL = 'https://media.example.com/'
     filter = CssAbsoluteFilter(content)
     output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
     self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
예제 #3
0
    def test_css_absolute_filter_filename_outside_compress_root(self):
        filename = '/foo/bar/baz/test.css'
        content = self.template % blankdict(url='../qux/')
        params = blankdict({
            'url': settings.COMPRESS_URL + 'bar/qux/',
        })
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))

        with self.settings(COMPRESS_URL='https://static.example.com/'):
            params['url'] = settings.COMPRESS_URL + 'bar/qux/'
            output = self.template % params
            filter = CssAbsoluteFilter(content)
            self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))
예제 #4
0
    def test_css_no_hash(self):
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        content = self.template % blankdict(url='../../')
        params = blankdict({
            'url': settings.COMPRESS_URL,
        })
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))

        with self.settings(COMPRESS_URL='http://static.example.com/'):
            params['url'] = settings.COMPRESS_URL
            output = self.template % params
            filter = CssAbsoluteFilter(content)
            self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
    def input(self, filename=None, basename=None, **kwargs):

        compiler = get_scss_compiler(self.namespace, basename)
        source = scss.source.SourceFile.from_string(self.content,
                                                    relpath=basename)
        content = compiler.compile_sources(source)
        return CssAbsoluteFilter(content).input(filename, basename, **kwargs)
예제 #6
0
 def test_guess_filename(self):
     for base_url in ('/static/', 'http://static.example.com/'):
         with self.settings(COMPRESS_URL=base_url):
             url = '%s/img/python.png' % settings.COMPRESS_URL.rstrip('/')
             path = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
             content = "p { background: url('%s') }" % url
             filter = CssAbsoluteFilter(content)
             self.assertEqual(path, filter.guess_filename(url))
예제 #7
0
    def test_css_absolute_filter_relative_path(self):
        filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'static', 'whatever/../css/url/test.css')
        imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
        content = self.template % blankdict(url='../../')
        params = blankdict({
            'url': settings.COMPRESS_URL,
            'hash': '?' + self.hashing_func(imagefilename),
        })
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))

        with self.settings(COMPRESS_URL='https://static.example.com/'):
            params['url'] = settings.COMPRESS_URL
            output = self.template % params
            filter = CssAbsoluteFilter(content)
            self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
예제 #8
0
    def test_css_absolute_filter_querystring(self):
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
        content = self.template % blankdict(url='../../', query='?foo')
        params = blankdict({
            'url': settings.COMPRESS_URL,
            'query': '?foo',
            'hash': '&' + self.hashing_func(imagefilename),
        })
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))

        with self.settings(COMPRESS_URL='http://media.example.com/'):
            params['url'] = settings.COMPRESS_URL
            output = self.template % params
            filter = CssAbsoluteFilter(content)
            self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
예제 #9
0
 def test_guess_filename(self):
     import urllib
     from compressor.filters.css_default import CssAbsoluteFilter
     for base_url in ('/media/', 'http://media.example.com/'):
         settings.COMPRESS_URL = base_url
         url = '%s/img/python.png' % settings.COMPRESS_URL.rstrip('/')
         path = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
         content = "p { background: url('%s') }" % url
         filter = CssAbsoluteFilter(content)
         self.assertEqual(path, filter.guess_filename(url))
예제 #10
0
 def test_css_absolute_filter_https(self):
     from compressor.filters.css_default import CssAbsoluteFilter
     filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
     imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
     content = "p { background: url('../../img/python.png') }"
     output = "p { background: url('%simg/python.png?%s') }" % (
         settings.COMPRESS_URL, self.suffix_method(imagefilename))
     filter = CssAbsoluteFilter(content)
     self.assertEqual(
         output, filter.input(filename=filename,
                              basename='css/url/test.css'))
     settings.COMPRESS_URL = 'https://media.example.com/'
     filter = CssAbsoluteFilter(content)
     filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
     output = "p { background: url('%simg/python.png?%s') }" % (
         settings.COMPRESS_URL, self.suffix_method(imagefilename))
     self.assertEqual(
         output, filter.input(filename=filename,
                              basename='css/url/test.css'))
예제 #11
0
    def test_css_absolute_filter(self):
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
        content = self.template % blankdict(url='../../')
        params = blankdict({
            'url': settings.COMPRESS_URL,
            'hash': '?' + self.hashing_func(imagefilename),
        })
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(
            output, filter.input(filename=filename,
                                 basename='css/url/test.css'))

        settings.COMPRESS_URL = params['url'] = 'http://static.example.com/'
        output = self.template % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(
            output, filter.input(filename=filename,
                                 basename='css/url/test.css'))
예제 #12
0
 def test_css_absolute_filter(self):
     from compressor.filters.css_default import CssAbsoluteFilter
     filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
     content = "p { background: url('../../images/image.gif') }"
     output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
     filter = CssAbsoluteFilter(content)
     self.assertEqual(output, filter.input(filename=filename))
     settings.COMPRESS_URL = 'http://media.example.com/'
     filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
     output = "p { background: url('%simages/image.gif?%s') }" % (settings.COMPRESS_URL, get_hashed_mtime(filename))
     self.assertEqual(output, filter.input(filename=filename))
예제 #13
0
    def input(self, **kwargs):
        if "{lessc}" in self.command:
            options = list(self.options)
            lessc_path = os.path.join(
                settings.BASE_DIR, 'node_modules', 'less', 'bin', 'lessc')

            options.append(('lessc', lessc_path))
            self.options = tuple(options)

        content = super(LessFilter, self).input(**kwargs)
        # process absolute file paths
        return CssAbsoluteFilter(content).input(**kwargs)
예제 #14
0
    def test_css_absolute_filter_querystring(self):
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
        params = {
            'url': settings.COMPRESS_URL,
            'hash': self.hashing_func(imagefilename),
        }
        content = "p { background: url('../../img/python.png?foo') }"

        output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
        filter = CssAbsoluteFilter(content)
        self.assertEqual(
            output, filter.input(filename=filename,
                                 basename='css/url/test.css'))
        settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
        filter = CssAbsoluteFilter(content)
        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
        output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
        self.assertEqual(
            output, filter.input(filename=filename,
                                 basename='css/url/test.css'))
예제 #15
0
    def input(self, **kwargs):
        if "{lessc}" in self.command:
            options = list(self.options)

            # interim use b3 lessc path until final switchover
            lessc_path = 'lessc'

            options.append(('lessc', lessc_path))
            self.options = tuple(options)

        content = super(LessFilter, self).input(**kwargs)
        # process absolute file paths
        return CssAbsoluteFilter(content).input(**kwargs)
예제 #16
0
 def test_css_absolute_filter_relative_path(self):
     filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'static',
                             'whatever/../css/url/test.css')
     imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
     params = {
         'url': settings.COMPRESS_URL,
         'hash': self.hashing_func(imagefilename),
     }
     output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
               "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }"
               ) % params
     filter = CssAbsoluteFilter(self.content)
     self.assertEqual(
         output, filter.input(filename=filename,
                              basename='css/url/test.css'))
     settings.COMPRESS_URL = params['url'] = 'https://static.example.com/'
     filter = CssAbsoluteFilter(self.content)
     output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
               "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }"
               ) % params
     self.assertEqual(
         output, filter.input(filename=filename,
                              basename='css/url/test.css'))
예제 #17
0
    def input(self, **kwargs):
        if "{lessc}" in self.command:
            options = list(self.options)
            lessc_path = 'lessc'
            filename = self.filename.split('/')[-1]
            # for handling the migration to Bootstrap 3
            if filename not in [
                    'hqstyle-core.less',
                    'hqstyle-mobile-c2.less',
                    'app_manager.less',
                    'core.less',
            ]:
                lessc_path = settings.LESS_FOR_BOOTSTRAP_3_BINARY
            options.append(('lessc', lessc_path))
            self.options = tuple(options)

        content = super(LessFilter, self).input(**kwargs)
        # process absolute file paths
        return CssAbsoluteFilter(content).input(**kwargs)
예제 #18
0
    def input(self, **kwargs):

        #raise Exception('BACK TRACE')

        hand_filters.chrono('input:')

        # LESSC
        content = super(LessAndCssAbsoluteFilter, self).input(**kwargs)

        self.validate_input()

        # CssAbsoluteFilter
        hand_filters.chrono('\t %s' % repr(kwargs))
        kwargs['filename'] = self.init_filename
        ret = CssAbsoluteFilter(content).input(**kwargs)

        hand_filters.chrono(':input')

        return ret
예제 #19
0
    def input(self, filename=None, basename=None, **kwargs):

        compiler = get_scss_compiler(self.namespace)
        content = compiler.compile_string(self.content)
        return CssAbsoluteFilter(content).input(filename, basename, **kwargs)
예제 #20
0
 def input(self, **kwargs):
     content = super(LessFilter, self).input(**kwargs)
     kwargs.setdefault('filename', self.filename)
     return CssAbsoluteFilter(content).input(**kwargs)
예제 #21
0
 def input(self, **kwargs):
     content = super(LessFilter, self).input(**kwargs)
     return CssAbsoluteFilter(content).input(**kwargs)