예제 #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
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)
예제 #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_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)
예제 #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_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)
예제 #7
0
 def test_triple_depth_spaced(self):
     self.assertEqual(' { { a } } ', parse_nested(' { { a } } } '))
예제 #8
0
 def test_single_depth_spaced(self):
     self.assertEqual(' a ', parse_nested(' a } '))
예제 #9
0
 def test_bundle(self):
     self.assertEqual(".b { :h { } } .t { ... } .c { ... } ",
                      parse_nested(".b { :h { } } .t { ... } .c { ... } }"))
예제 #10
0
 def test_double_depth_spaced(self):
     self.assertEqual(' { a } ', parse_nested(' { a } } '))
예제 #11
0
 def test_bundle(self):
     self.assertEqual(".b { :h { } } .t { ... } .c { ... } ",
                      parse_nested(".b { :h { } } .t { ... } .c { ... } }"))
예제 #12
0
 def test_braces_in_quotes(self):
     self.assertEqual('quotes: "{" "}"', parse_nested('quotes: "{" "}"}'))
예제 #13
0
 def test_triple_depth_spaced(self):
     self.assertEqual(' { { a } } ', parse_nested(' { { a } } } '))
예제 #14
0
 def test_single_depth_spaced(self):
     self.assertEqual(' a ', parse_nested(' a } '))
예제 #15
0
 def test_open_brace_in_quotes(self):
     self.assertEqual('quotes: "{"', parse_nested('quotes: "{"}'))
예제 #16
0
 def test_double_depth_spaced(self):
     self.assertEqual(' { a } ', parse_nested(' { a } } '))
예제 #17
0
 def test_open_brace_in_quotes(self):
     self.assertEqual('quotes: "{"', parse_nested('quotes: "{"}'))
예제 #18
0
 def test_braces_in_quotes(self):
     self.assertEqual('quotes: "{" "}"', parse_nested('quotes: "{" "}"}'))