Beispiel #1
0
    def test_compile_static(self):
        mocked_coffeescript_compiler = MagicMock()
        mocked_coffeescript_compiler.is_supported.side_effect = lambda source_path: source_path.endswith(".coffee")
        mocked_coffeescript_compiler.compile.return_value = "compiled coffeescript"
        mocked_less_compiler = MagicMock()
        mocked_less_compiler.is_supported.side_effect = lambda source_path: source_path.endswith(".less")
        mocked_less_compiler.compile.return_value = "compiled less"

        with patch("static_precompiler.utils.get_compilers") as mocked_get_compilers:
            mocked_get_compilers.return_value = [
                mocked_coffeescript_compiler,
                mocked_less_compiler
            ]
            self.assertEquals(
                compile_static("test.coffee"),
                "compiled coffeescript"
            )
            self.assertEquals(
                compile_static("test.less"),
                "compiled less"
            )
            self.assertRaises(
                UnsupportedFile,
                lambda: compile_static("test.sass")
            )
Beispiel #2
0
def compile_if_debug(path):
    # This is a bit of hackery to make static precompilation work with manifest storage
    if settings.DEBUG:
        try:
            compile_static(path)
        except FileExistsError:
            compile_static(path)
    return path.replace('.scss', '.css')
def compile_tag(source_path, compiler=None):
    if compiler:
        compiled = compiler.compile(source_path)
    else:
        compiled = compile_static(source_path)
    if PREPEND_STATIC_URL:
        compiled = static(compiled)
    return compiled
Beispiel #4
0
def compile_tag(source_path, compiler=None):
    if compiler:
        compiled = compiler.compile(source_path)
    else:
        compiled = compile_static(source_path)
    if PREPEND_STATIC_URL:
        compiled = static(compiled)
    return compiled
Beispiel #5
0
def test_compile_static(monkeypatch):

    compiler_stub = stub(compile=lambda x: "compiled",
                         compile_lazy=lambda x: "compiled lazy")

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_path",
                        lambda path: compiler_stub)

    assert compile_static("foo") == "compiled"
    assert compile_static_lazy("foo") == "compiled lazy"
def test_compile_static(monkeypatch):

    compiler_stub = stub(
        compile=lambda x: "compiled",
        compile_lazy=lambda x: "compiled lazy"
    )

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_path", lambda path: compiler_stub)

    assert compile_static("foo") == "compiled"
    assert compile_static_lazy("foo") == "compiled lazy"
Beispiel #7
0
def compile_tag(source_path, compiler=None):
    warnings.warn(
        "{% compile %} tag has been deprecated, use `compile` filter from `compile_static` template tag library "
        "instead.",
        DeprecationWarning,
    )
    if compiler:
        compiled = compiler.compile(source_path)
    else:
        compiled = utils.compile_static(source_path)
    if settings.PREPEND_STATIC_URL:
        compiled = django.templatetags.static.static(compiled)
    return compiled
def compile_tag(source_path, compiler=None):
    warnings.warn(
        "{% compile %} tag has been deprecated, use `compile` filter from `compile_static` template tag library "
        "instead.",
        DeprecationWarning,
    )
    if compiler:
        compiled = compiler.compile(source_path)
    else:
        compiled = utils.compile_static(source_path)
    if settings.PREPEND_STATIC_URL:
        compiled = django.templatetags.static.static(compiled)
    return compiled
Beispiel #9
0
    def test_compile_static(self):
        mocked_compiler = MagicMock()
        mocked_compiler.compile.return_value = "compiled"
        mocked_compiler.compile_lazy.return_value = "compiled"
        source_filename = "test.coffee"
        with patch("static_precompiler.utils.get_compiler_by_path"
                   ) as mocked_get_compiler_by_path:
            mocked_get_compiler_by_path.return_value = mocked_compiler
            self.assertEquals(compile_static(source_filename), "compiled")
            mocked_get_compiler_by_path.assert_called_once_with(
                source_filename)
            mocked_compiler.compile.assert_called_once_with(source_filename)

            mocked_get_compiler_by_path.reset_mock()
            self.assertEquals(compile_static_lazy(source_filename), "compiled")
            mocked_get_compiler_by_path.assert_called_once_with(
                source_filename)
            mocked_compiler.compile_lazy.assert_called_once_with(
                source_filename)
Beispiel #10
0
def compile_filter(source_path):
    compiled = utils.compile_static(source_path)
    if settings.PREPEND_STATIC_URL:
        compiled = django.templatetags.static.static(compiled)
    return compiled
def compile_filter(source_path):
    compiled = utils.compile_static(source_path)
    if settings.PREPEND_STATIC_URL:
        compiled = django.templatetags.static.static(compiled)
    return compiled