当前位置: 首页>>代码示例>>Python>>正文


Python Scss.parse_children方法代码示例

本文整理汇总了Python中scss.Scss.parse_children方法的典型用法代码示例。如果您正苦于以下问题:Python Scss.parse_children方法的具体用法?Python Scss.parse_children怎么用?Python Scss.parse_children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scss.Scss的用法示例。


在下文中一共展示了Scss.parse_children方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import parse_children [as 别名]

#.........这里部分代码省略.........
            try:
                s = raw_input('>>> ').strip()
            except EOFError:
                print
                break
            except KeyboardInterrupt:
                print
                break
            if s in ('exit', 'quit'):
                break
            for s in s.split(';'):
                s = source_file.prepare_source(s.strip(), line_numbers=False)
                if not s:
                    continue
                elif s.startswith('@'):
                    properties = []
                    children = deque()
                    SassRule(source_file, context=context, options=options, properties=properties)
                    code, name = (s.split(None, 1) + [''])[:2]
                    if code == '@option':
                        css._settle_options(rule, [''], set(), children, None, None, s, None, code, name)
                        continue
                    elif code == '@import':
                        css._do_import(rule, [''], set(), children, None, None, s, None, code, name)
                        continue
                    elif code == '@include':
                        final_cont = ''
                        css._do_include(rule, [''], set(), children, None, None, s, None, code, name)
                        code = css._print_properties(properties).rstrip('\n')
                        if code:
                            final_cont += code
                        if children:
                            css.children.extendleft(children)
                            css.parse_children()
                            code = css._create_css(css.rules).rstrip('\n')
                            if code:
                                final_cont += code
                        final_cont = css.post_process(final_cont)
                        print final_cont
                        continue
                elif s == 'ls' or s.startswith('show(') or s.startswith('show ') or s.startswith('ls(') or s.startswith('ls '):
                    m = re.match(r'(?:show|ls)(\()?\s*([^,/\\) ]*)(?:[,/\\ ]([^,/\\ )]+))*(?(1)\))', s, re.IGNORECASE)
                    if m:
                        name = m.group(2)
                        code = m.group(3)
                        name = name and name.strip().rstrip('s')  # remove last 's' as in functions
                        code = code and code.strip()
                        if not name:
                            pprint(sorted(['vars', 'options', 'mixins', 'functions']))
                        elif name in ('v', 'var', 'variable'):
                            if code == '*':
                                d = dict((k, v) for k, v in context.items())
                                pprint(d)
                            elif code:
                                d = dict((k, v) for k, v in context.items() if code in k)
                                pprint(d)
                            else:
                                d = dict((k, v) for k, v in context.items() if k.startswith('$') and not k.startswith('$__'))
                                pprint(d)
                        elif name in ('o', 'opt', 'option'):
                            if code == '*':
                                d = dict((k, v) for k, v in options.items())
                                pprint(d)
                            elif code:
                                d = dict((k, v) for k, v in options.items() if code in k)
                                pprint(d)
开发者ID:eevee,项目名称:pyScss,代码行数:70,代码来源:tool.py

示例2: SassRepl

# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import parse_children [as 别名]
class SassRepl(object):
    def __init__(self, is_sass=False):
        self.css = Scss()
        self.namespace = self.css.root_namespace
        self.options = self.css.scss_opts
        self.source_file = SourceFile.from_string('', '<shell>', line_numbers=False, is_sass=is_sass)
        self.calculator = Calculator(self.namespace)

    def __call__(self, s):
        from pprint import pformat

        if s in ('exit', 'quit'):
            raise KeyboardInterrupt

        for s in s.split(';'):
            s = self.source_file.prepare_source(s.strip())
            if not s:
                continue
            elif s.startswith('@'):
                scope = None
                properties = []
                children = deque()
                rule = SassRule(self.source_file, namespace=self.namespace, options=self.options, properties=properties)
                block = UnparsedBlock(rule, 1, s, None)
                code, name = (s.split(None, 1) + [''])[:2]
                if code == '@option':
                    self.css._settle_options(rule, children, scope, block)
                    continue
                elif code == '@import':
                    self.css._do_import(rule, children, scope, block)
                    continue
                elif code == '@include':
                    final_cont = ''
                    self.css._do_include(rule, children, scope, block)
                    code = self.css._print_properties(properties).rstrip('\n')
                    if code:
                        final_cont += code
                    if children:
                        self.css.children.extendleft(children)
                        self.css.parse_children()
                        code = self.css._create_css(self.css.rules).rstrip('\n')
                        if code:
                            final_cont += code
                    yield final_cont
                    continue
            elif s == 'ls' or s.startswith('show(') or s.startswith('show ') or s.startswith('ls(') or s.startswith('ls '):
                m = re.match(r'(?:show|ls)(\()?\s*([^,/\\) ]*)(?:[,/\\ ]([^,/\\ )]+))*(?(1)\))', s, re.IGNORECASE)
                if m:
                    name = m.group(2)
                    code = m.group(3)
                    name = name and name.strip().rstrip('s')  # remove last 's' as in functions
                    code = code and code.strip()
                    ns = self.namespace
                    if not name:
                        yield pformat(sorted(['vars', 'options', 'mixins', 'functions']))
                    elif name in ('v', 'var', 'variable'):
                        variables = dict(ns._variables)
                        if code == '*':
                            pass
                        elif code:
                            variables = dict((k, v) for k, v in variables.items() if code in k)
                        else:
                            variables = dict((k, v) for k, v in variables.items() if not k.startswith('$--'))
                        yield pformat(variables)

                    elif name in ('o', 'opt', 'option'):
                        opts = self.options
                        if code == '*':
                            pass
                        elif code:
                            opts = dict((k, v) for k, v in opts.items() if code in k)
                        else:
                            opts = dict((k, v) for k, v in opts.items() if not k.startswith('@'))
                        yield pformat(opts)

                    elif name in ('m', 'mix', 'mixin', 'f', 'func', 'funct', 'function'):
                        if name.startswith('m'):
                            funcs = dict(ns._mixins)
                        elif name.startswith('f'):
                            funcs = dict(ns._functions)
                        if code == '*':
                            pass
                        elif code:
                            funcs = dict((k, v) for k, v in funcs.items() if code in k[0])
                        else:
                            pass
                        # TODO print source when possible
                        yield pformat(funcs)
                    continue
            elif s.startswith('$') and (':' in s or '=' in s):
                prop, value = [a.strip() for a in _prop_split_re.split(s, 1)]
                prop = self.calculator.do_glob_math(prop)
                value = self.calculator.calculate(value)
                self.namespace.set_variable(prop, value)
                continue

            # TODO respect compress?
            try:
                yield(self.calculator.calculate(s).render())
            except (SyntaxError, SassEvaluationError) as e:
