Ejemplo n.º 1
0
    def render(self, context):
        if IN_TESTING:
            return ''

        pipeline_name = template.Variable(self.pipeline_name).resolve(context)

        if settings.ASSET_DEV_MODE:
            active = settings.ASSET_PIPELINE_ACTIVE
            try:
                pipeline = settings.ASSET_PIPELINES[active][pipeline_name]
            except:
                raise template.TemplateSyntaxError(
                    "Pipeline with name %s not defined in settings.ASSET_PIPELINES." % pipeline_name
                )
            outputs = pipeline.output_urls()
        else:
            #On live, we used the generated media file
            if self._generated_cache is None:
                self._generated_cache = read_generated_media_file()

            outputs = self._generated_cache[pipeline_name]

        if len(outputs) > 1:
            raise ValueError("Tried to access URL of a pipeline with multiple outputs")

        if outputs:
            return outputs[0]
        return ""
Ejemplo n.º 2
0
    def render(self, context):
        if IN_TESTING:
            return ''

        pipeline_name = template.Variable(self.pipeline_name).resolve(context)
        tags = []

        if settings.ASSET_DEV_MODE:
            active = settings.ASSET_PIPELINE_ACTIVE
            try:
                pipeline = settings.ASSET_PIPELINES[active][pipeline_name]
            except:
                raise template.TemplateSyntaxError(
                    "Pipeline with name %s not defined in settings.ASSET_PIPELINES." % pipeline_name
                )
            outputs = pipeline.output_urls()
        else:
            #On live, we used the generated media file
            if self._generated_cache is None:
                self._generated_cache = read_generated_media_file()

            outputs = self._generated_cache[pipeline_name]

        for output in outputs:
            if output.endswith(".css"):
                tag = u'<link rel="stylesheet" type="text/css" href="%s" />' % os.path.join(settings.STATIC_URL, output)
            elif output.endswith(".js"):
                tag = u'<script src="%s"></script>' % os.path.join(settings.STATIC_URL, output)
            else:
                raise ValueError("Invalid output found")
            tags.append(tag)
        return '\n'.join(tags)