def test_compile_file(self):
        compiler = CoffeeScript()

        self.assertEqual(
            self.clean_javascript(
                compiler.compile_file("scripts/test.coffee")),
            """(function() {\n  console.log("Hello, World!");\n}).call(this);"""
        )
Example #2
0
def test_compile_source():
    compiler = CoffeeScript()

    assert (clean_javascript(
        compiler.compile_source('console.log "Hello, World!"')
    ) == """(function() {\n  console.log("Hello, World!");\n}).call(this);""")

    with pytest.raises(StaticCompilationError):
        compiler.compile_source('console.log "Hello, World!')

    # Test non-ascii
    assert (clean_javascript(
        compiler.compile_source('console.log "Привет, Мир!"')
    ) == """(function() {\n  console.log("Привет, Мир!");\n}).call(this);""")
    def test_compile_source(self):
        compiler = CoffeeScript()

        self.assertEqual(
            self.clean_javascript(
                compiler.compile_source('console.log "Hello, World!"')),
            """(function() {\n  console.log("Hello, World!");\n}).call(this);"""
        )

        self.assertRaises(
            StaticCompilationError,
            lambda: compiler.compile_source('console.log "Hello, World!'))

        # Test non-ascii
        self.assertEqual(
            self.clean_javascript(
                compiler.compile_source('console.log "Привет, Мир!"')),
            """(function() {\n  console.log("Привет, Мир!");\n}).call(this);"""
        )
Example #4
0
from django.template.base import Library
from static_precompiler.compilers.coffeescript import CoffeeScript
from static_precompiler.templatetags.base import BaseInlineNode

register = Library()
compiler = CoffeeScript()


class InlineCoffeescriptNode(BaseInlineNode):

    compiler = compiler


#noinspection PyUnusedLocal
@register.tag(name="inlinecoffeescript")
def do_inlinecoffeescript(parser, token):
    nodelist = parser.parse(("endinlinecoffeescript", ))
    parser.delete_first_token()
    return InlineCoffeescriptNode(nodelist)


@register.simple_tag
def coffeescript(path):
    return compiler.compile(path)
Example #5
0
def test_compile_file():
    compiler = CoffeeScript()

    assert (clean_javascript(
        compiler.compile_file("scripts/test.coffee")
    ) == """(function() {\n  console.log("Hello, World!");\n}).call(this);""")
Example #6
0
 def test_get_output_filename(self):
     compiler = CoffeeScript()
     self.assertEqual(compiler.get_output_filename("dummy.coffee"),
                      "dummy.js")
     self.assertEqual(compiler.get_output_filename("dummy.coffee.coffee"),
                      "dummy.coffee.js")
Example #7
0
 def test_is_supported(self):
     compiler = CoffeeScript()
     self.assertEqual(compiler.is_supported("dummy"), False)
     self.assertEqual(compiler.is_supported("dummy.coffee"), True)