rack-cat 0.0.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/.gitignore +1 -0
- data/Rakefile +16 -0
- data/Readme +46 -0
- data/VERSION +1 -0
- data/lib/rack/cat.rb +53 -0
- data/rack-cat.gemspec +45 -0
- metadata +90 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "rack-cat"
|
5
|
+
gem.summary = "Rack middleware to concatenate yor assets (static, dynamic and remote)"
|
6
|
+
gem.description = "Rack middleware to concatenate yor assets (static, dynamic and remote). Use it to serve your javascripts and stylesheets faster!"
|
7
|
+
gem.email = "jacek.becela@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/ncr/rack-cat"
|
9
|
+
gem.authors = ["Jacek Becela"]
|
10
|
+
gem.add_dependency "rack"
|
11
|
+
gem.add_development_dependency "rack-test"
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
16
|
+
end
|
data/Readme
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
Rack::Cat
|
2
|
+
=========
|
3
|
+
|
4
|
+
A Rack middleware to concatenate your assets (static, dynamic and remote) to serve javascripts and stylesheets faster.
|
5
|
+
|
6
|
+
Currently it supports concatenating static files (read from disk) and dynamic pages (read from the app itself).
|
7
|
+
Remote file support will become a reality when I find someone who needs it ;)
|
8
|
+
|
9
|
+
|
10
|
+
Usage
|
11
|
+
=====
|
12
|
+
|
13
|
+
Use like any other Rack middleware. Rack::Cat constructor takes an options hash as a second argument:
|
14
|
+
|
15
|
+
{
|
16
|
+
:bundles => {
|
17
|
+
"/all.css" => [ "/stylesheets/layout.css", "/stylesheets/widgets.css"],
|
18
|
+
"/all.js" => [ "/javascripts/jquery.js", "/javascripts/application.js"]
|
19
|
+
},
|
20
|
+
:sources => ["tmp/public", "public"], # directiories to search for files (that tmp/public comes handy if you use heroku)
|
21
|
+
:destination => "public", # directory to write files to ("tmp/public" on heroku)
|
22
|
+
:debug => Rails.env.development? # regenerate files on each request (for use in development mode)
|
23
|
+
}
|
24
|
+
|
25
|
+
So in Rails you would type in config/environment.rb:
|
26
|
+
|
27
|
+
config.middleware.use Rack::Cat, { options hash like the above one here }
|
28
|
+
|
29
|
+
|
30
|
+
Contirbuting
|
31
|
+
============
|
32
|
+
|
33
|
+
Fork. Commit. Send pull requests.
|
34
|
+
|
35
|
+
|
36
|
+
Author
|
37
|
+
======
|
38
|
+
|
39
|
+
Jacek Becela http://github.com/ncr
|
40
|
+
|
41
|
+
|
42
|
+
License
|
43
|
+
=======
|
44
|
+
|
45
|
+
MIT
|
46
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/rack/cat.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "rack/mock"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class Cat
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@bundles = options[:bundles] # { "/destination/path" => [ "/array/of", "/source/paths"] }
|
9
|
+
@destination = options[:destination] # a directory to write bundles into
|
10
|
+
@sources = options[:sources] # array with source dirs
|
11
|
+
@debug = options[:debug] # regenerate bundles on each request
|
12
|
+
|
13
|
+
create_bundles
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
create_bundles if @debug
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
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)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_to_disk(path, content)
|
34
|
+
full_path = ::File.join(@destination, path)
|
35
|
+
FileUtils.mkdir_p(::File.dirname(full_path))
|
36
|
+
|
37
|
+
::File.open(full_path, "w") do |f|
|
38
|
+
f.write(content)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_from_disk(path)
|
43
|
+
@sources.each do |source|
|
44
|
+
full_path = ::File.join(source, Rack::Utils.unescape(path))
|
45
|
+
return ::File.read(full_path) if ::File.file?(full_path) && ::File.readable?(full_path)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_from_app(path)
|
50
|
+
Rack::MockRequest.new(@app).get(path).body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/rack-cat.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
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{rack-cat}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jacek Becela"]
|
12
|
+
s.date = %q{2010-04-22}
|
13
|
+
s.description = %q{Rack middleware to concatenate yor assets (static, dynamic and remote). Use it to serve your javascripts and stylesheets faster!}
|
14
|
+
s.email = %q{jacek.becela@gmail.com}
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme",
|
19
|
+
"VERSION",
|
20
|
+
"lib/rack/cat.rb",
|
21
|
+
"rack-cat.gemspec"
|
22
|
+
]
|
23
|
+
s.homepage = %q{http://github.com/ncr/rack-cat}
|
24
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
s.rubygems_version = %q{1.3.6}
|
27
|
+
s.summary = %q{Rack middleware to concatenate yor assets (static, dynamic and remote)}
|
28
|
+
|
29
|
+
if s.respond_to? :specification_version then
|
30
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
31
|
+
s.specification_version = 3
|
32
|
+
|
33
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
34
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
35
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
38
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
42
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-cat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jacek Becela
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-22 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rack-test
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Rack middleware to concatenate yor assets (static, dynamic and remote). Use it to serve your javascripts and stylesheets faster!
|
45
|
+
email: jacek.becela@gmail.com
|
46
|
+
executables: []
|
47
|
+
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files: []
|
51
|
+
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Rakefile
|
55
|
+
- Readme
|
56
|
+
- VERSION
|
57
|
+
- lib/rack/cat.rb
|
58
|
+
- rack-cat.gemspec
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/ncr/rack-cat
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Rack middleware to concatenate yor assets (static, dynamic and remote)
|
89
|
+
test_files: []
|
90
|
+
|