#.........这里部分代码省略.........
开发者ID:coinpayee,项目名称:pyScss,代码行数:103,代码来源:tool.py

示例3: SassRepl

# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import parse_children [as 别名]
class SassRepl(object):
    def __init__(self, is_sass=False):
        self.css = Scss()
        self.namespace = self.css.root_namespace
        self.options = self.css.scss_opts
        self.source_file = SourceFile.from_string("", "<shell>", line_numbers=False, is_sass=is_sass)
        self.calculator = Calculator(self.namespace)

    def __call__(self, s):
        from pprint import pformat

        if s in ("exit", "quit"):
            raise KeyboardInterrupt

        for s in s.split(";"):
            s = self.source_file.prepare_source(s.strip())
            if not s:
                continue
            elif s.startswith("@"):
                scope = None
                properties = []
                children = deque()
                rule = SassRule(self.source_file, namespace=self.namespace, options=self.options, properties=properties)
                block = UnparsedBlock(rule, 1, s, None)
                code, name = (s.split(None, 1) + [""])[:2]
                if code == "@option":
                    self.css._settle_options(rule, children, scope, block)
                    continue
                elif code == "@import":
                    self.css._do_import(rule, children, scope, block)
                    continue
                elif code == "@include":
                    final_cont = ""
                    self.css._do_include(rule, children, scope, block)
                    code = self.css._print_properties(properties).rstrip("\n")
                    if code:
                        final_cont += code
                    if children:
                        self.css.children.extendleft(children)
                        self.css.parse_children()
                        code = self.css._create_css(self.css.rules).rstrip("\n")
                        if code:
                            final_cont += code
                    yield final_cont
                    continue
            elif (
                s == "ls"
                or s.startswith("show(")
                or s.startswith("show ")
                or s.startswith("ls(")
                or s.startswith("ls ")
            ):
                m = re.match(r"(?:show|ls)(\()?\s*([^,/\\) ]*)(?:[,/\\ ]([^,/\\ )]+))*(?(1)\))", s, re.IGNORECASE)
                if m:
                    name = m.group(2)
                    code = m.group(3)
                    name = name and name.strip().rstrip("s")  # remove last 's' as in functions
                    code = code and code.strip()
                    ns = self.namespace
                    if not name:
                        yield pformat(sorted(["vars", "options", "mixins", "functions"]))
                    elif name in ("v", "var", "variable"):
                        variables = dict(ns._variables)
                        if code == "*":
                            pass
                        elif code:
                            variables = dict((k, v) for k, v in variables.items() if code in k)
                        else:
                            variables = dict((k, v) for k, v in variables.items() if not k.startswith("$--"))
                        yield pformat(variables)

                    elif name in ("o", "opt", "option"):
                        opts = self.options
                        if code == "*":
                            pass
                        elif code:
                            opts = dict((k, v) for k, v in opts.items() if code in k)
                        else:
                            opts = dict((k, v) for k, v in opts.items() if not k.startswith("@"))
                        yield pformat(opts)

                    elif name in ("m", "mix", "mixin", "f", "func", "funct", "function"):
                        if name.startswith("m"):
                            funcs = dict(ns._mixins)
                        elif name.startswith("f"):
                            funcs = dict(ns._functions)
                        if code == "*":
                            pass
                        elif code:
                            funcs = dict((k, v) for k, v in funcs.items() if code in k[0])
                        else:
                            pass
                        # TODO print source when possible
                        yield pformat(funcs)
                    continue
            elif s.startswith("$") and (":" in s or "=" in s):
                prop, value = [a.strip() for a in _prop_split_re.split(s, 1)]
                prop = self.calculator.do_glob_math(prop)
                value = self.calculator.calculate(value)
                self.namespace.set_variable(prop, value)
#.........这里部分代码省略.........
开发者ID:hblanks,项目名称:pyScss,代码行数:103,代码来源:tool.py


注:本文中的scss.Scss.parse_children方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。