How to use cssutils - 10 common examples

To help you get started, we’ve selected a few cssutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nueverest / blowdrycss / blowdrycss / unit_tests / test_BreakpointParser.py View on Github external
def test_set_limit_key(self):
        valid_css_classes = ['inline-small-up', 'inline-giant-down-i', 'green-xxsmall-only', 'padding-10-large-up', ]
        names = ['display', 'display', 'color', 'padding', ]
        values = ['inline', 'inline', 'green', '10', ]
        priorities = ['', 'important', '', '', ]
        expected = ['-up', '-down', '-only', '-up', ]

        for i, css_class in enumerate(valid_css_classes):
            css_property = Property(name=names[i], value=values[i], priority=priorities[i])
            breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
            breakpoint_parser.set_limit_key()
            self.assertEqual(breakpoint_parser.limit_key, expected[i])
github nueverest / blowdrycss / blowdrycss / unit_tests / test_BreakpointParser.py View on Github external
def test_css_for_down_general_usage(self):
        css_class = 'padding-100-medium-down'
        name = 'padding'
        value = px_to_em('100')
        expected = (
            '@media only screen and (max-width: 45.0em) {\n' +
            '\t.padding-100-medium-down {\n' +
            '\t\tpadding: 6.25em;\n' +
            '\t}\n' +
            '}\n\n'
        )
        css_property = Property(name=name, value=value, priority='')
        breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
        css = breakpoint_parser.css_for_down()
        self.assertEqual(css, expected)
github nueverest / blowdrycss / blowdrycss / unit_tests / test_ScalingParser.py View on Github external
def test_is_scaling_True(self):
        valid_css_classes = ['font-size-24-s', 'font-size-24-s-i', 'padding-10-s', 'margin-30-s-i', ]
        names = ['font-size', 'font-size', 'padding', 'margin', ]
        values = ['24px', '24px', '10px', '30px']
        priorities = ['', 'important', '', 'important', ]

        for i, css_class in enumerate(valid_css_classes):
            css_property = Property(name=names[i], value=values[i], priority=priorities[i])
            scaling_parser = ScalingParser(css_class=css_class, css_property=css_property)
            self.assertTrue(scaling_parser.is_scaling)
github nueverest / blowdrycss / blowdrycss / unit_tests / test_BreakpointParser.py View on Github external
def test_build_media_query_up_general_usage(self):
        css_class = 'padding-100-small-up'
        name = 'padding'
        value = px_to_em('100')
        expected = (
            '@media only screen and (min-width: 15.0625em) {\n' +
            '\t.padding-100-small-up {\n' +
            '\t\tpadding: 6.25em;\n' +
            '\t}\n' +
            '}\n\n'
        )
        css_property = Property(name=name, value=value, priority='')
        breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
        css = breakpoint_parser.build_media_query()
        self.assertEqual(css, expected)
github nueverest / blowdrycss / blowdrycss / unit_tests / test_ScalingParser.py View on Github external
def test_strip_scaling_flag(self):
        valid_css_classes = [
            'font-size-34-s', 'font-size-24-s-i', 'padding-12-s', 'margin-31-s-i',
            'font-size-10', 'font-size-13-i',
        ]
        names = ['font-size', 'font-size', 'padding', 'margin', 'font-size', 'font-size', ]
        values = ['34px', '24px', '12px', '31px', '15px', '52px', '10px', '13px', ]
        priorities = ['', 'important', '', 'important', '', '', '', '', ]
        expected = [
            'font-size-34', 'font-size-24-i', 'padding-12', 'margin-31-i',
            'font-size-10', 'font-size-13-i',
        ]

        for i, css_class in enumerate(valid_css_classes):
            css_property = Property(name=names[i], value=values[i], priority=priorities[i])
            scaling_parser = ScalingParser(css_class=css_class, css_property=css_property)
            clean_css_class = scaling_parser.strip_scaling_flag()
            self.assertEqual(clean_css_class, expected[i])
