rack-cat 0.1.0 → 0.1.1

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/Readme CHANGED
@@ -27,8 +27,8 @@ So in Rails you would type in config/environment.rb:
27
27
  config.middleware.use Rack::Cat, { options hash like the above one here }
28
28
 
29
29
 
30
- Contirbuting
31
- ============
30
+ Contribute
31
+ ==========
32
32
 
33
33
  Fork. Commit. Send pull requests.
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -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 create_bundles
24
- @bundles.each do |bundle, paths|
25
- concatenation = paths.map do |path|
26
- read_from_disk(path) || read_from_app(path)
27
- end.join("\n")
28
-
29
- write_to_disk(bundle, concatenation)
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))
@@ -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.0"
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-04-22}
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 = [
@@ -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
- - 0
9
- version: 0.1.0
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-04-22 00:00:00 +02:00
17
+ date: 2010-08-03 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency