def render(self, context):
        """Main entry point, renders the node."""
        group = self.group_var.resolve(context)
        config = self.media_settings.get(group, None)
        response = ''
        if config is not None:
            render_context = config.get('extra_context', {})
            condition = render_context.get('condition', None)
            template_suffix = self.media_type
            if condition:
                # If a condition is set, then the ie-specific template is
                # required.
                template_suffix += '_ie'
            template_name = 'media_compressor/compressed_%s.html' % \
                (template_suffix,)

            source_filenames = config['source_filenames']
            expanded_source_filenames = \
                expand_source_filenames(source_filenames)
            if len(expanded_source_filenames) > 0:
                if not settings.COMPRESS_DEBUG:
                    if settings.COMPRESS:
                        output_filename = config['output_filename_minified']
                    else:
                        output_filename = config['output_filename']
                    compress_media(output_filename, expanded_source_filenames,
                        settings.COMPRESS)
                    response += render_compressed(output_filename, template_name,
                        render_context)
                else:
                    for source_filename in expanded_source_filenames:
                        response += render_compressed(source_filename,
                            template_name, render_context)
        return response
Beispiel #2
0
def build_compressed_media(media_name, media_options):
    """Run over all the compressed media in settings.py and
    trigger the manual build process for it."""
    print 'Building compressed %s media:' % (media_name, )
    for group_name, group_options in media_options.items():
        print '  %s:' % (group_name, )
        output_filename = group_options['output_filename']
        source_filenames = group_options['source_filenames']
        source_filenames = expand_source_filenames(source_filenames)
        output_path, changed = compress_media(output_filename,
                                              source_filenames, False)
        print '    Plain:'
        print '      changed: %s' % (changed, )
        print '      path: %s' % (output_path, )
        output_filename = group_options['output_filename_minified']
        output_path, changed = compress_media(output_filename,
                                              source_filenames, True)
        print '    Minified:'
        print '      changed: %s' % (changed, )
        print '      path: %s' % (output_path, )
def build_compressed_media(media_name, media_options):
    """Run over all the compressed media in settings.py and
    trigger the manual build process for it."""
    print 'Building compressed %s media:' % (media_name,)
    for group_name, group_options in media_options.items():
        print '  %s:' % (group_name,)
        output_filename = group_options['output_filename']
        source_filenames = group_options['source_filenames']
        source_filenames = expand_source_filenames(source_filenames)
        output_path, changed = compress_media(output_filename,
            source_filenames, False)
        print '    Plain:'
        print '      changed: %s' % (changed,)
        print '      path: %s' % (output_path,)
        output_filename = group_options['output_filename_minified']
        output_path, changed = compress_media(output_filename,
            source_filenames, True)
        print '    Minified:'
        print '      changed: %s' % (changed,)
        print '      path: %s' % (output_path,)
    def render(self, context):
        """Main entry point, renders the node."""
        group = self.group_var.resolve(context)
        config = self.media_settings.get(group, None)
        response = ''
        if config is not None:
            render_context = config.get('extra_context', {})
            condition = render_context.get('condition', None)
            template_suffix = self.media_type
            if condition:
                # If a condition is set, then the ie-specific template is
                # required.
                template_suffix += '_ie'
            template_name = 'media_compressor/compressed_%s.html' % \
                (template_suffix,)

            source_filenames = config['source_filenames']
            expanded_source_filenames = \
                expand_source_filenames(source_filenames)
            if len(expanded_source_filenames) > 0:
                if not settings.COMPRESS_DEBUG:
                    if settings.COMPRESS:
                        output_filename = config['output_filename_minified']
                    else:
                        output_filename = config['output_filename']
                    compress_media(output_filename, expanded_source_filenames,
                                   settings.COMPRESS)
                    response += render_compressed(output_filename,
                                                  template_name,
                                                  render_context)
                else:
                    for source_filename in expanded_source_filenames:
                        response += render_compressed(source_filename,
                                                      template_name,
                                                      render_context)
        return response