-
Notifications
You must be signed in to change notification settings - Fork 2k
/
less.py
95 lines (82 loc) · 3.08 KB
/
less.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# encoding: utf-8
import click
import subprocess
import os
from ckan.common import config
from ckan.cli import error_shout
_custom_css = {
u'fuchsia': u'''
@layoutLinkColor: #E73892;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',
u'green': u'''
@layoutLinkColor: #2F9B45;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',
u'red': u'''
@layoutLinkColor: #C14531;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',
u'maroon': u'''
@layoutLinkColor: #810606;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',
}
@click.command(
name=u'less',
short_help=u'Compile all root less documents into their CSS counterparts')
def less():
command = (u'npm', u'bin')
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
output = process.communicate()
directory = output[0].strip()
if not directory:
error_shout(u'Command "{}" returned nothing. Check that npm is '
u'installed.'.format(u' '.join(command)))
less_bin = os.path.join(directory, u'lessc')
public = config.get(u'ckan.base_public_folder')
root = os.path.join(os.path.dirname(__file__), u'..', public, u'base')
root = os.path.abspath(root)
custom_less = os.path.join(root, u'less', u'custom.less')
for color in _custom_css:
f = open(custom_less, u'w')
f.write(_custom_css[color])
f.close()
_compile_less(root, less_bin, color)
f = open(custom_less, u'w')
f.write(u'// This file is needed in order for ./bin/less to '
u'compile in less 1.3.1+\n')
f.close()
_compile_less(root, less_bin, u'main')
def _compile_less(root, less_bin, color):
click.echo(u'compile {}.css'.format(color))
main_less = os.path.join(root, u'less', u'main.less')
main_css = os.path.join(root, u'css', u'{}.css'.format(color))
command = (less_bin, main_less, main_css)
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
output = process.communicate()
click.echo(output)