def handle(self, *command_args, **command_options):
        if command_options["debug"]:
            logging.getLogger("django_handlebars").setLevel(logging.DEBUG)

        console = NullConsole() if command_options["quiet"] else Console()

        try:
            console.set_out(self.stdout)
            console.set_err(self.stderr)
            console.raw = command_options["raw"]

            blockers = cant_compile()
            if blockers:
                console.err(
                    self.warn_unavail(
                        "<color:red>You can not compile handlebars templates:<color:reset>",
                        blockers))
                return

            from django_handlebars.management.compiler import Compiler
            compiler = Compiler(console=console)

            if command_options["clean"]:
                compiler.cleanup()

            if command_options["watch"]:
                blockers = cant_observe()
                if blockers:
                    console.err(
                        self.warn_unavail(
                            "<color:red>You can not watch file changes:<color:reset>",
                            blockers))
                    return

                from django_handlebars.management.observer import Observer

                compiler.add_path(appsettings.TPL_DIR)
                observer = Observer(appsettings.TPL_DIR, compiler)

                def close(signum, stack):
                    console.out("\nShutting down observer...")
                    observer.stop()

                signal.signal(signal.SIGINT, close)
                observer.start()
                signal.pause()

            else:
                compiler.add_path(appsettings.TPL_DIR)
                compiler.terminate()

        except ReadableError as err:
            console.err("<color:red>Ooops!<color:reset> %s" % err.message)
            return
    def handle(self, *command_args, **command_options):
        if command_options["debug"]:
            logging.getLogger("django_handlebars").setLevel(logging.DEBUG)

        console = NullConsole() if command_options["quiet"] else Console()

        try:
            console.set_out(self.stdout)
            console.set_err(self.stderr)
            console.raw = command_options["raw"]

            blockers = cant_compile()
            if blockers:
                console.err(
                    self.warn_unavail("<color:red>You can not compile handlebars templates:<color:reset>", blockers)
                )
                return

            from django_handlebars.management.compiler import Compiler

            compiler = Compiler(console=console)

            if command_options["clean"]:
                compiler.cleanup()

            if command_options["watch"]:
                blockers = cant_observe()
                if blockers:
                    console.err(self.warn_unavail("<color:red>You can not watch file changes:<color:reset>", blockers))
                    return

                from django_handlebars.management.observer import Observer

                compiler.add_path(appsettings.TPL_DIR)
                observer = Observer(appsettings.TPL_DIR, compiler)

                def close(signum, stack):
                    console.out("\nShutting down observer...")
                    observer.stop()

                signal.signal(signal.SIGINT, close)
                observer.start()
                signal.pause()

            else:
                compiler.add_path(appsettings.TPL_DIR)
                compiler.terminate()

        except ReadableError as err:
            console.err("<color:red>Ooops!<color:reset> %s" % err.message)
            return
import os
import time
import tempfile
import shutil

from imp import reload
from django.template import Template, Context
from unittest import skipIf
from django.test import TestCase
from django.test.utils import override_settings as _override_settings

import appsettings
from django_handlebars.utils import ReadableError, cant_compile, cant_observe


CANT_COMPILE = "; ".join(cant_compile())
CANT_OBSERVE = "; ".join(cant_observe())



class override_settings(_override_settings):
    def enable(self):
        super(override_settings, self).enable()
        reload(appsettings)

    def disable(self):
        super(override_settings, self).disable()
        reload(appsettings)


Example #4
0
import os
import re
from django.conf import settings
from django_handlebars.utils import cant_compile

root = os.path.dirname(__file__)
path = lambda p: os.path.join(root, p[:-1] if p.endswith("/") else p)

__all__ = ("NUM_THREADS", "COMPILED",
    "TPL_DIR", "TPL_CMPDIR", "TPL_MASK", "TPL_URL", 
    "SCRIPT_PATH", "SCRIPT_EXTRAS", "SCRIPT_TPL",)

# Tells whether compiled or or raw templates should be used in browser
# By default it assumes True if required packages installed
COMPILED = len(cant_compile()) == 0

# How many threads to spawn in Compiler 
NUM_THREADS = 4

# Raw templates file name mask. This is used in compilehandlebars --watch
# to handle filesystem events involving tergeting files only
TPL_MASK = "\w+.html$"

# Raw templates directory
TPL_DIR = path("static/js/templates-src")

# Compiled templates directory
TPL_CMPDIR = path("static/js/templates")

# Raw templates URL. Templates are loaded as regular static files,
Example #5
0
import os
import time
import tempfile
import shutil
import urllib2

from django.template import Template, Context
from unittest import skipIf
from django.test import TestCase
from django.test.utils import override_settings as _override_settings

import appsettings
from django_handlebars.utils import ReadableError, cant_compile, cant_observe

CANT_COMPILE = "; ".join(cant_compile())
CANT_OBSERVE = "; ".join(cant_observe())


class override_settings(_override_settings):
    def enable(self):
        super(override_settings, self).enable()
        reload(appsettings)

    def disable(self):
        super(override_settings, self).disable()
        reload(appsettings)


class TagsTest(TestCase):

    src_dir = tempfile.mkdtemp(prefix="tags-test-sources-")
import os
import re
from django.conf import settings
from django_handlebars.utils import cant_compile

root = os.path.dirname(__file__)
path = lambda p: os.path.join(root, p[:-1] if p.endswith("/") else p)

__all__ = ("NUM_THREADS", "COMPILED",
    "TPL_DIR", "TPL_CMPDIR", "TPL_MASK", "TPL_URL", "TPL_JSWRAPPER",
    "SCRIPT_PATH", "SCRIPT_EXTRAS", "SCRIPT_TPL",)

# Tells whether compiled or raw templates should be used in browser
# By default it assumes True if required packages installed
COMPILED = len(cant_compile()) == 0

# How many threads to spawn in Compiler 
NUM_THREADS = 4

# Raw templates file name mask. This is used in compilehandlebars --watch
# to handle filesystem events involving tergeting files only
TPL_MASK = "\w+.html$"

# Raw templates directory
TPL_DIR = path("static/js/templates-src")

# Compiled templates directory
TPL_CMPDIR = path("static/js/templates")

# Raw templates URL. Templates are loaded as regular static files,