compressit 0.5.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,21 +4,21 @@ Compressit provides a simple way to compress your project .css and .js files to
4
4
 
5
5
  == Features
6
6
 
7
- Compressit is designed to work within Rails projects or stand-alone, and supports the following:
8
-
9
- * Rake tasks
10
- * Command Line Input (CLI) (coming soon)
11
- * Thor tasks (coming soon)
7
+ * Command Line Input (CLI)
8
+ * Rake tasks (discontinued)
9
+ * Thor tasks (discontinued)
12
10
 
13
11
  == Install
14
12
 
15
- === Rails
13
+ === Rails (discontinued support)
14
+
15
+ NOTE: This will still work with Rails, however I have discontinued a specific rails 'integration' due to a very similar feature being added with the release of Rails 3.1
16
16
 
17
17
  Add this line to your Gemfile:
18
18
 
19
19
  gem 'compressit'
20
20
 
21
- Then bundle install:
21
+ Then do a bundle install:
22
22
 
23
23
  bundle install
24
24
 
@@ -30,44 +30,21 @@ Then bundle install:
30
30
 
31
31
  == Usage
32
32
 
33
- === CLI
34
-
35
- (coming soon)
36
-
37
- ---
38
-
39
- === Rake
40
-
41
- ==== Rails
42
- Setup (It is not required that you run this as both the .css and .js rake tasks will run it automatically):
43
-
44
- rake compressit:setup
45
-
46
- * Creates 'config/initializers/compressit.rb' with the version constants 'CSS_VERSION' and 'JS_VERSION' defaulted to '1.0.0'
47
- * Creates 'public/stylesheets/compressed/' where compressed .css file is saved
48
- * Creates 'public/javascripts/compressed/' where the compressed file is saved
49
-
50
- Iterates through 'public/stylesheets' and compresses all .css files placing them into 'public/stylesheets/compressed/'
51
-
52
- rake compressit:css
53
-
54
- Iterates through 'public/javascripts' and compresses all .js files placing them into 'public/javascripts/compressed/'
55
-
56
- rake compressit:js
57
-
58
- Versioning:
59
-
60
- Use 'config/initializers/compressit.rb' to version your .css and .js files. If you do not increment the version at all the previous file will just be overwritten
61
-
62
- ==== Non-Rails
63
-
64
- (coming soon)
33
+ Usage: compressit [option] [FOLDER] [VERSION]
34
+
35
+ -h, --help Display this screen
36
+ -v, --version Display current gem version
37
+ -c, --css FOLDER VERSION Compress css files from [FOLDER] into [FOLDER]/compressed
38
+ -j, --js FOLDER VERSION Compress javascript files from [FOLDER] into [FOLDER]/compressed
65
39
 
66
40
  ---
67
41
 
68
- === Thor
42
+ == TODO
69
43
 
70
- (coming soon)
44
+ * May add a better versioning system
45
+ * Initially had the ability to specify a destination folder, may add this back if requested
46
+ * Tests
47
+ * One final pass of cleanup and refactoring
71
48
 
72
49
  == Copyright
73
50
 
data/bin/compressit CHANGED
@@ -7,4 +7,4 @@ rescue LoadError
7
7
  require 'compressit'
8
8
  end
9
9
 
10
- Compressit.run(ARGV, STDIN)
10
+ Compressit.run(ARGV)
data/lib/compressit.rb CHANGED
@@ -1,51 +1,42 @@
1
- require 'optparse'
2
-
3
- require 'compressit/base'
4
- require 'compressit/version'
1
+ Dir["#{File.dirname(__FILE__)}/compressit/*"].each {|file| require(file)}
5
2
 
6
- require 'compressit/railtie' if defined?(Rails)
3
+ require 'optparse'
7
4
 
8
5
  module Compressit
9
6
  class << self
10
7
 
11
- def run(arguments, stdin)
12
- @arguments = arguments
13
- @stdin = stdin
14
-
15
- if parsed_options? && arguments_valid?
16
- process_arguments
17
- process_command
18
- else
19
- # Compressit::Base.show_usage
8
+ def run(arguments)
9
+ options = Hash.new
10
+
11
+ optparser = OptionParser.new do|opts|
12
+
13
+ opts.banner = "Usage: compressit [option] [FOLDER] [VERSION]"
14
+
15
+ opts.on('-h', '--help', 'Display this help') do
16
+ puts optparser
17
+ end
18
+ opts.on('-v', '--version', 'Display current gem version') do
19
+ puts "Currently using version: #{VERSION}"
20
+ end
21
+ opts.on('-c', '--css FOLDER VERSION', 'Compress css files from [FOLDER] into [FOLDER]/compressed') do
22
+ puts "Compressing css files from '#{arguments[0]}' into '#{arguments[0]}/compressed/compressed-#{arguments[1]}.css'"
23
+ options[:folder], options[:version], options[:ext] = arguments[0], arguments[1], '.css'
24
+ Compressit::Base.compressit(options)
25
+ end
26
+ opts.on('-j', '--js FOLDER VERSION', 'Compress javascript files from [FOLDER] into [FOLDER]/compressed') do
27
+ puts "Compressing javascript files from '#{arguments[0]}' into '#{arguments[0]}/compressed/compressed-#{arguments[1]}.js'"
28
+ options[:folder], options[:version], options[:ext] = arguments[0], arguments[1], '.js'
29
+ Compressit::Base.compressit(options)
30
+ end
20
31
  end
