sinatra-bundles 0.1.1 → 0.1.2
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.md +12 -2
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/lib/sinatra/bundles.rb +4 -4
- data/sinatra-bundles.gemspec +5 -2
- data/spec/sinatra-bundles_spec.rb +11 -11
- metadata +12 -2
data/README.md
CHANGED
@@ -20,7 +20,11 @@ Assuming you have the following files in public:
|
|
20
20
|
./javascripts/lightbox.js
|
21
21
|
./javascripts/blog.js
|
22
22
|
|
23
|
-
You can bundle these files in your app like this
|
23
|
+
You can bundle these files in your app like this. First, install the gem
|
24
|
+
|
25
|
+
% [sudo] gem install sinatra-bundles
|
26
|
+
|
27
|
+
And include it in your app:
|
24
28
|
|
25
29
|
require 'sinatra'
|
26
30
|
require 'sinatra/bundles'
|
@@ -32,6 +36,8 @@ You can bundle these files in your app like this:
|
|
32
36
|
'sinatra-bundles rocks!'
|
33
37
|
end
|
34
38
|
|
39
|
+
That sinatra is version 0.10.1, so you'll have to grab it from source and install it that way, since it's not out yet.
|
40
|
+
|
35
41
|
Then in your view, you can use the view helpers to insert the proper script tags:
|
36
42
|
|
37
43
|
= javascript_bundle_include_tag(:all)
|
@@ -79,7 +85,11 @@ Check out the code for my blog for a real example: [darkblog on github](http://g
|
|
79
85
|
What you Need
|
80
86
|
-------------
|
81
87
|
|
82
|
-
sinatra >= 0.10.1 (edge)
|
88
|
+
sinatra >= 0.10.1 (edge)
|
89
|
+
packr
|
90
|
+
rainpress
|
91
|
+
|
92
|
+
packr and rainpress are dependencies, but sinatra isn't, since version 0.10.1 isn't out yet, and you have to download the source manually.
|
83
93
|
|
84
94
|
Note on Patches/Pull Requests
|
85
95
|
-----------------------------
|
data/Rakefile
CHANGED
@@ -12,8 +12,7 @@ begin
|
|
12
12
|
gem.authors = ['Daniel Huckstep']
|
13
13
|
gem.add_dependency 'rainpress', '>= 0'
|
14
14
|
gem.add_dependency 'packr', '>= 0'
|
15
|
-
|
16
|
-
# gem.add_dependency 'sinatra', '>= 0.10.1'
|
15
|
+
gem.add_dependency 'sinatra', '>= 1.0.a'
|
17
16
|
gem.add_development_dependency 'rspec', '>= 1.2.9'
|
18
17
|
gem.add_development_dependency 'rack-test', '>= 0.5.3'
|
19
18
|
gem.add_development_dependency 'yard', '>= 0'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/sinatra/bundles.rb
CHANGED
@@ -44,7 +44,7 @@ module Sinatra
|
|
44
44
|
# @param [String] name The name of a bundle
|
45
45
|
# @return [String] The HTML that can be inserted into the doc
|
46
46
|
def to_html(name)
|
47
|
-
"<link type='text/css' href='/stylesheets/
|
47
|
+
"<link type='text/css' href='/stylesheets/bundles/#{name}.css#{@app.stamp_bundles ? "?#{stamp}" : ''}' rel='stylesheet' media='screen' />"
|
48
48
|
end
|
49
49
|
|
50
50
|
protected
|
@@ -74,7 +74,7 @@ module Sinatra
|
|
74
74
|
# @param [String] name The name of a bundle
|
75
75
|
# @return [String] The HTML that can be inserted into the doc
|
76
76
|
def to_html(name)
|
77
|
-
"<script type='text/javascript' src='/javascripts/
|
77
|
+
"<script type='text/javascript' src='/javascripts/bundles/#{name}.js#{@app.stamp_bundles ? "?#{stamp}" : ''}'></script>"
|
78
78
|
end
|
79
79
|
|
80
80
|
protected
|
@@ -153,14 +153,14 @@ module Sinatra
|
|
153
153
|
|
154
154
|
app.helpers(Helpers)
|
155
155
|
|
156
|
-
app.get('/stylesheets/
|
156
|
+
app.get('/stylesheets/bundles/:bundle.css') do |bundle|
|
157
157
|
content_type('text/css')
|
158
158
|
headers['Vary'] = 'Accept-Encoding'
|
159
159
|
expires(options.bundle_cache_time, :public, :must_revalidate) if options.cache_bundles
|
160
160
|
options.stylesheet_bundles[bundle.intern]
|
161
161
|
end
|
162
162
|
|
163
|
-
app.get('/javascripts/
|
163
|
+
app.get('/javascripts/bundles/:bundle.js') do |bundle|
|
164
164
|
content_type('text/javascript; charset=utf-8')
|
165
165
|
headers['Vary'] = 'Accept-Encoding'
|
166
166
|
expires(options.bundle_cache_time, :public, :must_revalidate) if options.cache_bundles
|
data/sinatra-bundles.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-bundles}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Huckstep"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-07}
|
13
13
|
s.description = %q{Bundle CSS and Javascript assets to a single file, compress, and cache them for snappier web experiences.}
|
14
14
|
s.email = %q{darkhelmet@darkhelmetlive.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -109,12 +109,14 @@ Gem::Specification.new do |s|
|
|
109
109
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
110
110
|
s.add_runtime_dependency(%q<rainpress>, [">= 0"])
|
111
111
|
s.add_runtime_dependency(%q<packr>, [">= 0"])
|
112
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 1.0.a"])
|
112
113
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
113
114
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.3"])
|
114
115
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
115
116
|
else
|
116
117
|
s.add_dependency(%q<rainpress>, [">= 0"])
|
117
118
|
s.add_dependency(%q<packr>, [">= 0"])
|
119
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.a"])
|
118
120
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
119
121
|
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
120
122
|
s.add_dependency(%q<yard>, [">= 0"])
|
@@ -122,6 +124,7 @@ Gem::Specification.new do |s|
|
|
122
124
|
else
|
123
125
|
s.add_dependency(%q<rainpress>, [">= 0"])
|
124
126
|
s.add_dependency(%q<packr>, [">= 0"])
|
127
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.a"])
|
125
128
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
126
129
|
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
127
130
|
s.add_dependency(%q<yard>, [">= 0"])
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require 'app'
|
3
3
|
require 'production_app'
|
4
4
|
|
5
|
-
describe '
|
5
|
+
describe 'sinatra-bundles' do
|
6
6
|
def app(env = :test)
|
7
7
|
case env
|
8
8
|
when :production
|
@@ -85,28 +85,28 @@ describe 'SinatraBundles' do
|
|
85
85
|
app.new.instance_eval do
|
86
86
|
options.disable(:stamp_bundles)
|
87
87
|
javascript_bundle_include_tag(:test)
|
88
|
-
end.should == "<script type='text/javascript' src='/javascripts/
|
88
|
+
end.should == "<script type='text/javascript' src='/javascripts/bundles/test.js'></script>"
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should stamp bundles with the timestamp of the newest file in the bundle' do
|
92
92
|
app.new.instance_eval do
|
93
93
|
javascript_bundle_include_tag(:test)
|
94
|
-
end.should == "<script type='text/javascript' src='/javascripts/
|
94
|
+
end.should == "<script type='text/javascript' src='/javascripts/bundles/test.js?#{js_stamp(%w(test1 test2))}'></script>"
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should serve bundles' do
|
98
|
-
get "/javascripts/
|
98
|
+
get "/javascripts/bundles/test.js"
|
99
99
|
last_response.should be_ok
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'should concat files in order with newlines including one at the end' do
|
103
|
-
get '/javascripts/
|
103
|
+
get '/javascripts/bundles/test.js'
|
104
104
|
last_response.body.should == @scripts.map { |path| File.read(path) }.join("\n") + "\n"
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should set cache headers' do
|
108
108
|
app.enable(:cache_bundles)
|
109
|
-
get '/javascripts/
|
109
|
+
get '/javascripts/bundles/test.js'
|
110
110
|
last_response.should be_ok
|
111
111
|
last_response.headers['Vary'].should == 'Accept-Encoding'
|
112
112
|
last_response.headers['Cache-Control'].should == 'public, must-revalidate, max-age=31536000'
|
@@ -124,28 +124,28 @@ describe 'SinatraBundles' do
|
|
124
124
|
app.new.instance_eval do
|
125
125
|
options.disable(:stamp_bundles)
|
126
126
|
stylesheet_bundle_link_tag(:test)
|
127
|
-
end.should == "<link type='text/css' href='/stylesheets/
|
127
|
+
end.should == "<link type='text/css' href='/stylesheets/bundles/test.css' rel='stylesheet' media='screen' />"
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'should stamp bundles with the timestamp of the newest file in the bundle' do
|
131
131
|
app.new.instance_eval do
|
132
132
|
stylesheet_bundle_link_tag(:test)
|
133
|
-
end.should == "<link type='text/css' href='/stylesheets/
|
133
|
+
end.should == "<link type='text/css' href='/stylesheets/bundles/test.css?#{css_stamp(%w(test1 test2))}' rel='stylesheet' media='screen' />"
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should serve bundles' do
|
137
|
-
get "/stylesheets/
|
137
|
+
get "/stylesheets/bundles/test.css"
|
138
138
|
last_response.should be_ok
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should concat files in order with newlines including one at the end' do
|
142
|
-
get '/stylesheets/
|
142
|
+
get '/stylesheets/bundles/test.css'
|
143
143
|
last_response.body.should == @styles.map { |path| File.read(path) }.join("\n") + "\n"
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'should set cache headers' do
|
147
147
|
app.enable(:cache_bundles)
|
148
|
-
get '/stylesheets/
|
148
|
+
get '/stylesheets/bundles/test.css'
|
149
149
|
last_response.should be_ok
|
150
150
|
last_response.headers['Vary'].should == 'Accept-Encoding'
|
151
151
|
last_response.headers['Cache-Control'].should == 'public, must-revalidate, max-age=31536000'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-bundles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Huckstep
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,16 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: sinatra
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.a
|
44
|
+
version:
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: rspec
|
37
47
|
type: :development
|