Beispiel #1
0
    def handle(self, *args, **options):
        """
        Run command.
        """
        self.verbose('Processing svgicons...Please Wait...')

        identifier = options.get('identifier')
        if not identifier:
            identifier = load_resource_version_identifier()

        for target in get_resource_targets():
            # build filename
            filename = get_svgicons_filename(target, identifier)

            # build icon sheet
            resources = get_resources(target, 'svg')
            resources_with_style = get_resources(target, 'svg', 'with-style')
            if len(resources) > 0 or len(resources_with_style) > 0:
                self.verbose('> %s' % filename)

                svg = get_combined_svg(resources, resources_with_style)

                # folder exists?
                if not os.path.isdir(settings.STATIC_ROOT):
                    os.makedirs(settings.STATIC_ROOT)

                # write file
                path = os.path.join(settings.STATIC_ROOT, filename)
                with codecs.open(path, 'w', encoding='utf-8') as f:
                    f.write(svg)

        self.verbose('Complete.')
Beispiel #2
0
    def get_used_font_declarations(self):
        """
        Return a unique list of font declarations that are currently used by the
        system and need to be cached.
        """
        font_declarations = {}
        targets = get_resource_targets()
        for target in targets:
            font_resources = get_resources(
                target,
                css_media='font',
                data_only=True
            )

            for font_resource in font_resources:
                font_declaration = FontCache.get_font_declaration(font_resource)
                font_name = font_declaration.font_name
                if font_name in font_declarations:
                    # font already listed. Join varients
                    font_declarations[font_name].join_with(font_declaration)
                else:
                    # new font
                    font_declarations[font_name] = font_declaration

        return sorted(
            font_declarations.values(),
            key=lambda decl: decl.font_name
        )
Beispiel #3
0
 def test_get_resource_targets_should_return_list_in_alphabetical_order(
         self):
     resources = get_resource_targets()
     alphabetical_ordered_resources = sorted(list(resources))
     for a, b in zip(resources, alphabetical_ordered_resources):
         self.assertEqual(a, b)
Beispiel #4
0
 def test_get_resource_targets_should_return_list_with_correct_amount_of_resources(
         self):
     targets = get_resource_targets()
     for target in self.EXPECTED_TARGETS:
         self.assertIn(target, targets)
Beispiel #5
0
 def test_get_resource_targets_should_return_list(self):
     self.assertIsInstance(get_resource_targets(), list)