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 svgiconref(ref):
    """
    Renders markup for presenting an SVG icon with the given name referencing
    the SVG icon set from an external source.
    """
    if not ref:
        raise AttributeError(
            'Expected valid \'ref\' argument for template tag \'svgiconref\'.')

    # split reference into target and icon name
    try:
        target, name = ref.split('/', 2)
    except ValueError:
        raise AttributeError(
            'Expected valid \'ref\' argument for template tag \'svgiconref\' '
            + 'in the format \'<target>/<icon-name>\'.')

    # determine target icon set filename
    if settings.DEBUG:
        # in debug mode, we use the media api to refer to an individual
        # SVG file. We need to use the media api, since there
        # is some processing involved here in order to guarantee that the
        # SVG icon behaves in the same way as in production mode.
        url = '/%ssvgicons/%s/%s.svg' % (settings.MEDIA_API_URL, target, name)
    else:
        # the deployment process should have generated all required SVG icon
        # files, so we simply refer to it...
        identifier = load_resource_version_identifier()
        filename = get_svgicons_filename(target, identifier)
        url = '%s%s' % (settings.STATIC_URL, filename)

    return format_html(
        '<i class="svgicon svgicon-{}"><svg>' +
        '<use xlink:href="{}#svgicon-{}"/></svg>' + '</i>', name, url, name)
Beispiel #3
0
    def test_deploy_should_deploy_website(self):
        call_command('deploy')
        identifier = load_resource_version_identifier()

        # version identifier correct?
        self._assertStaticFile('revision', identifier)

        # deploy timestamp?
        self.assertEqual(datetime.now(), load_deploy_timestamp())

        # static (compiled) assets present
        for bucket in ['backend', 'backend-inline', 'frontend', 'inline']:
            self._assertStaticFile('cubane.%s.screen.%s.min.css' % (bucket, identifier))
            self._assertStaticFile('cubane.%s.%s.min.js' % (bucket, identifier))

        # static (compiled) css for testing bucket
        self._assertStaticFile('cubane.testing.screen.%s.min.css' % identifier)
        self._assertStaticFile('cubane.testing.print.%s.min.css' % identifier)

        # static (compiled) empty files for css and js
        self._assertStaticFile('cubane.empty.screen.%s.min.css' % identifier)
        self._assertStaticFile('cubane.empty.print.%s.min.css' % identifier)
        self._assertStaticFile('cubane.empty.%s.min.js' % identifier)

        # compiled svg icons?
        self._assertStaticFile('cubane.svgicons.frontend.%s.svg' % identifier)
        self._assertStaticFile('cubane.svgicons.testing.%s.svg' % identifier)

        # fonts
        self._assertStaticFile(
            'cubane.frontend.screen.%s.min.css' % identifier,
            contains_content='@font-face {\n    font-family: \'Open Sans\';'
        )
Beispiel #4
0
    def test_should_load_resource_version_from_file_if_exists(self):
        version = generate_resource_version_identifier()
        save_resource_version_identifier(version)

        filename = get_resource_version_filename()
        self.assertTrue(os.path.isfile(filename))

        loaded_version = load_resource_version_identifier()
        os.remove(filename)
        self.assertEqual(version, loaded_version)
Beispiel #5
0
def inline_svgicons(target):
    """
    Renders inline markup for defining an SVG icon sheet for all SVG icon
    assets defined for the given bucket name (target). SVG assets are using the
    standard resource system that is also used for CSS and Javascript assets in
    combination with resources and inline_resources template tags.
    """
    if target not in get_resource_target_definition():
        raise AttributeError(
            'Expected valid \'target\' argument for template ' +
            'tag \'inline_svgicons\'.')

    if settings.DEBUG:
        return mark_safe(
            get_combined_svg(get_resources(target, 'svg'),
                             get_resources(target, 'svg', 'with-style')))
    else:
        identifier = load_resource_version_identifier()
        filename = get_svgicons_filename(target, identifier)
        path = os.path.join(settings.STATIC_ROOT, filename)
        return mark_safe(file_get_contents(path))
Beispiel #6
0
 def test_should_return_none_if_file_does_not_exist(self):
     filename = get_resource_version_filename()
     self.assertFalse(os.path.isfile(filename))
     self.assertIsNone(load_resource_version_identifier())
Beispiel #7
0
 def _get_path(self):
     identifier = load_resource_version_identifier()
     filename = get_svgicons_filename('frontend', identifier)
     return os.path.join(settings.STATIC_ROOT, filename)
Beispiel #8
0
 def get_identifier(self):
     """
     Return the current resource identifier for the current version for
     all assets.
     """
     return load_resource_version_identifier()