示例#1
0
def parse_mixin(less, parent=None, **kwargs):
    match = MIXIN.match(less)

    if not match:
        raise ValueError()

    code = match.group()

    contents = None

    if match.group('nested'):
        matched_length = len(match.group())

        remaining_less = less[matched_length:]

        contents = parse_nested(remaining_less)

        code += contents + '}'

    params = parse_params(match.group('params'))

    if contents:
        for param in params:
            if param['value'] and not param['name']:
                param['name'] = param['value']
                param['value'] = None

    name = match.group('name')

    if match.group('nested') and not match.group('param_detect'):
        raise ValueError()

    return Mixin(parent=parent, code=code, name=name, params=params,
                 contents=contents)
示例#2
0
文件: mixin.py 项目: WolfForMoon/TASK
def parse_mixin(less, parent=None, **kwargs):
    match = MIXIN.match(less)

    if not match:
        raise ValueError()

    code = match.group()

    contents = None

    if match.group("nested"):
        matched_length = len(match.group())

        remaining_less = less[matched_length:]

        contents = parse_nested(remaining_less)

        code += contents + "}"

    params = parse_params(match.group("params"))

    if contents:
        for param in params:
            if param["value"] and not param["name"]:
                param["name"] = param["value"]
                param["value"] = None

    name = match.group("name")

    if match.group("nested") and not match.group("param_detect"):
        raise ValueError()

    return Mixin(parent=parent, code=code, name=name, params=params, contents=contents)
示例#3
0
def parse_media(less, parent=None, **kwargs):
    match = MEDIA.match(less)

    if not match:
        raise ValueError()

    media = [media.strip() for media in match.group('media').split(',')]

    matched_length = len(match.group())

    remaining_less = less[matched_length:]

    contents = parse_nested(remaining_less)

    code = match.group() + contents + '}'

    return Media(code=code, media=media, contents=contents, parent=parent)
示例#4
0
def parse_media(less, parent=None, **kwargs):
    match = MEDIA.match(less)

    if not match:
        raise ValueError()

    media = [media.strip() for media in match.group('media').split(',')]

    matched_length = len(match.group())

    remaining_less = less[matched_length:]

    contents = parse_nested(remaining_less)

    code = match.group() + contents + '}'

    return Media(code=code, media=media, contents=contents, parent=parent)
示例#5
0
def parse_selector(less, parent=None, **kwargs):
    match = SELECTOR.match(less)

    if not match:
        raise ValueError()
        
    names = match.group('names')
    
    if names.startswith('@media'):
        raise ValueError

    names = [name.strip() for name in names.split(',')]

    matched_length = len(match.group())

    remaining_less = less[matched_length:]

    contents = parse_nested(remaining_less)

    code = match.group() + contents + '}'

    return Selector(code=code, names=names, contents=contents, parent=parent)
示例#6
0
def parse_selector(less, parent=None, **kwargs):
    match = SELECTOR.match(less)

    if not match:
        raise ValueError()

    names = match.group('names')

    if names.startswith('@media'):
        raise ValueError

    names = [name.strip() for name in names.split(',')]

    matched_length = len(match.group())

    remaining_less = less[matched_length:]

    contents = parse_nested(remaining_less)

    code = match.group() + contents + '}'

    return Selector(code=code, names=names, contents=contents, parent=parent)
示例#7
0
def parse_mixin(less, parent=None, **kwargs):
    match = MIXIN.match(less)

    if not match:
        raise ValueError()

    code = match.group()

    contents = None

    if match.group('nested'):
        matched_length = len(match.group())

        remaining_less = less[matched_length:]

        contents = parse_nested(remaining_less)

        code += contents + '}'

    params = parse_params(match.group('params'))

    if contents:
        for param in params:
            if param['value'] and not param['name']:
                param['name'] = param['value']
                param['value'] = None

    name = match.group('name')

    if match.group('nested') and not match.group('param_detect'):
        raise ValueError()

    return Mixin(parent=parent,
                 code=code,
                 name=name,
                 params=params,
                 contents=contents)
示例#8
0
 def test_bundle(self):
     self.assertEqual(".b { :h { } } .t { ... } .c { ... } ",
                      parse_nested(".b { :h { } } .t { ... } .c { ... } }"))
示例#9
0
 def test_braces_in_quotes(self):
     self.assertEqual('quotes: "{" "}"', parse_nested('quotes: "{" "}"}'))
示例#10
0
 def test_triple_depth_spaced(self):
     self.assertEqual(' { { a } } ', parse_nested(' { { a } } } '))
示例#11
0
 def test_single_depth_spaced(self):
     self.assertEqual(' a ', parse_nested(' a } '))
示例#12
0
 def test_open_brace_in_quotes(self):
     self.assertEqual('quotes: "{"', parse_nested('quotes: "{"}'))
示例#13
0
 def test_single_depth_spaced(self):
     self.assertEqual(' a ', parse_nested(' a } '))
示例#14
0
 def test_braces_in_quotes(self):
     self.assertEqual('quotes: "{" "}"', parse_nested('quotes: "{" "}"}'))
示例#15
0
 def test_double_depth_spaced(self):
     self.assertEqual(' { a } ', parse_nested(' { a } } '))
示例#16
0
 def test_open_brace_in_quotes(self):
     self.assertEqual('quotes: "{"', parse_nested('quotes: "{"}'))
示例#17
0
 def test_bundle(self):
     self.assertEqual(".b { :h { } } .t { ... } .c { ... } ",
                      parse_nested(".b { :h { } } .t { ... } .c { ... } }"))
示例#18
0
 def test_triple_depth_spaced(self):
     self.assertEqual(' { { a } } ', parse_nested(' { { a } } } '))
示例#19
0
 def test_double_depth_spaced(self):
     self.assertEqual(' { a } ', parse_nested(' { a } } '))