Skip to content

Commit

Permalink
Add front-end-build paste command
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Feb 15, 2013
1 parent bb089f3 commit 63a4a50
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
56 changes: 54 additions & 2 deletions ckan/lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,6 @@ class MinifyCommand(CkanCommand):
exclude_dirs = ['vendor']

def command(self):
self.less()
self._load_config()
for base_path in self.args:
if os.path.isfile(base_path):
Expand Down Expand Up @@ -1806,6 +1805,25 @@ def minify_file(self, path):
f.close()
print "Minified file '{0}'".format(path)


class LessCommand(CkanCommand):
'''Create minified versions of the given Javascript and CSS files.
Usage:
paster minify [FILE|DIRECTORY] ...
for example:
paster less
'''
summary = __doc__.split('\n')[0]
usage = __doc__
min_args = 0

def command(self):
self.less()

custom_css = {
'fuchsia': '''
@layoutLinkColor: #b509b5;
Expand Down Expand Up @@ -1839,7 +1857,6 @@ def minify_file(self, path):
@btnPrimaryBackgroundHighlight: #f21010;
''',
}

def less(self):
''' Compile less files '''
import subprocess
Expand Down Expand Up @@ -1874,3 +1891,38 @@ def compile_less(self, root, less_bin, color):

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()
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63a4a50

Please sign in to comment.