示例#1
0
    def importScss(self, scope, token, fileName, options):
        myStyleSheet = token
        while not myStyleSheet.isStyleSheet():
            myStyleSheet = myStyleSheet.parent

        css = None
        extension = ".scss" if len(fileName) < 5 or fileName[-5] != ".scss" else ""
        paths = copy.copy(self.paths)
        paths.append(myStyleSheet.path)
        importPath = ""
        for prefix in paths:
            path = prefix + "/" + fileName + extension
            (dir, file) = os.path.split(path)
            hiddenPath = dir + "/_" + file

            if os.path.exists(hiddenPath):
                options.importCss = False
                importPath = hiddenPath
                break
            if os.path.exists(path):
                importPath = path
                break

        if not importPath:
            raise SCSSRunTimeError("Could not find import \"%s\" in search path: %s" % (fileName, paths))

        if importPath in self.imports:
            (importScope, styleSheet) = self.imports[importPath]
            if importScope:
                if styleSheet:
                    self.importStyleSheet(token, styleSheet)
                self.importScope(scope, importScope)
            else:
                pass # recursive inclusion
        else:
            self.imports[importPath] = (None, None)

            with codecs.open(importPath, "r") as f:
                css = f.read()

            parser = cssparser.CSSParser()
            styleSheet = parser.parse(css, options)
            (directory, fileName) = os.path.split(path)
            styleSheet.setPath(directory)

            compiler = scsscompiler.SCSSCompiler()
            compiler.setGlobalScope(scope)
            compiler.compile(styleSheet, options)

            if options.importCss:
                self.importStyleSheet(token, styleSheet)
                self.imports[importPath] = (scope, styleSheet)
            else:
                self.imports[importPath] = (scope, None)
示例#2
0
    def evaluate(self, callerScope, arguments=None):
        try:
            scope = self.scope.clone()
            if arguments != None:
                self.mapArguments(arguments, callerScope, scope)

            body = self.body.clone()
            import scsscompiler
            compiler = scsscompiler.SCSSCompiler()
            compiler.setGlobalScope(scope)
            compiler.compile(body)
            return body.children[1:-1]
        except Exception, exception:
            raise SCSSRunTimeError(
                str(exception) + "\n  In call to mixin " + self.name)
示例#3
0
    def start(self, options=cssparser.CSSOptions()):
        compiler = scsscompiler.SCSSCompiler()
        scope = compiler.getGlobalScope()
        while True:
            statement = raw_input(">> ")
            if statement == "\\q" or statement == "exit()":
                print "Bye."
                return

            try:
                expression = scssexpression.SCSSExpression.fromString(
                    statement, options)
                expression.evaluate(scope)
                for token in expression.tokens:
                    print token.toString(options)
            except Exception, exception:
                print exception
示例#4
0
    optionParser = optparse.OptionParser(usage = usage)
    optionParser.add_option("", "--color", action = "store_true",
                      help = "Colorize the output")
    optionParser.add_option("-i", "--interactive", action = "store_true",
                      help = "Run an interactive SassScript shell.")
    optionParser.add_option("-I", "--load-path",
                      help = "Add a sass import path.")
    optionParser.add_option("", "--minimize", action = "store_true",
                      help = "Minimize the output (--style compact in sass).")
    (o, args) = optionParser.parse_args()

    options = cssparser.CSSOptions(stripWhiteSpace = o.minimize, stripComments = o.minimize,
                                   minimizeValues = o.minimize, stripExtraSemicolons = o.minimize,
                                   colorize = o.color, compileScss = True)

    if o.load_path:
        import scssimporter
        scssimporter.Importer.addPath(load_path)

    if o.interactive:
        console = scssconsole.SCSSConsole()
        console.start(options)
    else:
        parser = cssparser.CSSParser()
        token = parser.parse(sys.stdin.read(), options)
    
        compiler = scsscompiler.SCSSCompiler()
        compiler.compile(token, options)
    
        print token.toString(options)