rack-sprocketize 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +79 -0
- data/Rakefile +13 -0
- data/lib/rack-sprocketize.rb +1 -0
- data/lib/rack/sprocketize.rb +91 -0
- data/lib/rack/sprocketize/sprocket.rb +51 -0
- data/lib/rack/sprocketize/version.rb +5 -0
- data/rack-sprocketize.gemspec +30 -0
- data/spec/rack/sprocketize_spec.rb +234 -0
- data/spec/spec_helper.rb +44 -0
- metadata +208 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Peter Browne
|
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.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Rack::Sprocketize
|
2
|
+
|
3
|
+
Rack::Sprocketize is a piece of Rack Middleware which uses [Sprockets](http://getsprockets.org/) to concatenate javascript files and then optionally compresses them. In a development environment, the files will be sprocketized on each request if there have been changes to the source files. In a production environment, the files will only be sprocketized one time, and only if there have been changes. Also, in a production environment, the files will be compressed by whichever javascript compressor is available.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install rack-sprocketize
|
8
|
+
|
9
|
+
## Basic Usage
|
10
|
+
|
11
|
+
require 'rack-sprocketize'
|
12
|
+
use Rack::Sprocketize
|
13
|
+
|
14
|
+
or in Rails:
|
15
|
+
|
16
|
+
# Gemfile
|
17
|
+
gem 'rack-sprocketize'
|
18
|
+
|
19
|
+
# config/application.rb
|
20
|
+
config.middleware.use Rack::Sprocketize
|
21
|
+
|
22
|
+
### Sprocketizing
|
23
|
+
|
24
|
+
Rack::Sprocketize takes each file in the given `:source_path` (`'app/javascripts'` by default) and uses Sprockets to include any other required files. Then it outputs the results in the `:output_path` (`'public/javascripts` by default). Also, files that begin with `'_'` will not be sprocketized and will essentially be treated like partials.
|
25
|
+
|
26
|
+
So, given the following files in an app:
|
27
|
+
|
28
|
+
# app/javascripts/main.js
|
29
|
+
//= require "_partial"
|
30
|
+
|
31
|
+
# app/javascripts/_partial.js
|
32
|
+
var hello = 'world';
|
33
|
+
|
34
|
+
# app/javascripts/plugin.js
|
35
|
+
var plugin = 'blah';
|
36
|
+
|
37
|
+
Rack::Sprocketize will sprocketize them into `:output_path` like this:
|
38
|
+
|
39
|
+
# public/javascripts/main.js
|
40
|
+
var hello = 'world';
|
41
|
+
|
42
|
+
# public/javascripts/plugin.js
|
43
|
+
var plugin = 'blah';
|
44
|
+
|
45
|
+
Notice how the files weren't all concatenated into one file. You use Sprockets' `//= require` syntax to control how the files will be concatenated.
|
46
|
+
|
47
|
+
Both the `:source_path` and `:output_path` can be customized when setting up Rack::Sprocketize:
|
48
|
+
|
49
|
+
use Rack::Sprocketize, :source_path => 'js', :output_path => 'public/js'
|
50
|
+
|
51
|
+
### Compression
|
52
|
+
|
53
|
+
Rack::Sprocketize determines which javascript compressor you want to use based on which one has been required.
|
54
|
+
|
55
|
+
require 'packr'
|
56
|
+
use Rack::Sprocketize
|
57
|
+
# would use Packr
|
58
|
+
|
59
|
+
or in Rails:
|
60
|
+
|
61
|
+
# Gemfile
|
62
|
+
gem 'jsmin'
|
63
|
+
|
64
|
+
# config/application.rb
|
65
|
+
config.middleware.use Rack::Sprocketize
|
66
|
+
# would use JSMin
|
67
|
+
|
68
|
+
To pass options to the javascript compressor just use the `:compression_options` option:
|
69
|
+
|
70
|
+
require 'packr'
|
71
|
+
use Rack::Sprocketize, :compression_options => { :shrink_vars => true }
|
72
|
+
|
73
|
+
By default, the files are only compressed in a production environment. If for some reason you want them to always be compressed, pass the `:always_compress` option:
|
74
|
+
|
75
|
+
use Rack::Sprocketize, :always_compress => true
|
76
|
+
|
77
|
+
## Copyright
|
78
|
+
|
79
|
+
Copyright (c) 2011 [Peter Browne](http://petebrowne.com). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
|
8
|
+
desc 'Open an irb session preloaded with this library'
|
9
|
+
task :console do
|
10
|
+
sh 'irb -rubygems -I lib -r rack/sprocketize'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/sprocketize'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Sprocketize
|
5
|
+
autoload :Sprocket, 'rack/sprocketize/sprocket'
|
6
|
+
autoload :VERSION, 'rack/sprocketize/version'
|
7
|
+
|
8
|
+
DEFAULT_OPTIONS = {
|
9
|
+
:source_path => 'app/javascripts',
|
10
|
+
:output_path => 'public/javascripts',
|
11
|
+
:load_path => %w(vendor/javascripts)
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :options, :compression_options, :source_path, :output_path, :always_check, :always_compress
|
16
|
+
|
17
|
+
def configure(options = {})
|
18
|
+
self.options = DEFAULT_OPTIONS.dup.merge(options)
|
19
|
+
self.compression_options = self.options.delete(:compression_options) || {}
|
20
|
+
self.source_path = ::File.expand_path self.options.delete(:source_path)
|
21
|
+
self.output_path = ::File.expand_path self.options.delete(:output_path)
|
22
|
+
|
23
|
+
self.always_check = if self.options.key?(:always_check)
|
24
|
+
self.options.delete(:always_check)
|
25
|
+
else
|
26
|
+
self.environment == 'development'
|
27
|
+
end
|
28
|
+
|
29
|
+
self.always_compress = if self.options.key?(:always_compress)
|
30
|
+
self.options.delete(:always_compress)
|
31
|
+
else
|
32
|
+
self.environment == 'production'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def environment
|
37
|
+
if defined?(RAILS_ENV)
|
38
|
+
RAILS_ENV # Rails 2
|
39
|
+
elsif defined?(Rails) && defined?(Rails.env)
|
40
|
+
Rails.env.to_s # Rails 3
|
41
|
+
elsif defined?(@app.settings) && defined?(@app.settings.environment)
|
42
|
+
@app.settings.environment # Sinatra
|
43
|
+
elsif ENV.key?('RACK_ENV')
|
44
|
+
ENV['RACK_ENV']
|
45
|
+
else
|
46
|
+
'development'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def always_check?
|
51
|
+
!!@always_check
|
52
|
+
end
|
53
|
+
|
54
|
+
def always_compress?
|
55
|
+
!!@always_compress
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(app, options = {})
|
60
|
+
@app = app
|
61
|
+
Sprocketize.configure(options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def call(env)
|
65
|
+
@request = Rack::Request.new(env)
|
66
|
+
sprocketize unless skip?
|
67
|
+
@app.call(env)
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def skip?
|
73
|
+
return false if Sprocketize.always_check?
|
74
|
+
@sprocketized && @request.params['sprocketize'].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def source_files
|
78
|
+
files = Dir.glob ::File.join(Sprocketize.source_path, '**/*.js')
|
79
|
+
files.reject! { |file| ::File.basename(file) =~ /^_/ }
|
80
|
+
files
|
81
|
+
end
|
82
|
+
|
83
|
+
def sprocketize
|
84
|
+
source_files.each do |source_file|
|
85
|
+
sprocket = Sprocket.new(source_file)
|
86
|
+
sprocket.sprocketize if sprocket.stale?
|
87
|
+
end
|
88
|
+
@sprocketized = true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'sprockets'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class Sprocketize
|
6
|
+
class Sprocket
|
7
|
+
def initialize(source_file)
|
8
|
+
@source_file = source_file
|
9
|
+
@output_path = @source_file.sub /^#{Regexp.escape(Sprocketize.source_path)}/, Sprocketize.output_path
|
10
|
+
@secretary = Sprockets::Secretary.new Sprocketize.options.merge(:source_files => [ @source_file ])
|
11
|
+
end
|
12
|
+
|
13
|
+
def compress(output)
|
14
|
+
if defined?(JSMin)
|
15
|
+
JSMin.minify(output)
|
16
|
+
elsif defined?(Packr)
|
17
|
+
Packr.pack output, compression_options(:shrink_vars => true)
|
18
|
+
elsif defined?(YUI) and defined?(YUI::JavaScriptCompressor)
|
19
|
+
YUI::JavaScriptCompressor.new(compression_options(:munge => true)).compress(output)
|
20
|
+
elsif defined?(Closure) and defined?(Closure::Compiler)
|
21
|
+
Closure::Compiler.new(compression_options).compile(output)
|
22
|
+
else
|
23
|
+
output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def concat
|
28
|
+
@secretary.concatenation.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def stale?
|
32
|
+
!::File.exist?(@output_path) || @secretary.source_last_modified > ::File.mtime(@output_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def sprocketize
|
36
|
+
FileUtils.mkdir_p ::File.dirname(@output_path)
|
37
|
+
::File.open(@output_path, 'w') do |file|
|
38
|
+
output = concat
|
39
|
+
output = compress(output) if Sprocketize.always_compress?
|
40
|
+
file.write(output.strip)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def compression_options(defaults = {})
|
47
|
+
defaults.merge Sprocketize.compression_options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'rack/sprocketize/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'rack-sprocketize'
|
7
|
+
s.version = Rack::Sprocketize::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = %w(Pete Browne)
|
10
|
+
s.email = %w(me@petebrowne.com)
|
11
|
+
s.homepage = ''
|
12
|
+
s.summary = %(Rack::Sprocketize is a piece of Rack Middleware which uses Sprockets to concatenate javascript files and then optionally compresses them.)
|
13
|
+
s.description = %(Rack::Sprocketize is a piece of Rack Middleware which uses Sprockets to concatenate javascript files and then optionally compresses them. In a development environment, the files will be sprocketized on each request if there have been changes to the source files. In a production environment, the files will only be sprocketized one time, and only if there have been changes. Also, in a production environment, the files will be compressed by whichever javascript compressor is available.)
|
14
|
+
|
15
|
+
s.rubyforge_project = 'rack-sprocketize'
|
16
|
+
|
17
|
+
s.add_dependency 'rack', '~> 1.2.1'
|
18
|
+
s.add_dependency 'sprockets', '~> 1.0.2'
|
19
|
+
s.add_development_dependency 'rspec', '~> 2.5.0'
|
20
|
+
s.add_development_dependency 'test-construct', '~> 1.2.0'
|
21
|
+
s.add_development_dependency 'jsmin', '~> 1.0.1'
|
22
|
+
s.add_development_dependency 'packr', '~> 3.1.0'
|
23
|
+
s.add_development_dependency 'yui-compressor', '~> 0.9.4'
|
24
|
+
s.add_development_dependency 'closure-compiler', '~> 1.0.0'
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
29
|
+
s.require_paths = %w(lib)
|
30
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::Sprocketize do
|
4
|
+
it 'concatenates javascripts' do
|
5
|
+
within_construct do |c|
|
6
|
+
c.file 'app/javascripts/main.js', %{//= require <plugin>\n//= require "_plugin"}
|
7
|
+
c.file 'app/javascripts/another.js', '1'
|
8
|
+
c.file 'vendor/javascripts/plugin.js', '2'
|
9
|
+
c.file 'app/javascripts/_plugin.js', '3'
|
10
|
+
|
11
|
+
app.call(request)
|
12
|
+
|
13
|
+
File.read('public/javascripts/main.js').should == "2\n3"
|
14
|
+
File.read('public/javascripts/another.js').should == "1"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not compress the output' do
|
19
|
+
reveal_const :JSMin do
|
20
|
+
within_construct do |c|
|
21
|
+
c.file 'app/javascripts/main.js', '1'
|
22
|
+
|
23
|
+
JSMin.should_not_receive(:minify)
|
24
|
+
app.call(request)
|
25
|
+
File.read('public/javascripts/main.js').should == '1'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when main files are updated' do
|
31
|
+
it 'concatenates again' do
|
32
|
+
within_construct do |c|
|
33
|
+
c.file 'app/javascripts/main.js', '1'
|
34
|
+
|
35
|
+
app.call(request)
|
36
|
+
sleep 1
|
37
|
+
c.file 'app/javascripts/main.js', '2'
|
38
|
+
|
39
|
+
app.call(request)
|
40
|
+
File.read('public/javascripts/main.js').should == '2'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when required files are updated' do
|
46
|
+
it 'concatenates again' do
|
47
|
+
within_construct do |c|
|
48
|
+
c.file 'app/javascripts/main.js', %{//= require "_plugin"}
|
49
|
+
c.file 'app/javascripts/_plugin.js', '1'
|
50
|
+
|
51
|
+
app.call(request)
|
52
|
+
sleep 1
|
53
|
+
c.file 'app/javascripts/_plugin.js', '2'
|
54
|
+
|
55
|
+
app.call(request)
|
56
|
+
File.read('public/javascripts/main.js').should == '2'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when files are added' do
|
62
|
+
it 'concatenates the new files' do
|
63
|
+
within_construct do |c|
|
64
|
+
c.file 'app/javascripts/main.js', '1'
|
65
|
+
|
66
|
+
app.call(request)
|
67
|
+
sleep 1
|
68
|
+
c.file 'app/javascripts/another.js', %{//= require "_plugin"}
|
69
|
+
c.file 'app/javascripts/_plugin.js', '2'
|
70
|
+
|
71
|
+
app.call(request)
|
72
|
+
File.read('public/javascripts/another.js').should == '2'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when there are no changes' do
|
78
|
+
it 'does not concatenate' do
|
79
|
+
within_construct do |c|
|
80
|
+
c.file 'app/javascripts/main.js', '1'
|
81
|
+
|
82
|
+
app.call(request)
|
83
|
+
sleep 1
|
84
|
+
|
85
|
+
output_file = Pathname.new('public/javascripts/main.js')
|
86
|
+
expect {
|
87
|
+
app.call(request)
|
88
|
+
}.to_not change(output_file, :mtime)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with :always_check set to false' do
|
94
|
+
it 'does not concatenate' do
|
95
|
+
within_construct do |c|
|
96
|
+
c.file 'app/javascripts/main.js', '1'
|
97
|
+
|
98
|
+
app(:always_check => false).call(request)
|
99
|
+
sleep 1
|
100
|
+
c.file 'app/javascripts/main.js', '2'
|
101
|
+
|
102
|
+
app.call(request)
|
103
|
+
File.read('public/javascripts/main.js').should == '1'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'with :always_compress set to true' do
|
109
|
+
context 'with jsmin required' do
|
110
|
+
it 'compresses the output' do
|
111
|
+
reveal_const :JSMin do
|
112
|
+
within_construct do |c|
|
113
|
+
c.file 'app/javascripts/main.js', '1'
|
114
|
+
|
115
|
+
JSMin.should_receive(:minify).with("1\n").and_return('compressed')
|
116
|
+
app(:always_compress => true).call(request)
|
117
|
+
File.read('public/javascripts/main.js').should == 'compressed'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with packr required' do
|
124
|
+
it 'compresses the output' do
|
125
|
+
reveal_const :Packr do
|
126
|
+
within_construct do |c|
|
127
|
+
c.file 'app/javascripts/main.js', '1'
|
128
|
+
|
129
|
+
Packr.should_receive(:pack).with("1\n", :shrink_vars => true).and_return('compressed')
|
130
|
+
app(:always_compress => true).call(request)
|
131
|
+
File.read('public/javascripts/main.js').should == 'compressed'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'with yui/compressor required' do
|
138
|
+
it 'compresses the output' do
|
139
|
+
reveal_const :YUI do
|
140
|
+
within_construct do |c|
|
141
|
+
c.file 'app/javascripts/main.js', '1'
|
142
|
+
|
143
|
+
compressor = double(:compressor)
|
144
|
+
compressor.should_receive(:compress).with("1\n").and_return('compressed')
|
145
|
+
YUI::JavaScriptCompressor.should_receive(:new).with(:munge => true).and_return(compressor)
|
146
|
+
app(:always_compress => true).call(request)
|
147
|
+
File.read('public/javascripts/main.js').should == 'compressed'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'with closure-compiler required' do
|
154
|
+
it 'compresses the output' do
|
155
|
+
reveal_const :Closure do
|
156
|
+
within_construct do |c|
|
157
|
+
c.file 'app/javascripts/main.js', '1'
|
158
|
+
|
159
|
+
compiler = double(:compiler)
|
160
|
+
compiler.should_receive(:compile).with("1\n").and_return('compressed')
|
161
|
+
Closure::Compiler.should_receive(:new).and_return(compiler)
|
162
|
+
app(:always_compress => true).call(request)
|
163
|
+
File.read('public/javascripts/main.js').should == 'compressed'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'in a production environment' do
|
171
|
+
before do
|
172
|
+
Rails = double(:rails, :env => 'production')
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
Object.send(:remove_const, :Rails)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'concatenates only one time' do
|
180
|
+
within_construct do |c|
|
181
|
+
c.file 'app/javascripts/main.js', '1'
|
182
|
+
|
183
|
+
app.call(request)
|
184
|
+
sleep 1
|
185
|
+
c.file 'app/javascripts/main.js', '2'
|
186
|
+
|
187
|
+
app.call(request)
|
188
|
+
File.read('public/javascripts/main.js').should == '1'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'compresses the output' do
|
193
|
+
reveal_const :JSMin do
|
194
|
+
within_construct do |c|
|
195
|
+
c.file 'app/javascripts/main.js', '1'
|
196
|
+
|
197
|
+
JSMin.should_receive(:minify).with("1\n").and_return('compressed')
|
198
|
+
app.call(request)
|
199
|
+
File.read('public/javascripts/main.js').should == 'compressed'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'with a :sprocketize param' do
|
205
|
+
it 'concatenates again' do
|
206
|
+
within_construct do |c|
|
207
|
+
c.file 'app/javascripts/main.js', '1'
|
208
|
+
|
209
|
+
app.call(request)
|
210
|
+
sleep 1
|
211
|
+
c.file 'app/javascripts/main.js', '2'
|
212
|
+
|
213
|
+
app.call request('/?sprocketize=1')
|
214
|
+
File.read('public/javascripts/main.js').should == '2'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'with :always_check set to true' do
|
220
|
+
it 'concatenates again' do
|
221
|
+
within_construct do |c|
|
222
|
+
c.file 'app/javascripts/main.js', '1'
|
223
|
+
|
224
|
+
app(:always_check => true).call(request)
|
225
|
+
sleep 1
|
226
|
+
c.file 'app/javascripts/main.js', '2'
|
227
|
+
|
228
|
+
app.call(request)
|
229
|
+
File.read('public/javascripts/main.js').should == '2'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path('../../lib', __FILE__)
|
2
|
+
$:.unshift(lib) unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'rspec'
|
7
|
+
require 'construct'
|
8
|
+
require 'pathname'
|
9
|
+
require 'jsmin'
|
10
|
+
require 'packr'
|
11
|
+
require 'yui/compressor'
|
12
|
+
require 'closure-compiler'
|
13
|
+
require 'rack/sprocketize'
|
14
|
+
|
15
|
+
$hidden_consts = {}
|
16
|
+
[ :JSMin, :Packr, :YUI, :Closure ].each do |const|
|
17
|
+
$hidden_consts[const] = Object.const_get(const)
|
18
|
+
Object.send :remove_const, const
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.include Construct::Helpers
|
23
|
+
|
24
|
+
def app(*args)
|
25
|
+
@app ||= Rack::Builder.app do
|
26
|
+
use Rack::Lint
|
27
|
+
use Rack::Sprocketize, *args
|
28
|
+
run lambda { |env| [ 200, { 'Content-Type' => 'text/html' }, [ 'Hello World!' ] ] }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def request(url = '/', options = {})
|
33
|
+
Rack::MockRequest.env_for(url, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def reveal_const(const)
|
37
|
+
begin
|
38
|
+
Object.const_set const, $hidden_consts[const]
|
39
|
+
yield
|
40
|
+
ensure
|
41
|
+
Object.send :remove_const, const
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-sprocketize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pete
|
14
|
+
- Browne
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-03-07 00:00:00 -06:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rack
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 29
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 2
|
34
|
+
- 1
|
35
|
+
version: 1.2.1
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: sprockets
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 19
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 2
|
51
|
+
version: 1.0.2
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rspec
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 27
|
63
|
+
segments:
|
64
|
+
- 2
|
65
|
+
- 5
|
66
|
+
- 0
|
67
|
+
version: 2.5.0
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: test-construct
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 31
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 2
|
82
|
+
- 0
|
83
|
+
version: 1.2.0
|
84
|
+
type: :development
|
85
|
+
version_requirements: *id004
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: jsmin
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 21
|
95
|
+
segments:
|
96
|
+
- 1
|
97
|
+
- 0
|
98
|
+
- 1
|
99
|
+
version: 1.0.1
|
100
|
+
type: :development
|
101
|
+
version_requirements: *id005
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: packr
|
104
|
+
prerelease: false
|
105
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 3
|
113
|
+
- 1
|
114
|
+
- 0
|
115
|
+
version: 3.1.0
|
116
|
+
type: :development
|
117
|
+
version_requirements: *id006
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: yui-compressor
|
120
|
+
prerelease: false
|
121
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 51
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
- 9
|
130
|
+
- 4
|
131
|
+
version: 0.9.4
|
132
|
+
type: :development
|
133
|
+
version_requirements: *id007
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: closure-compiler
|
136
|
+
prerelease: false
|
137
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ~>
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 23
|
143
|
+
segments:
|
144
|
+
- 1
|
145
|
+
- 0
|
146
|
+
- 0
|
147
|
+
version: 1.0.0
|
148
|
+
type: :development
|
149
|
+
version_requirements: *id008
|
150
|
+
description: Rack::Sprocketize is a piece of Rack Middleware which uses Sprockets to concatenate javascript files and then optionally compresses them. In a development environment, the files will be sprocketized on each request if there have been changes to the source files. In a production environment, the files will only be sprocketized one time, and only if there have been changes. Also, in a production environment, the files will be compressed by whichever javascript compressor is available.
|
151
|
+
email:
|
152
|
+
- me@petebrowne.com
|
153
|
+
executables: []
|
154
|
+
|
155
|
+
extensions: []
|
156
|
+
|
157
|
+
extra_rdoc_files: []
|
158
|
+
|
159
|
+
files:
|
160
|
+
- .gitignore
|
161
|
+
- Gemfile
|
162
|
+
- LICENSE
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- lib/rack-sprocketize.rb
|
166
|
+
- lib/rack/sprocketize.rb
|
167
|
+
- lib/rack/sprocketize/sprocket.rb
|
168
|
+
- lib/rack/sprocketize/version.rb
|
169
|
+
- rack-sprocketize.gemspec
|
170
|
+
- spec/rack/sprocketize_spec.rb
|
171
|
+
- spec/spec_helper.rb
|
172
|
+
has_rdoc: true
|
173
|
+
homepage: ""
|
174
|
+
licenses: []
|
175
|
+
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options: []
|
178
|
+
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
version: "0"
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
none: false
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
hash: 3
|
196
|
+
segments:
|
197
|
+
- 0
|
198
|
+
version: "0"
|
199
|
+
requirements: []
|
200
|
+
|
201
|
+
rubyforge_project: rack-sprocketize
|
202
|
+
rubygems_version: 1.3.7
|
203
|
+
signing_key:
|
204
|
+
specification_version: 3
|
205
|
+
summary: Rack::Sprocketize is a piece of Rack Middleware which uses Sprockets to concatenate javascript files and then optionally compresses them.
|
206
|
+
test_files:
|
207
|
+
- spec/rack/sprocketize_spec.rb
|
208
|
+
- spec/spec_helper.rb
|