Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add --compile options to use uglifier/yui-compressor to compile JS/CSS

  • Loading branch information...
commit d944cc9b48979bf12163520fb28e3b4059d6e3c0 1 parent 9450bb8
Alex Sexton authored August 18, 2012
2  Gemfile
... ...
@@ -1,4 +1,4 @@
1 1
 source 'https://rubygems.org'
2 2
 
3 3
 # Specify your gem's dependencies in catapult.gemspec
4  
-gemspec
  4
+gemspec
6  example/assets/javascripts/app.js
... ...
@@ -1 +1,5 @@
1  
-//= require_tree .
  1
+//= require_tree .
  2
+
  3
+var init = function(){
  4
+  alert('init 2!');
  5
+};
7  example/assets/stylesheets/app.css
... ...
@@ -1 +1,6 @@
1  
-/*= require_tree .*/
  1
+/*= require_tree .*/
  2
+
  3
+body {
  4
+  color: #000;
  5
+  background: #FFF;
  6
+}
1  lib/catapult.rb
@@ -6,6 +6,7 @@
6 6
 
7 7
 module Catapult
8 8
   autoload :CLI, 'catapult/cli'
  9
+  autoload :Compressor, 'catapult/compressor'
9 10
   autoload :TryStatic, 'catapult/try_static'
10 11
 
11 12
   def self.root
8  lib/catapult/cli.rb
@@ -15,10 +15,16 @@ def self.source_root
15 15
     desc 'build [asset1 asset2..]', 'Build project'
16 16
 
17 17
     method_option :target, :aliases => '-t', :desc => 'Directory to compile assets to'
  18
+    method_option :compile, :type => :boolean, :aliases => '-c', :desc => 'Compile and minify assets'
18 19
 
19 20
     def build(*assets)
20 21
       target = Pathname(options[:target] || './public/assets')
21 22
 
  23
+      if options[:compile]
  24
+        Catapult.environment.js_compressor  = Compressor::JS.new
  25
+        Catapult.environment.css_compressor = Compressor::CSS.new
  26
+      end
  27
+
22 28
       say "Building: #{Catapult.root}"
23 29
 
24 30
       Catapult.environment.each_logical_path(assets) do |logical_path|
@@ -63,4 +69,4 @@ def new(name)
63 69
       directory('templates/app', name)
64 70
     end
65 71
   end
66  
-end
  72
+end
18  lib/catapult/compressor.rb
... ...
@@ -0,0 +1,18 @@
  1
+module Catapult
  2
+  module Compressor
  3
+    class JS
  4
+      def compress(source, options = {})
  5
+        require 'uglifier'
  6
+        Uglifier.compile(source, options)
  7
+      end
  8
+    end
  9
+
  10
+    class CSS
  11
+      def compress(source, options = {})
  12
+        require 'yui/compressor'
  13
+        compressor = YUI::CssCompressor.new(options)
  14
+        compressor.compress(source)
  15
+      end
  16
+    end
  17
+  end
  18
+end
7  templates/app/browser.json
... ...
@@ -1,7 +0,0 @@
1  
-{
2  
-  "name": "app",
3  
-  "version": "1.0.0",
4  
-  "dependencies": {
5  
-    "jquery": "latest"
6  
-  }
7  
-}

0 notes on commit d944cc9

Please sign in to comment.
Something went wrong with that request. Please try again.