compressed-gzipped-assets 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/compressed-gzipped-assets.example.yml +5 -0
- data/compressed-gzipped-assets.gemspec +64 -0
- data/lib/compressed-gzipped-assets.rb +80 -0
- data/test/helper.rb +10 -0
- data/test/test_compressed-gzipped-assets.rb +7 -0
- metadata +106 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Shaw
|
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,17 @@
|
|
1
|
+
= compressed-gzipped-assets
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Ryan Shaw. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "compressed-gzipped-assets"
|
8
|
+
gem.summary = %Q{compressed-gzipped-assets is a drop-in to use google closure compiler or yui compressor to compress/minify your css/js when caching is enabled, it will also save a gzipped version of the file in the same dirctory so your webserver doesnt have to gzip "on the fly" every time the file is requested. }
|
9
|
+
gem.description = %Q{for more info see the readme.}
|
10
|
+
gem.email = "ryankshaw@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ryankshaw/compressed-gzipped-assets"
|
12
|
+
gem.authors = ["Ryan Shaw"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_dependency 'rails', ['>= 2.1.0']
|
15
|
+
gem.add_dependency 'yui-compressor', ['>= 0.9.1']
|
16
|
+
gem.add_dependency 'closure-compiler', ['>= 0.1.6']
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "compressed-gzipped-assets #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{compressed-gzipped-assets}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Shaw"]
|
12
|
+
s.date = %q{2010-01-22}
|
13
|
+
s.description = %q{for more info see the readme.}
|
14
|
+
s.email = %q{ryankshaw@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"compressed-gzipped-assets.example.yml",
|
27
|
+
"compressed-gzipped-assets.gemspec",
|
28
|
+
"lib/compressed-gzipped-assets.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/test_compressed-gzipped-assets.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/ryankshaw/compressed-gzipped-assets}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
|
+
s.summary = %q{compressed-gzipped-assets is a drop-in to use google closure compiler or yui compressor to compress/minify your css/js when caching is enabled, it will also save a gzipped version of the file in the same dirctory so your webserver doesnt have to gzip "on the fly" every time the file is requested.}
|
37
|
+
s.test_files = [
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_compressed-gzipped-assets.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<rails>, [">= 2.1.0"])
|
49
|
+
s.add_runtime_dependency(%q<yui-compressor>, [">= 0.9.1"])
|
50
|
+
s.add_runtime_dependency(%q<closure-compiler>, [">= 0.1.6"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rails>, [">= 2.1.0"])
|
54
|
+
s.add_dependency(%q<yui-compressor>, [">= 0.9.1"])
|
55
|
+
s.add_dependency(%q<closure-compiler>, [">= 0.1.6"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rails>, [">= 2.1.0"])
|
60
|
+
s.add_dependency(%q<yui-compressor>, [">= 0.9.1"])
|
61
|
+
s.add_dependency(%q<closure-compiler>, [">= 0.1.6"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require 'zlib'
|
3
|
+
require "yui/compressor" # always required because even if you use closure-compiler it will be used for css
|
4
|
+
# closure-compiler is also required unless you want to use yui for both css and javascript
|
5
|
+
|
6
|
+
raise "GoogleClosureCompiler only Supports Rails >= 2.1.x" unless Rails.version >= "2.1"
|
7
|
+
|
8
|
+
# Adapted from Smurf plugin http://github.com/thumblemonks/smurf/
|
9
|
+
# Supports Rails >= 2.1.x
|
10
|
+
module ActionView::Helpers::AssetTagHelper
|
11
|
+
private
|
12
|
+
def join_asset_file_contents_with_compilation(files)
|
13
|
+
content = join_asset_file_contents_without_compilation(files)
|
14
|
+
if !files.grep(%r[/javascripts]).empty?
|
15
|
+
content = AssetCompressorWithGoogleClosureOrYUI.javascript_compressor.compress(content)
|
16
|
+
elsif !files.grep(%r[/stylesheets]).empty?
|
17
|
+
content = AssetCompressorWithGoogleClosureOrYUI.css_compressor.compress(content)
|
18
|
+
end
|
19
|
+
content
|
20
|
+
end
|
21
|
+
alias_method_chain :join_asset_file_contents, :compilation
|
22
|
+
|
23
|
+
# this helps the NginxHttpGzipStaticModule do it's thing.
|
24
|
+
# from it's website:
|
25
|
+
# Before serving a file from disk to a gzip-enabled client, this module will look
|
26
|
+
# for a precompressed file in the same location that ends in ".gz". The purpose
|
27
|
+
# is to avoid compressing the same file each time it is requested.
|
28
|
+
# see http://wiki.nginx.org/NginxHttpGzipStaticModule
|
29
|
+
def write_asset_file_contents_with_create_static_gziped_files(joined_asset_path, asset_paths)
|
30
|
+
FileUtils.mkdir_p(File.dirname(joined_asset_path))
|
31
|
+
contents = join_asset_file_contents(asset_paths)
|
32
|
+
File.open(joined_asset_path, "w+") { |cache| cache.write(contents) }
|
33
|
+
|
34
|
+
zip_name = "#{joined_asset_path}.gz"
|
35
|
+
Zlib::GzipWriter.open(zip_name, Zlib::BEST_COMPRESSION) {|f| f.write(contents) }
|
36
|
+
# Set mtime to the latest of the combined files to allow for
|
37
|
+
# consistent ETag without a shared filesystem.
|
38
|
+
mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max
|
39
|
+
File.utime(mt, mt, joined_asset_path, zip_name)
|
40
|
+
end
|
41
|
+
alias_method_chain :write_asset_file_contents, :create_static_gziped_files
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
end # ActionView::Helpers::AssetTagHelper
|
46
|
+
|
47
|
+
module AssetCompressorWithGoogleClosureOrYUI
|
48
|
+
class << self
|
49
|
+
CONFIG = YAML.load_file(File.join(RAILS_ROOT, 'config', 'asset_compressor_with_google_closure_or_yui.yml'))[RAILS_ENV] || {}
|
50
|
+
|
51
|
+
def compilation_level
|
52
|
+
CONFIG['compilation_level'] || 'SIMPLE_OPTIMIZATIONS'
|
53
|
+
end
|
54
|
+
|
55
|
+
def java
|
56
|
+
CONFIG['java'] || 'java'
|
57
|
+
end
|
58
|
+
|
59
|
+
def css_compressor
|
60
|
+
@css_compressor ||= YUI::CssCompressor.new({
|
61
|
+
:java => java
|
62
|
+
})
|
63
|
+
end
|
64
|
+
|
65
|
+
def javascript_compressor
|
66
|
+
@javascript_compressor ||= begin
|
67
|
+
if CONFIG['javascript_compressor'] == 'yui'
|
68
|
+
compressor_lib = YUI::JavaScriptCompressor
|
69
|
+
else
|
70
|
+
require 'closure-compiler'
|
71
|
+
compressor_lib = Closure::Compiler
|
72
|
+
end
|
73
|
+
compressor_lib.new({
|
74
|
+
:java => java,
|
75
|
+
:compilation_level => compilation_level
|
76
|
+
})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compressed-gzipped-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yui-compressor
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: closure-compiler
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.6
|
54
|
+
version:
|
55
|
+
description: for more info see the readme.
|
56
|
+
email: ryankshaw@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- compressed-gzipped-assets.example.yml
|
72
|
+
- compressed-gzipped-assets.gemspec
|
73
|
+
- lib/compressed-gzipped-assets.rb
|
74
|
+
- test/helper.rb
|
75
|
+
- test/test_compressed-gzipped-assets.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/ryankshaw/compressed-gzipped-assets
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
version:
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.5
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: compressed-gzipped-assets is a drop-in to use google closure compiler or yui compressor to compress/minify your css/js when caching is enabled, it will also save a gzipped version of the file in the same dirctory so your webserver doesnt have to gzip "on the fly" every time the file is requested.
|
104
|
+
test_files:
|
105
|
+
- test/helper.rb
|
106
|
+
- test/test_compressed-gzipped-assets.rb
|