def parse(self, target): from scss import parser includeValue = self.data[1] if isinstance(target, ParseNode) and not (isinstance( includeValue, QuotedStringValue)): name = str(includeValue) params = self.data[2:] mixin = self.root.cache['mix'].get(name) if mixin: mixin.include(target, params) else: warn("Required mixin not found: %s:%d." % (name, len(params))) elif isinstance(target, parser.Stylesheet) and isinstance( includeValue, QuotedStringValue): # @include "scss file to include" # Parse this file for more class names to emit in Dart class. options = target.currentOptions f = target.currentFile s = parser.Stylesheet(options=target.currentOptions) f = target.currentFile path = dirname(abspath(f.name)) includePath = normpath('{0}/{1}'.format(path, self.data[1].value)) f = open(includePath, 'r') nodes = s.loadReturnNodes(f) target.addInclude(includeValue.value, nodes)
def handle(self, *args, **options): # response = urllib2.urlopen(str('static/img/artworks-000261133514-g8rmw0-t500x500.jpg')) # soup = BeautifulSoup(response.read(), "lxml") # # for link in soup.find_all('script'): # script_info = link.string #Fix your shitty API soundcloud!! # soundcloud_avatar = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', # str(script_info.encode('utf-8')))[0].replace('large', 't500x500') file_path = 'DreamEasyApp/static/sass/_colors.scss' src = open( file_path ).read() # Create parser object p = parser.Stylesheet( options=dict( compress=True ) ) print p.loads( src ) color_thief = ColorThief('DreamEasyApp/static/img/dreameasy.jpg') # get the dominant color dominant_color = color_thief.get_color(quality=10) # build a color palette palette = color_thief.get_palette(color_count=6, quality=10) print dominant_color, palette
def main(argv=None): try: # Upgrade shell in interactive mode import atexit import readline history = os.path.join(os.environ['HOME'], ".scss-history") atexit.register(readline.write_history_file, history) readline.parse_and_bind("tab: complete") readline.set_completer(complete) readline.read_history_file(history) except (ImportError, IOError): pass # Create options p = optparse.OptionParser( usage="%prog [OPTION]... [INFILE] [OUTFILE]", version="%prog " + VERSION, epilog="SCSS compiler.", description= "Compile INFILE or standard input, to OUTFILE or standard output.") p.add_option('-c', '--cache', action='store_true', dest='cache', help="Create and use cache file. Only for files.") p.add_option('-i', '--interactive', action='store_true', dest='shell', help="Run in interactive shell mode.") p.add_option('-m', '--compress', action='store_true', dest='compress', help="Compress css output.") p.add_option('-w', '--watch', dest='watch', help="""Watch files or directories for changes. The location of the generated CSS can be set using a colon: scss -w input.scss:output.css """) p.add_option('-S', '--no-sorted', action='store_false', dest='sort', help="Do not sort declaration.") p.add_option('-C', '--no-comments', action='store_false', dest='comments', help="Clear css comments.") p.add_option('-W', '--no-warnings', action='store_false', dest='warn', help="Disable warnings.") opts, args = p.parse_args(argv or sys.argv[1:]) precache = opts.cache # Interactive mode if opts.shell: p = parser.Stylesheet() print 'SCSS v. %s interactive mode' % VERSION print '================================' print 'Ctrl+D or quit for exit' while True: try: s = raw_input('>>> ').strip() if s == 'quit': raise EOFError print p.loads(s) except (EOFError, KeyboardInterrupt): print '\nBye bye.' break sys.exit() # Watch mode elif opts.watch: self, sep, target = opts.watch.partition(':') files = [] if not os.path.exists(self): print >> sys.stderr, "Path don't exist: %s" % self sys.exit(1) if os.path.isdir(self): for f in os.listdir(self): path = os.path.join(self, f) if os.path.isfile(path) and f.endswith('.scss'): tpath = os.path.join(target or self, f[:-5] + '.css') files.append([path, tpath, 0]) else: files.append([self, target or self[:-5] + '.css', 0]) s = parser.Stylesheet(options=dict( comments=opts.comments, compress=opts.compress, warn=opts.warn, sort=opts.sort, cache=precache, )) def parse(f): infile, outfile, mtime = f ttime = os.path.getmtime(infile) if mtime < ttime: print " Parse '%s' to '%s' .. done" % (infile, outfile) out = s.load(open(infile, 'r')) open(outfile, 'w').write(out) f[2] = os.path.getmtime(outfile) print 'SCSS v. %s watch mode' % VERSION print '================================' print 'Ctrl+C for exit\n' while True: try: for f in files: parse(f) time.sleep(0.3) except OSError: pass except KeyboardInterrupt: print "\nSCSS stoped." break sys.exit() # Default compile files elif not args: infile = sys.stdin outfile = sys.stdout precache = False elif len(args) == 1: try: infile = open(args[0], 'r') outfile = sys.stdout except IOError, e: sys.stderr.write(str(e)) sys.exit()
sys.stderr.write(str(e)) sys.exit() elif len(args) == 2: try: infile = open(args[0], 'r') outfile = open(args[1], 'w') except IOError, e: sys.stderr.write(str(e)) sys.exit() else: p.print_help(sys.stdout) sys.exit() try: s = parser.Stylesheet(options=dict( comments=opts.comments, compress=opts.compress, warn=opts.warn, sort=opts.sort, cache=precache, )) outfile.write(s.load(infile)) except ValueError, e: raise SystemExit(e) if __name__ == '__main__': main()
def compileSCSS(filename): p = parser.Stylesheet(options=dict(compress=True, cache=True)) #return parser.load(filename) return p.load(filename)
palettes_css = [] palettes_markup = {} if markup.find(id="swatch-css"): style = markup.find(id="swatch-css") style.clear() else: style = markup.new_tag("style", id="swatch-css") for f in os.listdir(PALETTES_DIRECTORY): if f.endswith(".scss"): name = os.path.splitext(f)[0] palettes_markup[name] = [] palette = palettes_markup[name] f = open(os.path.join(PALETTES_DIRECTORY, f), "r") css = parser.Stylesheet(options={"compress": False}) css.loads(f.read()) colors = css.ctx f.close() for color in colors: palettes_css.append( ".swatch-%s-%s{background-color: %s}" % (name, camel_to_hyphen(color), colors.get(color))) palette.append({ "name": color, "hex": str(colors[color]), "rgb": get_rgb(str(colors[color])), "hsl": get_hsl(str(colors[color])), }) style.append(cssmin.cssmin("".join(palettes_css)))
from scss import parser # TODO: # pip install scss # https://pythonhosted.org/scss/ file_path = path_to_file src = open( file_path ).read() # from file print parser.load( 'file_path' ) # from string print parser.parse( 'src' ) # Create parser object p = parser.Stylesheet( options=dict( compress=True ) ) print p.loads( src ) p.load( file_path ) print p