Permalink
Browse files

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

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

0 comments on commit d944cc9

Please sign in to comment.