21
- end
22
-
23
- def parsed_options?
24
- oparser = OptionParser.new
25
- oparser.on('-h', '--help') {Compressit::Base.show_usage}
26
- oparser.on('-s', '--setup') {Compressit::Base.setup}
27
- oparser.on('-v', '--version') {puts "#{VERSION}"}
28
-
29
- oparser.on('-css', '--css') {Compressit::Base.css}
30
- oparser.on('-js', '--js') {Compressit::Base.js}
31
32
 
32
- oparser.parse!(@arguments) rescue return false
33
- end
34
-
35
- # True if required arguments were provided
36
- def arguments_valid?
37
- # TO DO - implement your real logic here
38
- true
33
+ begin optparser.parse!(arguments)
34
+ rescue OptionParser::InvalidOption => error
35
+ puts "Oops! #{error}, try this: "
36
+ puts optparser
37
+ exit 1
38
+ end
39
39
  end
40
40
 
41
- # Setup the arguments
42
- def process_arguments
43
- # TO DO - place in local vars, etc
44
- end
45
-
46
- def process_command
47
- # TO DO - do whatever this app does
48
- end
49
-
50
41
  end
51
42
  end
@@ -2,101 +2,31 @@ module Compressit
2
2
  module Base
3
3
  class << self
4
4
 
5
- def setup
6
- @java = '/usr/bin/java'
7
- @yuicompressor = File.expand_path(File.dirname(__FILE__) + './../yuicompressor-2.4.6.jar')
5
+ def compressit(options)
6
+ @version, @ext, @folder = options[:version], options[:ext], options[:folder]
8
7
 
9
- if defined?(Rails)
10
- # install thor tasks (coming soon)
11
- # `thor install lib/tasks/compressit.thor`
12
-
13
- # create the rails initializer that will contain the css/js version constants
14
- unless File.exists?("#{Rails.root}/config/initializers/compressit.rb")
15
- File.open("#{Rails.root}/config/initializers/compressit.rb", 'w') do |file|
16
- file.puts "CSS_VERSION = '1.0.0'"
17
- file.puts "JS_VERSION = '1.0.0'"
18
- end
19
- end
20
-
21
- # create the folder where the compressed .css files will be saved
22
- File.directory?("#{Rails.root}/public/stylesheets/compressed") ? true : Dir.mkdir("#{Rails.root}/public/stylesheets/compressed")
23
-
24
- # create the folder where the compressed .js files will be saved
25
- File.directory?("#{Rails.root}/public/javascripts/compressed") ? true : Dir.mkdir("#{Rails.root}/public/javascripts/compressed")
26
-
27
- # after the initializer has been created it needs to be required because it cannot be accessed through rake tasks
28
- require "#{Rails.root}/config/initializers/compressit.rb"
29
-
30
- # set css/js instance variables from css/js constants
31
- @css_version = CSS_VERSION
32
- @js_version = JS_VERSION
33
- else
34
- # coming soon
35
- end
36
- end
37
-
38
- def css
39
- if defined?(Rails)
40
- @files_to_compress = Dir.glob("#{Rails.root}/public/stylesheets/**/*.css")
41
- @destination_path = Dir.open("#{Rails.root}/public/stylesheets/compressed")
42
- else
43
- # coming soon
44
- end
45
-
46
- @ext = '.css'
47
- @compressed = "compressed-#{@css_version}#{@ext}"
8
+ @java, @yuicompressor = '/usr/bin/java', File.expand_path(File.dirname(__FILE__) + './../yuicompressor-2.4.6.jar')
48
9
 
49
- compressit
50
- end
51
-
52
- def js
53
- if defined?(Rails)
54
- @files_to_compress = Dir.glob("#{Rails.root}/public/javascripts/**/*.js")
55
- @destination_path = Dir.open("#{Rails.root}/public/javascripts/compressed")
56
- else
57
- # coming soon
58
- end
10
+ Dir.exists?("#{@folder}/compressed") ? true : Dir.mkdir("#{@folder}/compressed")
11
+ @destination_path = Dir.open("#{@folder}/compressed")
59
12
 
