Beispiel #1
0
def generate_result_object(hayaku):
    # Trying to substitute abbreviation with aliased one,
    # should be placed somewhere else
    if isinstance(hayaku, dict):
        hayaku['abbr'] = hayaku['options'].get('aliases').get(
            hayaku.get('abbr'), hayaku.get('abbr')).replace(': ', ':')

    args = extract(hayaku)

    # Not that proper check for only-property with fallback,
    # should be inside `extract`, couldn't do it properly.
    if not args and ':' in hayaku.get('abbr', ''):
        abbr = hayaku.get('abbr')
        colon_index = abbr.index(':') + 1
        hayaku['abbr'] = abbr[:colon_index]
        args = extract(hayaku)
        args['keyword-value'] = abbr[colon_index:]

    if not args:
        return None

    options = {}
    if isinstance(hayaku, dict):
        options = hayaku.get('options')

    value = expand_value(args, options.get('dict'), options)
    if value is None:
        return

    if value.startswith('[') and value.endswith(']'):
        value = False

    result = {
        'abbr':
        args.get('abbr'),
        'type':
        options.get('dict', {}).get(args['property-name'],
                                    {}).get('type', 'property'),
        'property':
        args.get('property-name'),
        'value':
        value
    }
    if isinstance(hayaku, dict) and hayaku.get('clipboard'):
        result['clipboard'] = hayaku.get('clipboard')

    if args.get('no-unprefixed-property'):
        result['no-unprefixed-property'] = True

    if args.get('prefixes'):
        result['prefixes'] = args.get('prefixes', [])

    if args.get('important'):
        result['important'] = True

    if result.get('value') == '#' or not result.get('value'):
        result['value'] = {
            'default': args.get('default-value', ''),
            'symbols': []
        }
        possible_values = [
            val for prop, val in get_flat_css(options.get('dict'),
                                              include_commented=True)
            if prop == result.get('property')
        ]
        if possible_values:
            units = []
            keywords = []

            for p_value in (v for v in possible_values if len(v) > 1):
                if p_value.startswith('.'):
                    units.append(p_value[1:])
                else:
                    if p_value.startswith('<'):
                        result['value']['symbols'].append(p_value)
                    else:
                        keywords.append(p_value)
            if units:
                result['value']['units'] = units
            if keywords:
                result['value']['keywords'] = keywords

    return result
Beispiel #2
0
def generate_result_object(hayaku):
    # Trying to substitute abbreviation with aliased one,
    # should be placed somewhere else
    if isinstance(hayaku, dict):
        hayaku['abbr'] = hayaku['options'].get('aliases').get(hayaku.get('abbr'), hayaku.get('abbr')).replace(': ', ':')

    args = extract(hayaku)

    # Not that proper check for only-property with fallback,
    # should be inside `extract`, couldn't do it properly.
    if not args and ':' in hayaku.get('abbr', ''):
        abbr = hayaku.get('abbr')
        colon_index = abbr.index(':') + 1
        hayaku['abbr'] = abbr[:colon_index]
        args = extract(hayaku)
        args['keyword-value'] = abbr[colon_index:]

    if not args:
        return None

    options = {}
    if isinstance(hayaku, dict):
        options = hayaku.get('options')

    value = expand_value(args, options.get('dict'), options)
    if value is None:
        return

    if value.startswith('[') and value.endswith(']'):
        value = False

    result = {
        'abbr': args.get('abbr'),
        'type': options.get('dict', {}).get(args['property-name'], {}).get('type', 'property'),
        'property': args.get('property-name'),
        'value': value
    }
    if isinstance(hayaku, dict) and hayaku.get('clipboard'):
        result['clipboard'] = hayaku.get('clipboard')

    if args.get('no-unprefixed-property'):
        result['no-unprefixed-property'] = True

    if args.get('prefixes'):
        result['prefixes'] = args.get('prefixes', [])

    if args.get('important'):
        result['important'] = True

    if result.get('value') == '#' or not result.get('value'):
        result['value'] = {
            'default': args.get('default-value',''),
            'symbols': []
        }
        possible_values = [val for prop, val in get_flat_css(options.get('dict'), include_commented=True) if prop == result.get('property')]
        if possible_values:
            units = []
            keywords = []

            for p_value in (v for v in possible_values if len(v) > 1):
                if p_value.startswith('.'):
                    units.append(p_value[1:])
                else:
                    if p_value.startswith('<'):
                        result['value']['symbols'].append(p_value)
                    else:
                        keywords.append(p_value)
            if units:
                result['value']['units'] = units
            if keywords:
                result['value']['keywords'] = keywords

    return result
Beispiel #3
0
 def test_10(self):
     self.assertEqual(expand_value(extract("w"), {}), "[100%]")
Beispiel #4
0
 def test_11(self):
     self.assertEqual(expand_value(extract("c#")), "#")
Beispiel #5
0
 def test_7(self):
     self.assertEqual(expand_value(extract("w10perc"), self.opts), "10%")
Beispiel #6
0
 def test_8(self):
     self.assertEqual(expand_value(extract("vat")), "top")
Beispiel #7
0
 def test_6(self):
     self.assertEqual(expand_value(extract("w10%")), "10%")
Beispiel #8
0
 def test_5(self):
     self.assertEqual(expand_value(extract("w"), self.opts), "[100%]")
Beispiel #9
0
 def test_4(self):
     self.assertEqual(expand_value(extract("w0px"), self.opts), "0")
Beispiel #10
0
 def test_1(self):
     self.assertEqual(expand_value(extract("zi12"), self.opts), "12")
Beispiel #11
0
 def test_0(self):
     self.assertEqual(expand_value(extract("z8"), self.opts), "8")