Ejemplo n.º 1
0
def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and 'percents'.startswith(unit):
        unit = '%'

    if isinstance(value, float):
        full_unit = options.get('CSS_default_unit_decimal', 'em')
    else:
        full_unit = options.get('CSS_default_unit', 'px')

    if value == 0:
        return '0'
    if value == '':
        return ''

    if unit:
        units = (val[1:] for key, val in FLAT_CSS
                 if key == name and val.startswith('.'))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax"
                    "vm", "ch", "rem", "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return

    return '{0}{1}'.format(value, full_unit)
Ejemplo n.º 2
0
def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and "percents".startswith(unit):
        unit = "%"

    if isinstance(value, float):
        full_unit = options.get("CSS_default_unit_decimal", "em")
    else:
        full_unit = options.get("CSS_default_unit", "px")

    if "<number>" in [val for prop, val in get_flat_css() if prop == name] and not options.get(
        "CSS_units_for_unitless_numbers"
    ):
        full_unit = ""

    if value == 0:
        return "0"
    if value == "":
        return ""

    if unit:
        units = (val[1:] for key, val in get_flat_css() if key == name and val.startswith("."))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax" "vm", "ch", "rem", "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return

    return "{0}{1}".format(value, full_unit)
Ejemplo n.º 3
0
def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and 'percents'.startswith(unit):
        unit = '%'

    if isinstance(value, float):
        full_unit = options.get('CSS_default_unit_decimal', 'em')
    else:
        full_unit = options.get('CSS_default_unit', 'px')

    if value == 0:
        return '0'
    if value == '':
        return ''

    if unit:
        units = (val[1:] for key, val in FLAT_CSS if key == name and val.startswith('.'))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax" "vm", "ch", "rem",
            "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return

    return '{0}{1}'.format(value, full_unit)
Ejemplo n.º 4
0
 def test_4(self):
     self.assertEqual(hayaku_extract('w1px'), 'width: 1px')
Ejemplo n.º 5
0
 def test_28(self):
     self.assertEqual(hayaku_extract('b2'), 'bottom: 2px')
Ejemplo n.º 6
0
 def test_21(self):
     self.assertEqual(hayaku_extract('p3x'), 'padding: 3ex')
Ejemplo n.º 7
0
 def test_25(self):
     self.assertEqual(hayaku_extract('p3r'), 'padding: 3rem')
Ejemplo n.º 8
0
 def test_14(self):
     self.assertEqual(hayaku_extract('m-0.0'), 'margin: 0')
Ejemplo n.º 9
0
 def test_0(self):
     self.assertEqual(hayaku_extract('fs'), 'font-size')
Ejemplo n.º 10
0
 def test_9(self):
     self.assertEqual(hayaku_extract('w1e'), 'width: 1em')
Ejemplo n.º 11
0
 def test_10(self):
     self.assertEqual(hayaku_extract('m-1'), 'margin: -1px')
Ejemplo n.º 12
0
 def test_5(self):
     self.assertEqual(hayaku_extract('w1.1'), 'width: 1.1em')
Ejemplo n.º 13
0
 def test_6(self):
     self.assertEqual(hayaku_extract('w.1'), 'width: .1em')
Ejemplo n.º 14
0
 def test_4(self):
     self.assertEqual(hayaku_extract('w1px'), 'width: 1px')
Ejemplo n.º 15
0
 def test_issue_76_2(self):
     self.assertEqual(hayaku_extract('border'), 'border')
Ejemplo n.º 16
0
 def test_issue_76_1(self):
     self.assertEqual(hayaku_extract('text-decoration'), 'text-decoration')
Ejemplo n.º 17
0
 def test_6(self):
     self.assertEqual(hayaku_extract('w.1'), 'width: .1em')
Ejemplo n.º 18
0
 def test_11(self):
     self.assertEqual(hayaku_extract('m-.1'), 'margin: -.1em')
Ejemplo n.º 19
0
 def test_10(self):
     self.assertEqual(hayaku_extract('m-1'), 'margin: -1px')
Ejemplo n.º 20
0
 def test_14(self):
     self.assertEqual(hayaku_extract('m-0.0'), 'margin: 0')
Ejemplo n.º 21
0
 def test_16(self):
     self.assertEqual(hayaku_extract('p1m'), 'padding: 1mm')
Ejemplo n.º 22
0
 def test_15(self):
     self.assertEqual(hayaku_extract('h1.100'), 'height: 1.1em')
Ejemplo n.º 23
0
 def test_19(self):
     self.assertEqual(hayaku_extract('p2.p'), 'padding: 2px')
Ejemplo n.º 24
0
 def test_16(self):
     self.assertEqual(hayaku_extract('p1m'), 'padding: 1mm')
Ejemplo n.º 25
0
 def test_23(self):
     self.assertEqual(hayaku_extract('p3h'), 'padding: 3vh')