60
- @ext = '.js'
61
- @compressed = "compressed-#{@js_version}.#{@ext}"
13
+ @files_to_compress, @compressed = Dir.glob("#{@folder}/**/*#{@ext}"), "compressed-#{@version}#{@ext}"
62
14
 
63
- compressit
64
- end
65
-
66
- def compressit
67
15
  # remove compressed file if the version hasn't been updated to avoid duplicate compression
68
16
  `rm -f #{File.path(@destination_path)}/#{@compressed}` if File.exists?("#{File.path(@destination_path)}/#{@compressed}")
69
-
17
+
70
18
  # compress each file in @files_to_compress and save the compressed file to @destination_path
71
- @files_to_compress.each do |file|
72
- `#{@java} -jar #{@yuicompressor} #{file} >> #{File.path(@destination_path)}/#{@compressed}`
73
- puts "Added: #{File.basename(file)}... \n"
19
+ begin
20
+ @files_to_compress.each do |file|
21
+ `#{@java} -jar #{@yuicompressor} #{file} >> #{File.path(@destination_path)}/#{@compressed}`
22
+ puts "Added: #{File.basename(file)}... \n"
23
+ end
24
+
25
+ # confirm compression and show destination path where file can be found
26
+ puts "Complete! Compressed #{@ext} file '#{@compressed}', can be found in '#{File.path(@destination_path)}'"
27
+ rescue
28
+ puts "Hmm... looks like this folder doesn't contain any #{@ext} files."
74
29
  end
75
-
76
- # confirm compression and show destination path where file can be found
77
- puts "Complete! Compressed #{@ext} file '#{@compressed}', can be found in '#{File.path(@destination_path)}'"
78
- end
79
-
80
- # add the ability to see css/js version. do
81
-
82
- def show_usage
83
- puts %{
84
- --- Usage ---
85
- (--)help, -h # show this usage
86
- (--)setup, -s # create initial .css and .js version files
87
- (--)version, -v # show the current gem version
88
-
89
- (--)css, -css # compress .css files with the version specified in the config file (coming soon)
90
- (--)js, -js # compress .js files with the version specified in the config file (coming soon)
91
-
92
- --- Rake Tasks ---
93
- rake css # compress .css files with the version specified in the config file
94
- rake js # compress .js files with the version specified in the config file
95
-
96
- --- Thor Tasks ---
97
- thor css # compress .css files with the version specified in the config file (coming soon)
98
- thor js # compress .js files with the version specified in the config file (coming soon)
99
- }
100
30
  end
101
31
 
102
32
  end
@@ -1,3 +1,3 @@
1
1
  module Compressit
2
- VERSION = "0.5.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: compressit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.1
5
+ version: 0.9.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - sdomino
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-08 00:00:00 Z
13
+ date: 2011-08-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -42,10 +42,7 @@ files:
42
42
  - compressit.gemspec
43
43
  - lib/compressit.rb
44
44
  - lib/compressit/base.rb
45
- - lib/compressit/railtie.rb
46
45
  - lib/compressit/version.rb
47
- - lib/tasks/compressit.rake
48
- - lib/tasks/compressit.thor
49
46
  - lib/yuicompressor-2.4.6.jar
50
47
  - spec/compressit_spec.rb
51
48
  - spec/spec_helper.rb
@@ -1,16 +0,0 @@
1
- require 'rails'
2
-
3
- module Compressit
4
- class Railtie < Rails::Railtie
5
-
6
- # initializer "compressit.configure_rails_initialization" do
7
- #
8
- # end
9
-
10
- rake_tasks do
11
- # load "tasks/compressit.tasks"
12
- load "tasks/compressit.rake"
13
- end
14
-
15
- end
16
- end
@@ -1,20 +0,0 @@
1
- require 'compressit'
2
-
3
- namespace :compressit do
4
-
5
- desc ''
6
- task :setup do
7
- Compressit::Base.setup
8
- end
9
-
10
- desc ''
11
- task :css => :setup do
12
- Compressit::Base.css
13
- end
14
-
15
- desc ''
16
- task :js => :setup do
17
- Compressit::Base.js
18
- end
19
-
20
- end
@@ -1,27 +0,0 @@
1
- # require 'compressit'
2
-
3
- class Compressit < Thor
4
-
5
- desc ''
6
- def config do
7
- Compressit::Base.config
8
- end
9
-
10
- desc ''
11
- def setup do
12
- Compressit::Base.setup
13
- end
14
-
15
- desc ''
16
- method_options :version, :default => "1.0.0"
17
- def css do
18
- Compressit::Base.css
19
- end
20
-
21
- desc ''
22
- method_options :version, :default => "1.0.0"
23
- def js do
24
- Compressit::Base.js
25
- end
26
-
27
- end