-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathless2soy.py
executable file
·34 lines (30 loc) · 1.14 KB
/
less2soy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import sys
import subprocess
import os
prefix = ['{namespace less_css}\n', '/**\n','css file\n', '*/\n','{template .css_html}\n', '<style>\n{call .css_text}\n{/call}\n</style>' , '\n{/template}\n', '/**\n','css file\n', '*/\n','{template .css_text}\n']
suffix = ['{/template}']
def run(input_file,cp_dir):
css_file = input_file.replace( ".less", ".css")
soy_file = input_file.replace( ".less", ".css.soy")
if( css_file == input_file):
exit(1);
process = subprocess.Popen(["/usr/bin/env", "lessc","--no-color", input_file],stdout=subprocess.PIPE)
stdout = process.stdout
lines = []
for line in stdout:
lines.append( line.decode('utf-8'))
css = open( css_file, 'w')
css.writelines(lines)
css.close()
esc_lines = []
for line in lines:
l = line.replace('{','^lb^').replace('}','^rb^').replace('^lb^','{lb}').replace('^rb^','{rb}')
esc_lines.append(l)
out = open( soy_file ,'w')
out.writelines(prefix)
out.writelines(esc_lines)
out.writelines(suffix)
out.close();
if __name__ == '__main__':
run(sys.argv[1], os.path.dirname(sys.argv[0]))