예제 #1
0
    def test_should_not_raise_error_if_absolute_path(self):
        base_path = self.get_testapp_static_path()
        src_filename = os.path.join(base_path, 'css', 'test_simple.css')
        dst_filename = os.path.join(settings.STATIC_ROOT, 'cubane', 'testapp',
                                    'css', 'test_simple.css')
        dst_path = os.path.dirname(dst_filename)

        if not os.path.exists(dst_path):
            os.makedirs(dst_path)
        shutil.copyfile(src_filename, dst_filename)

        self.assertEqual('html{color:red;}',
                         get_resource('cubane/testapp/css/test_simple.css'))

        os.remove(dst_filename)
예제 #2
0
def get_combined_svg_for_resources(resources, with_style=False):
    """
    Combine the given list of resources.
    """
    markup = ''
    for filename in resources:
        try:
            file_content = get_resource(filename)
        except:
            raise ValueError('Unable to read svg icon file \'%s\'.' % filename)

        name = get_svg_name_from_file(filename)
        viewbox, svg_content = get_svg_content(name, file_content, with_style)
        markup += '<symbol id="svgicon-%(name)s" viewBox="%(viewbox)s">' % {
            'name': name,
            'viewbox': viewbox
        }
        markup += svg_content
        markup += '</symbol>'

    return markup
예제 #3
0
 def test_should_return_resources_for_debug_mode(self):
     self.assertEqual('html{color:red;}',
                      get_resource('cubane/testapp/css/test_simple.css'))
예제 #4
0
    def render(self, context):
        """
        Render resource tag.
        """
        target = value_or_literal(self.target, context)
        css_media = value_or_literal(self.css_media, context)

        # async
        if self.is_async is not None:
            is_async = value_or_literal(self.is_async, context)
        elif self.ext == 'js':
            is_async = True
        else:
            is_async = False

        # additonal_data
        if self.additional_data is not None:
            additional_data = value_or_literal(self.additional_data, context)
        else:
            additional_data = None

        if css_media and css_media not in settings.CSS_MEDIA:
            raise template.TemplateSyntaxError(
                ("'resources' only accepts the following values for css_media argument: " +
                 "%s."
                ) % settings.CSS_MEDIA
            )

        # if target is not defined, just ignore it.
        if target not in get_resource_target_definition():
            return ''

        if self.inline:
            if not settings.MINIFY_RESOURCES:
                resources = get_resources(target, self.ext)
                content = '\n'.join([get_resource(url) for url in resources])
            else:
                content = get_resource(
                    get_minified_filename(
                        target,
                        self.ext,
                        'screen' if self.ext == 'css' else None,
                        self.get_identifier()
                    )
                )

            return self.inline_include(content, additional_data, css_media)
        else:
            if not settings.MINIFY_RESOURCES:
                resources = get_resources(target, self.ext, css_media)
                return ''.join([
                    self.include(url, css_media, is_async, additional_data) for url in resources
                ])
            else:
                return self.include(
                    get_minified_filename(
                        target,
                        self.ext,
                        css_media,
                        self.get_identifier()
                    ), css_media, is_async, additional_data
                )