def process_resource_entry(self, target, ext, css_media, prefix, resource): """ Process the given (raw) resource. """ prefix, resource = super(ResourceManagerExtension, self).process_resource_entry( target, ext, css_media, prefix, resource) # if we are rendering css and the resource is a font, # then substitude it with its corresponding font css # file if ext == '.css' and prefix == 'font': font_declaration = FontCache.get_font_declaration(resource) if font_declaration is not None: resource = FontCache.get_font_css_url( font_declaration.font_name) prefix = 'screen' return prefix, resource
def handle(self, *args, **options): """ Run command. """ fontcache = FontCache() # clear first if we are refreshing the cache if options.get('refresh'): fontcache.clear(verbose=True) # update font cache fontcache.update(verbose=True)
def test_should_patrse_font_declaration(self): d = FontCache.get_font_declaration('Open Sans:300,300i') self.assertIsInstance(d, FontDeclaration) self.assertEqual('Open Sans', d.font_name) self.assertEqual(['300', '300i'], d.variants_display)
def setUp(self): self.fontcache = FontCache()
def test_should_return_media_url_path_to_font_declaration_css_file(self): self.assertEqual('/media/fonts/open-sans/open-sans.css', FontCache.get_font_css_url('Open Sans'))
def test_should_ignore_not_a_list(self): fontcache = FontCache() self.assertEqual([], fontcache.get_backends())
def test_should_return_list_of_installed_backends(self): fontcache = FontCache() self.assertIn( GoogleFontsBackend, [backend.__class__ for backend in fontcache.get_backends()])
def test_should_return_slugified_font_name(self): self.assertEqual('open-sans', FontCache.get_unique_font_name('Open Sans'))
def handle(self, *args, **options): """ Run command. """ fontcache = FontCache() fontcache.clear(verbose=True)