djanowski-collage 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/Rakefile +28 -0
- data/example/config.ru +8 -0
- data/example/public/app.js +3 -0
- data/example/public/jquery.js +3 -0
- data/lib/collage.rb +87 -0
- metadata +66 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/gempackagetask'
|
|
3
|
+
require 'rake/clean'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
gem_spec_file = 'collage.gemspec'
|
|
7
|
+
|
|
8
|
+
gem_spec = eval(File.read(gem_spec_file)) rescue nil
|
|
9
|
+
|
|
10
|
+
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
|
11
|
+
pkg.need_zip = false
|
|
12
|
+
pkg.need_tar = false
|
|
13
|
+
rm_f FileList['pkg/**/*.*']
|
|
14
|
+
end if gem_spec
|
|
15
|
+
|
|
16
|
+
desc "Generate the gemspec file."
|
|
17
|
+
task :gemspec do
|
|
18
|
+
require 'erb'
|
|
19
|
+
|
|
20
|
+
File.open(gem_spec_file, 'w') do |f|
|
|
21
|
+
f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Builds and installs the gem."
|
|
26
|
+
task :install => :repackage do
|
|
27
|
+
`sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
|
|
28
|
+
end
|
data/example/config.ru
ADDED
data/lib/collage.rb
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class Collage
|
|
2
|
+
def initialize(app, options)
|
|
3
|
+
@app = app
|
|
4
|
+
@path = File.expand_path(options[:path])
|
|
5
|
+
@files = options[:files]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def call(env)
|
|
9
|
+
return @app.call(env) unless env['PATH_INFO'] == "/#{Collage.filename}"
|
|
10
|
+
|
|
11
|
+
result = Packager.new(@path, @files)
|
|
12
|
+
|
|
13
|
+
result.ignore(filename)
|
|
14
|
+
|
|
15
|
+
File.open(filename, 'w') {|f| f.write(result) }
|
|
16
|
+
|
|
17
|
+
[200, {'Content-Type' => 'text/javascript', 'Content-Length' => result.size.to_s, 'Last-Modified' => result.mtime.httpdate}, result]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def filename
|
|
21
|
+
File.join(@path, Collage.filename)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
def filename
|
|
26
|
+
"js.js"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def timestamp(path)
|
|
30
|
+
Packager.new(path).timestamp
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def html_tag(path)
|
|
34
|
+
%Q{<script type="text/javascript" src="/#{filename}?#{timestamp(path)}"></script>}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Packager
|
|
39
|
+
def initialize(path, patterns = nil)
|
|
40
|
+
@path = path
|
|
41
|
+
@patterns = Array(patterns || "**/*.js")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def package
|
|
45
|
+
files.inject("") do |contents,file|
|
|
46
|
+
contents += File.read(file) + "\n\n"
|
|
47
|
+
contents
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def files
|
|
52
|
+
@files ||= @patterns.map do |pattern|
|
|
53
|
+
Dir[File.join(@path, pattern)]
|
|
54
|
+
end.flatten
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def timestamp
|
|
58
|
+
mtime.to_i.to_s
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def mtime
|
|
62
|
+
@mtime ||= files.map {|f| File.mtime(f) }.max
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def size
|
|
66
|
+
result.size
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def result
|
|
70
|
+
@result ||= package
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def each(&block)
|
|
74
|
+
result.each(&block)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def to_s
|
|
78
|
+
result.to_s
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def ignore(file)
|
|
82
|
+
if files.delete(file)
|
|
83
|
+
@result = nil
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: djanowski-collage
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Damian Janowski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-03-01 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: damian.janowski@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.markdown
|
|
24
|
+
files:
|
|
25
|
+
- lib/collage.rb
|
|
26
|
+
- LICENSE
|
|
27
|
+
- Rakefile
|
|
28
|
+
- example/config.ru
|
|
29
|
+
- example/public
|
|
30
|
+
- example/public/app.js
|
|
31
|
+
- example/public/jquery.js
|
|
32
|
+
- example/public/js.js
|
|
33
|
+
- README.markdown
|
|
34
|
+
has_rdoc: false
|
|
35
|
+
homepage:
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options:
|
|
38
|
+
- --line-numbers
|
|
39
|
+
- --inline-source
|
|
40
|
+
- --title
|
|
41
|
+
- collage
|
|
42
|
+
- --main
|
|
43
|
+
- README.markdown
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
version:
|
|
58
|
+
requirements: []
|
|
59
|
+
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.2.0
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 2
|
|
64
|
+
summary: Rack middleware that packages your JS into a single file.
|
|
65
|
+
test_files: []
|
|
66
|
+
|