github jorgebastida / glue / tests.py View on Github external
def setUp(self):
        cssutils.log.setLevel(logging.ERROR)
        self.base_path = os.path.dirname(os.path.abspath(__file__))
        self.output_path = os.path.join(self.base_path, self.TEST_PATH)
        shutil.rmtree(self.output_path, True)
        os.makedirs(self.output_path)
        self.pwd = os.getcwd()
        os.chdir(self.output_path)
        sys.stdout = StringIO()
        sys.stderr = StringIO()
github lavr / python-emails / emails / testsuite / loader / test_helpers.py View on Github external
# encoding: utf-8
from __future__ import unicode_literals, print_function

import logging; import  cssutils; cssutils.log.setLevel(logging.FATAL)

from emails.loader.helpers import (guess_charset, guess_text_charset, decode_text, guess_html_charset, RULES_U)


def test_re_rules():
    assert RULES_U.re_is_http_equiv.findall('http-equiv="Content-Type" content="text/html; charset=UTF-8"')


def test_guess_charset():
    assert guess_charset(headers={'content-type': 'text/html; charset=utf-8'}, html='') == 'utf-8'

    assert guess_charset(headers=None, html='') == 'xxx-N'

    html = """"""
    assert guess_charset(headers=None, html=html) == 'UTF-8'
    assert guess_text_charset(html, is_html=True) == 'UTF-8'
github myfreeweb / cssprefixer / cssprefixer / rules.py View on Github external
def __get_prefixed_prop(self, prefix=None):
        name = self.prop.name
        if prefix:
            name = '-%s-%s' % (prefix, self.prop.name)
        newValues = []
        for value in self.prop.value.split(','):
            parts = value.strip().split(' ')
            parts[0] = prefixRegex.sub('', parts[0])
            if parts[0] in rules and prefix and rules[parts[0]].should_prefix():
                parts[0] = '-%s-%s' % (prefix, parts[0])
            newValues.append(' '.join(parts))
        return cssutils.css.Property(
                name=name,
                value=', '.join(newValues),
                priority=self.prop.priority
                )
github jorgebastida / cssbuster / cssbuster.py View on Github external
"the css and the images."))

    css_path = os.path.basename(args[0])
    img_rel_path = args[1]

    # Configure the logger
    log = logging.getLogger('csscache')
    handler = logging.StreamHandler(sys.stderr)
    handler.setLevel(logging.ERROR)
    log.addHandler(handler)

    if options.minified:
        cssutils.ser.prefs.useMinified()

    # Create the parser
    parser = cssutils.CSSParser(log=log,
                                raiseExceptions=True,
                                parseComments=not options.minified,
                                validate=False)
    try:
        # Parse the original file
        sheet = parser.parseFile(args[0])
    except Exception, e:
        sys.stderr.write('Error: %s %s\n' % (css_path, e.args[0]))
        sys.exit(1)

    # Replace all the urls
    replacer = partial(cache_bust_replacer, options, css_path, img_rel_path)
    cssutils.replaceUrls(sheet, replacer, ignoreImportRules=True)

    # print the new css
    sys.stdout.write(sheet.cssText)
github norbusan / calibre-debian / src / calibre / ebooks / oeb / normalize_css.py View on Github external
def test_border_condensation(self):
            vals = 'red solid 5px'
            css = '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in EDGES for p, v in zip(BORDER_PROPS, vals.split()))
            style = parseStyle(css)
            condense_rule(style)
            for e, p in product(EDGES, BORDER_PROPS):
                self.assertFalse(style.getProperty('border-%s-%s' % (e, p)))
                self.assertFalse(style.getProperty('border-%s' % e))
                self.assertFalse(style.getProperty('border-%s' % p))
            self.assertEqual(style.getProperty('border').value, vals)
            css = '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in ('top',) for p, v in zip(BORDER_PROPS, vals.split()))
            style = parseStyle(css)
            condense_rule(style)
            self.assertEqual(style.cssText, 'border-top: %s' % vals)
            css += ';' + '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in ('right', 'left', 'bottom') for p, v in
                             zip(BORDER_PROPS, vals.replace('red', 'green').split()))
            style = parseStyle(css)
            condense_rule(style)
            self.assertEqual(len(style.getProperties()), 4)
            self.assertEqual(style.getProperty('border-top').value, vals)