diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py index 264b4a28a28..f9e34d91d17 100644 --- a/ckan/lib/cli.py +++ b/ckan/lib/cli.py @@ -1804,3 +1804,122 @@ def minify_file(self, path): f.write(rjsmin.jsmin(source)) f.close() print "Minified file '{0}'".format(path) + + +class LessCommand(CkanCommand): + '''Compile all root less documents into their CSS counterparts + + Usage: + + paster less + + ''' + summary = __doc__.split('\n')[0] + usage = __doc__ + min_args = 0 + + def command(self): + self.less() + + custom_css = { + 'fuchsia': ''' + @layoutLinkColor: #b509b5; + @mastheadBackgroundColorStart: #dc0bdc; + @mastheadBackgroundColorEnd: #f31df3; + @btnPrimaryBackground: #f544f5; + @btnPrimaryBackgroundHighlight: #f76bf7; + ''', + + 'green': ''' + @layoutLinkColor: #045b04; + @mastheadBackgroundColorStart: #068106; + @mastheadBackgroundColorEnd: #08a808; + @btnPrimaryBackground: #0acf0a; + @btnPrimaryBackgroundHighlight: #10f210 + ''', + + 'red': ''' + @layoutLinkColor: #b50909; + @mastheadBackgroundColorStart: #dc0b0b; + @mastheadBackgroundColorEnd: #f31d1d; + @btnPrimaryBackground: #f54444; + @btnPrimaryBackgroundHighlight: #f76b6b; + ''', + + 'maroon': ''' + @layoutLinkColor: #5b0404; + @mastheadBackgroundColorStart: #810606; + @mastheadBackgroundColorEnd: #a80808; + @btnPrimaryBackground: #cf0a0a; + @btnPrimaryBackgroundHighlight: #f21010; + ''', + } + def less(self): + ''' Compile less files ''' + import subprocess + command = 'npm bin' + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + output = process.communicate() + directory = output[0].strip() + less_bin = os.path.join(directory, 'lessc') + + root = os.path.join(os.path.dirname(__file__), '..', 'public', 'base') + root = os.path.abspath(root) + custom_less = os.path.join(root, 'less', 'custom.less') + for color in self.custom_css: + f = open(custom_less, 'w') + f.write(self.custom_css[color]) + f.close() + self.compile_less(root, less_bin, color) + f = open(custom_less, 'w') + f.write('// This file is needed in order for ./bin/less to compile in less 1.3.1+\n') + f.close() + self.compile_less(root, less_bin, 'main') + + + + def compile_less(self, root, less_bin, color): + print 'compile %s.css' % color + import subprocess + main_less = os.path.join(root, 'less', 'main.less') + main_css = os.path.join(root, 'css', '%s.css' % color) + + command = '%s %s %s' % (less_bin, main_less, main_css) + + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + output = process.communicate() + + + +class FrontEndBuildCommand(CkanCommand): + ''' Creates and minifies css and JavaScript files + + Usage: + + paster front-end-build + ''' + + summary = __doc__.split('\n')[0] + usage = __doc__ + min_args = 0 + + def command(self): + self._load_config() + + # Less css + cmd = LessCommand('less') + cmd.command() + + # js translation strings + cmd = TranslationsCommand('trans') + cmd.options = self.options + cmd.args = ('js',) + cmd.command() + + # minification + cmd = MinifyCommand('minify') + cmd.options = self.options + root = os.path.join(os.path.dirname(__file__), '..', 'public', 'base') + root = os.path.abspath(root) + cmd.args = (root,) + cmd.command() diff --git a/setup.py b/setup.py index 97f1e1bc2ec..0a7b3818510 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,10 @@ check-po-files = ckan.i18n.check_po_files:CheckPoFiles trans = ckan.lib.cli:TranslationsCommand minify = ckan.lib.cli:MinifyCommand + less = ckan.lib.cli:LessCommand datastore = ckanext.datastore.commands:SetupDatastoreCommand + front-end-build = ckan.lib.cli:FrontEndBuildCommand + [console_scripts] ckan-admin = bin.ckan_admin:Command