Example #1
0
 def load_template(self, template_name, template_dirs=None):
     if not template_name.endswith('.hisp'):
         raise TemplateDoesNotExist(template_name)
     source, display_name = self.load_template_source(template_name, template_dirs)
     source = hisper().convert(source)
     origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
     try:
         template = get_template_from_string(source, origin, template_name)
         return template, None
     except TemplateDoesNotExist:
         # If compiling the template we found raises TemplateDoesNotExist, back off to
         # returning the source and display name for the template we were asked to load.
         # This allows for correct identification (later) of the actual template that does
         # not exist.
         return source, display_name
Example #2
0
    def handle(self, *args, **kwargs):
        loader = Loader(filter(bool, (
            kwargs['fs'] and 'django.template.loaders.app_directories.Loader',
            kwargs['apps'] and 'django.template.loaders.filesystem.Loader')))
        directories = chain(*filter(bool, (
            kwargs['fs'] and settings.TEMPLATE_DIRS,
            kwargs['apps'] and app_template_dirs)))
        hisp = hisper(kwargs['compress'])

        for dir in set(directories):
            for (root, _, files) in os.walk(dir):
                for filename in files:
                    try:
                        source, name = loader.load_template_source(filename, [root])
                    except TemplateDoesNotExist:
                        continue
                    print 'Converting %s....' % name
                    output = hisp.convert(source)
                    dest = os.path.join(root, filename + '.html')
                    with open(dest, 'w') as outfile:
                        outfile.write(output)
Example #3
0
 def load_template(self, template_name, template_dirs=None):
     if not template_name.endswith('.hisp'):
         raise TemplateDoesNotExist(template_name)
     source, display_name = self.load_template_source(template_name, template_dirs)
     origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
     return hisper().convert(source), origin