mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	In this commit we modify our CSS parser not only to render the text from
a given CSS tokens produced but also enforce 4 space indentation on it.
Also we enforce some basic rules we would like our CSS to follow such as
* Always have "\n" in between the starting of body({) and body itself
  and ending of the body and the closing of body(}).
* Use 4 space indents while having but something within the block
  structure ( { .... } ).
* Have single space after ',' in between multiple selectors.
* Have only a single space in between selector and the starting of
  block structure ({ ... }) if block structure starts on same line as
  of selector.
  eg. body {
          body content here
      }
  Notice single space between 'body' and '{'.
Fixes: #1659.
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env python
 | 
						|
from __future__ import absolute_import
 | 
						|
from __future__ import print_function
 | 
						|
from lib.css_parser import parse, CssParserException
 | 
						|
from typing import Iterable, Text
 | 
						|
import os
 | 
						|
import sys
 | 
						|
import glob
 | 
						|
 | 
						|
# check for the venv
 | 
						|
from lib import sanity_check
 | 
						|
sanity_check.check_venv(__file__)
 | 
						|
 | 
						|
def validate(fn):
 | 
						|
    # type: (Text) -> None
 | 
						|
    text = open(fn).read()
 | 
						|
    section_list = parse(text)
 | 
						|
    if text != section_list.text():
 | 
						|
        print('%s seems to be broken:' % (fn,))
 | 
						|
        open('/var/tmp/pretty_css.txt', 'w').write(section_list.text())
 | 
						|
        os.system('diff %s /var/tmp/pretty_css.txt' % (fn,))
 | 
						|
        sys.exit(1)
 | 
						|
 | 
						|
def check_our_files(filenames):
 | 
						|
    # type: (Iterable[Text]) -> None
 | 
						|
    for filename in filenames:
 | 
						|
        try:
 | 
						|
            validate(filename)
 | 
						|
        except CssParserException as e:
 | 
						|
            msg = '''
 | 
						|
                ERROR! Some CSS seems to be misformatted.
 | 
						|
                {}
 | 
						|
                See line {} in file {}
 | 
						|
                '''.format(e.msg, e.token.line, filename)
 | 
						|
            print(msg)
 | 
						|
            sys.exit(1)
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    # If command arguments are provided, we only check those filenames.
 | 
						|
    # Otherwise, we check all possible filenames.
 | 
						|
    filenames = sys.argv[1:]
 | 
						|
    if not filenames:
 | 
						|
        filenames = glob.glob('static/styles/*.css')
 | 
						|
    check_our_files(filenames)
 |