Ejemplo n.º 26
0
 def test_17(self):
     self.assertEqual(hayaku_extract('p1%'), 'padding: 1%')
Ejemplo n.º 27
0
 def test_27(self):
     self.assertEqual(hayaku_extract('p3t'), 'padding: 3pt')
Ejemplo n.º 28
0
 def test_18(self):
     self.assertEqual(hayaku_extract('p.23pe'), 'padding: .23%')
Ejemplo n.º 29
0
 def test_30(self):
     self.assertEqual(hayaku_extract('bw'), 'border-width: 2px')
Ejemplo n.º 30
0
 def test_19(self):
     self.assertEqual(hayaku_extract('p2.p'), 'padding: 2px')
Ejemplo n.º 31
0
 def test_issue_83_3(self):
     self.assertEqual(hayaku_extract('conn'), 'content: normal;')
Ejemplo n.º 32
0
 def test_20(self):
     self.assertEqual(hayaku_extract('p2.3p'), 'padding: 2.3px')
Ejemplo n.º 33
0
 def test_5(self):
     self.assertEqual(hayaku_extract('w1.1'), 'width: 1.1em')
Ejemplo n.º 34
0
 def test_0(self):
     self.assertEqual(hayaku_extract('fs'), 'font-size')
Ejemplo n.º 35
0
 def test_9(self):
     self.assertEqual(hayaku_extract('w1e'), 'width: 1em')
Ejemplo n.º 36
0
 def test_21(self):
     self.assertEqual(hayaku_extract('p3x'), 'padding: 3ex')
Ejemplo n.º 37
0
 def test_11(self):
     self.assertEqual(hayaku_extract('m-.1'), 'margin: -.1em')
Ejemplo n.º 38
0
 def test_22(self):
     self.assertEqual(hayaku_extract('p3w'), 'padding: 3vw')
Ejemplo n.º 39
0
 def test_15(self):
     self.assertEqual(hayaku_extract('h1.100'), 'height: 1.1em')
Ejemplo n.º 40
0
 def test_23(self):
     self.assertEqual(hayaku_extract('p3h'), 'padding: 3vh')
Ejemplo n.º 41
0
 def test_17(self):
     self.assertEqual(hayaku_extract('p1%'), 'padding: 1%')
Ejemplo n.º 42
0
 def test_24(self):
     self.assertEqual(hayaku_extract('p3c'), 'padding: 3ch')
Ejemplo n.º 43
0
 def test_18(self):
     self.assertEqual(hayaku_extract('p.23pe'), 'padding: .23%')
Ejemplo n.º 44
0
 def test_25(self):
     self.assertEqual(hayaku_extract('p3r'), 'padding: 3rem')
Ejemplo n.º 45
0
 def test_20(self):
     self.assertEqual(hayaku_extract('p2.3p'), 'padding: 2.3px')
Ejemplo n.º 46
0
 def test_26(self):
     self.assertEqual(hayaku_extract('p3i'), 'padding: 3in')
Ejemplo n.º 47
0
 def test_22(self):
     self.assertEqual(hayaku_extract('p3w'), 'padding: 3vw')
Ejemplo n.º 48
0
 def test_27(self):
     self.assertEqual(hayaku_extract('p3t'), 'padding: 3pt')
Ejemplo n.º 49
0
 def test_24(self):
     self.assertEqual(hayaku_extract('p3c'), 'padding: 3ch')
Ejemplo n.º 50
0
 def test_28(self):
     self.assertEqual(hayaku_extract('b2'), 'bottom: 2px')
Ejemplo n.º 51
0
 def test_26(self):
     self.assertEqual(hayaku_extract('p3i'), 'padding: 3in')
Ejemplo n.º 52
0
 def test_29(self):
     self.assertEqual(hayaku_extract('bd2'), 'border: 2px')
Ejemplo n.º 53
0
 def test_1(self):
     self.assertEqual(hayaku_extract('fst'), 'font-style')
Ejemplo n.º 54
0
 def test_30(self):
     self.assertEqual(hayaku_extract('bw'), 'border-width: 2px')
Ejemplo n.º 55
0
 def test_29(self):
     self.assertEqual(hayaku_extract('bd2'), 'border: 2px')
Ejemplo n.º 56
0
 def test_issue_83_1(self):
     self.assertEqual(hayaku_extract('co'), 'color')
Ejemplo n.º 57
0
 def test_31(self):
     self.assertEqual(hayaku_extract('blw'), 'border-left-width: 2px')
Ejemplo n.º 58
0
 def test_issue_76_2(self):
     self.assertEqual(hayaku_extract('border'), 'border')
Ejemplo n.º 59
0
 def test_issue_76_1(self):
     self.assertEqual(hayaku_extract('text-decoration'), 'text-decoration')
Ejemplo n.º 60
0
 def test_issue_83_2(self):
     self.assertEqual(hayaku_extract('con'), 'content')