compressit 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +2 -0
- data/bin/compressit +10 -0
- data/compressit.gemspec +23 -0
- data/lib/compressit/base.rb +104 -0
- data/lib/compressit/railtie.rb +16 -0
- data/lib/compressit/version.rb +3 -0
- data/lib/compressit.rb +51 -0
- data/lib/tasks/compressit.rake +20 -0
- data/lib/tasks/compressit.thor +27 -0
- data/lib/yuicompressor-2.4.6.jar +0 -0
- data/spec/compressit_spec.rb +15 -0
- data/spec/spec_helper.rb +2 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 sdomino
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= Compressit
|
2
|
+
|
3
|
+
Compressit provides a simple way to compress your project .css and .js files to not only reduce their size, but also reduce web requests improving the overall performance of your site.
|
4
|
+
|
5
|
+
== Features
|
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)
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
=== Rails
|
16
|
+
|
17
|
+
Add this line to your Gemfile:
|
18
|
+
|
19
|
+
gem 'compressit'
|
20
|
+
|
21
|
+
Then bundle install:
|
22
|
+
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
=== Non Rails
|
28
|
+
|
29
|
+
gem install compressit
|
30
|
+
|
31
|
+
== Usage
|
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)
|
65
|
+
|
66
|
+
---
|
67
|
+
|
68
|
+
=== Thor
|
69
|
+
|
70
|
+
(coming soon)
|
71
|
+
|
72
|
+
== Copyright
|
73
|
+
|
74
|
+
Copyright (c) 2011 Steve Domino. See LICENSE.txt for further details
|
data/Rakefile
ADDED
data/bin/compressit
ADDED
data/compressit.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "compressit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "compressit"
|
7
|
+
s.version = Compressit::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["sdomino"]
|
10
|
+
s.email = ["sdomino@pagodabox.com"]
|
11
|
+
s.homepage = "http://wwww.pagodabox.com"
|
12
|
+
s.summary = "Compressit is a simple gem that will compress all of your .css and .js."
|
13
|
+
s.description = "Compressit uses the yuicompressor-2.4.6.jar java file created by Yahoo to compress all of your .css and .js files into single compressed files respectively. This not only reduces the size of your files, but also results in less http requests at load time resulting in an overall faster site."
|
14
|
+
|
15
|
+
s.rubyforge_project = "compressit"
|
16
|
+
|
17
|
+
s.add_development_dependency "rspec"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = [".", "lib"]
|
23
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Compressit
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@java = '/usr/bin/java'
|
7
|
+
@yuicompressor = File.expand_path(File.dirname(__FILE__) + './../yuicompressor-2.4.6.jar')
|
8
|
+
|
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}"
|
48
|
+
|
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
|
59
|
+
|
60
|
+
@ext = '.js'
|
61
|
+
@compressed = "compressed-#{@js_version}.#{@ext}"
|
62
|
+
|
63
|
+
compressit
|
64
|
+
end
|
65
|
+
|
66
|
+
def compressit
|
67
|
+
# remove compressed file if the version hasn't been updated to avoid duplicate compression
|
68
|
+
`rm -f #{File.path(@destination_path)}/#{@compressed}` if File.exists?("#{File.path(@destination_path)}/#{@compressed}")
|
69
|
+
|
70
|
+
# 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"
|
74
|
+
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
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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
|
data/lib/compressit.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'compressit/base'
|
4
|
+
require 'compressit/version'
|
5
|
+
|
6
|
+
require 'compressit/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
module Compressit
|
9
|
+
class << self
|
10
|
+
|
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
|
20
|
+
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
|
+
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
|
39
|
+
end
|
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
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
Binary file
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compressit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- sdomino
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-13 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Compressit uses the yuicompressor-2.4.6.jar java file created by Yahoo to compress all of your .css and .js files into single compressed files respectively. This not only reduces the size of your files, but also results in less http requests at load time resulting in an overall faster site.
|
27
|
+
email:
|
28
|
+
- sdomino@pagodabox.com
|
29
|
+
executables:
|
30
|
+
- compressit
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- bin/compressit
|
42
|
+
- compressit.gemspec
|
43
|
+
- lib/compressit.rb
|
44
|
+
- lib/compressit/base.rb
|
45
|
+
- lib/compressit/railtie.rb
|
46
|
+
- lib/compressit/version.rb
|
47
|
+
- lib/tasks/compressit.rake
|
48
|
+
- lib/tasks/compressit.thor
|
49
|
+
- lib/yuicompressor-2.4.6.jar
|
50
|
+
- spec/compressit_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
homepage: http://wwww.pagodabox.com
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- .
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: compressit
|
76
|
+
rubygems_version: 1.7.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Compressit is a simple gem that will compress all of your .css and .js.
|
80
|
+
test_files:
|
81
|
+
- spec/compressit_spec.rb
|
82
|
+
- spec/spec_helper.rb
|