rack-cat 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme +2 -2
- data/VERSION +1 -1
- data/lib/rack/cat.rb +21 -9
- data/rack-cat.gemspec +2 -2
- data/test/cat_test.rb +19 -0
- metadata +3 -3
data/Readme
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/rack/cat.rb
CHANGED
@@ -10,26 +10,38 @@ module Rack
|
|
10
10
|
@sources = options[:sources] # array with source dirs
|
11
11
|
@debug = options[:debug] # regenerate bundles on each request
|
12
12
|
|
13
|
-
create_bundles
|
13
|
+
create_bundles unless @debug
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
-
create_bundles if @debug
|
17
|
+
create_bundles(Rack::Request.new(env).path) if @debug
|
18
18
|
@app.call(env)
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def
|
24
|
-
@bundles.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
def bundle_path(request_path)
|
24
|
+
@bundles.keys.detect { |bp| request_path.start_with?(bp) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_bundles(request_path = nil)
|
28
|
+
if request_path && bp = bundle_path(request_path)
|
29
|
+
create_bundle(bp)
|
30
|
+
else
|
31
|
+
@bundles.keys.each do |bp|
|
32
|
+
create_bundle(bp)
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
37
|
+
def create_bundle(bundle_path)
|
38
|
+
concatenation = @bundles[bundle_path].map do |path|
|
39
|
+
read_from_disk(path) || read_from_app(path)
|
40
|
+
end.join("\n")
|
41
|
+
|
42
|
+
write_to_disk(bundle_path, concatenation)
|
43
|
+
end
|
44
|
+
|
33
45
|
def write_to_disk(path, content)
|
34
46
|
full_path = ::File.join(@destination, path)
|
35
47
|
FileUtils.mkdir_p(::File.dirname(full_path))
|
data/rack-cat.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-cat}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jacek Becela"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-03}
|
13
13
|
s.description = %q{Rack middleware to concatenate yor assets (static, dynamic and remote). Use it to serve your javascripts and stylesheets faster!}
|
14
14
|
s.email = %q{jacek.becela@gmail.com}
|
15
15
|
s.files = [
|
data/test/cat_test.rb
CHANGED
@@ -16,6 +16,25 @@ class CatTest < Test::Unit::TestCase
|
|
16
16
|
app.call(env)
|
17
17
|
|
18
18
|
assert_equal "foo\nbar\nbaz\napp", File.read("test/fixtures/baz/public/all.txt")
|
19
|
+
FileUtils.rm_r("test/fixtures/baz")
|
20
|
+
end
|
21
|
+
|
22
|
+
test "concatentaion of static and dynamic files in debug mode" do
|
23
|
+
env = Rack::MockRequest.env_for("/all.txt")
|
24
|
+
app = Rack::Cat.new(
|
25
|
+
lambda {|env| [200, {}, ["app"]]},
|
26
|
+
:sources => ["test/fixtures", "test/fixtures/foo"],
|
27
|
+
:bundles => {
|
28
|
+
"/all.txt" => ["/foo.txt", "/bar/bar.txt", "/baz.txt", "/app.txt"],
|
29
|
+
"/none.txt" => ["/foo.txt", "/app.txt"]
|
30
|
+
},
|
31
|
+
:destination => "test/fixtures/baz/public/",
|
32
|
+
:debug => true
|
33
|
+
)
|
34
|
+
app.call(env)
|
35
|
+
|
36
|
+
assert_equal "foo\nbar\nbaz\napp", File.read("test/fixtures/baz/public/all.txt")
|
37
|
+
assert !File.exists?("test/fixtures/baz/public/none.txt")
|
19
38
|
|
20
39
|
FileUtils.rm_r("test/fixtures/baz")
|
21
40
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jacek Becela
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-03 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|