wbzyl-sinatra-static-assets 0.0.2 → 0.0.5
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.markdown +25 -15
- data/Rakefile +0 -8
- data/VERSION.yml +1 -1
- data/examples/app1/{app.rb → app1.rb} +1 -1
- data/examples/app1/config.ru +2 -4
- data/examples/app1/views/index.erb +1 -1
- data/examples/app1/views/layout.erb +2 -1
- data/examples/app2/{app.rb → app2.rb} +1 -1
- data/examples/app2/config.ru +2 -4
- data/examples/app2/public/stylesheets/app2.css +18 -0
- data/examples/app2/public/stylesheets/src/skating.png +0 -0
- data/lib/sinatra/static_assets.rb +39 -15
- data/sinatra-static-assets.gemspec +8 -7
- metadata +8 -7
- data/examples/app2/public/stylesheets/src/bronzed_olive.png +0 -0
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# *StaticAssets* Sinatra Extension
|
2
2
|
|
3
3
|
To install it, run:
|
4
4
|
|
@@ -10,15 +10,27 @@ To use, include it in a Sinatra application:
|
|
10
10
|
gem 'wbzyl-sinatra-static-assets'
|
11
11
|
require 'sinatra/static_assets'
|
12
12
|
|
13
|
-
|
13
|
+
## When you will need this gem?
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
# ...
|
18
|
-
end
|
15
|
+
In short, whenever two or more applications are deployed to sub-URI
|
16
|
+
with Phussion Passenger.
|
19
17
|
|
18
|
+
This means, that we want these applications to be mounted
|
19
|
+
under one host, `http://example.org` in the example below:
|
20
20
|
|
21
|
-
|
21
|
+
http://example.org/app1
|
22
|
+
http://example.org/app2
|
23
|
+
...
|
24
|
+
http://example.org/tests/app3
|
25
|
+
http://example.org/secret/app3
|
26
|
+
...
|
27
|
+
|
28
|
+
See Phusion Passenger users guide, [Deploying a Rack-based Ruby
|
29
|
+
application](http://www.modrails.com/documentation/Users guide Apache.html#_deploying_a_rack_based_ruby_application),
|
30
|
+
Deploying to a sub URI.
|
31
|
+
|
32
|
+
|
33
|
+
*How to fix broken images/CSS/JavaScript URIs in sub-URI deployments*
|
22
34
|
|
23
35
|
Some people experience broken images and other broken static assets
|
24
36
|
when they deploy their application to a sub-URI
|
@@ -48,11 +60,6 @@ This will generate the proper image tag to
|
|
48
60
|
so that your images will always work
|
49
61
|
no matter what sub-URI you've deployed to.
|
50
62
|
|
51
|
-
These helper methods are more valuable than you may think. For example
|
52
|
-
they also append a timestamp to the URI to better facilitate HTTP
|
53
|
-
caching. For more information, please refer to the Rails API docs.
|
54
|
-
|
55
|
-
|
56
63
|
## Deploying to a sub URI
|
57
64
|
|
58
65
|
Add to */etc/hosts*:
|
@@ -74,8 +81,11 @@ Add to */etc/httpd/conf.d/sinatra.conf*
|
|
74
81
|
RackBaseURI /app2
|
75
82
|
</VirtualHost>
|
76
83
|
|
77
|
-
|
84
|
+
Now, goto to `http://sinatra.local/app1` or `http://sinatra.local/app2`.
|
85
|
+
|
86
|
+
|
87
|
+
## TODO
|
78
88
|
|
79
|
-
|
89
|
+
1. Append a timestamp to the URI to better facilitate HTTP
|
90
|
+
caching. For more information, see the Rails API docs.
|
80
91
|
|
81
|
-
Note the terminating slash.
|
data/Rakefile
CHANGED
@@ -27,11 +27,3 @@ Rake::TestTask.new(:test) do |t|
|
|
27
27
|
t.pattern = 'test/**/*_test.rb'
|
28
28
|
t.verbose = false
|
29
29
|
end
|
30
|
-
|
31
|
-
desc 'Install the package as a gem.'
|
32
|
-
task :install => [:clean, :build] do
|
33
|
-
gem = Dir['pkg/*.gem'].last
|
34
|
-
sh "sudo gem install --no-rdoc --no-ri --local #{gem}"
|
35
|
-
end
|
36
|
-
|
37
|
-
task :default => :test
|
data/VERSION.yml
CHANGED
data/examples/app1/config.ru
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# run with: thin --rackup config.ru -p 4567 start
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
# default with passenger
|
3
|
+
require 'app1'
|
6
4
|
|
5
|
+
use Rack::ShowExceptions
|
7
6
|
use Rack::Static, :urls => ["/stylesheets", "/javascripts", "/images"], :root => "public"
|
8
|
-
|
9
7
|
run Sinatra::Application
|
@@ -3,7 +3,8 @@
|
|
3
3
|
<head>
|
4
4
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
5
5
|
|
6
|
-
|
6
|
+
<%= stylesheet_link_tag "/stylesheets/app1.css" %>
|
7
|
+
|
7
8
|
<script src="/javascripts/app1.js" type="text/javascript"></script>
|
8
9
|
|
9
10
|
<title><%= @title %></title>
|
data/examples/app2/config.ru
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# run with: thin --rackup config.ru -p 4567 start
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
# default with passenger
|
3
|
+
require 'app2'
|
6
4
|
|
5
|
+
use Rack::ShowExceptions
|
7
6
|
use Rack::Static, :urls => ["/stylesheets", "/javascripts", "/images"], :root => "public"
|
8
|
-
|
9
7
|
run Sinatra::Application
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/*
|
2
|
+
Theme for app2: http://www.colourlovers.com/palette/81363/rainy
|
3
|
+
*/
|
4
|
+
|
5
|
+
html {
|
6
|
+
margin: 0;
|
7
|
+
padding: 0;
|
8
|
+
background: #659DF1 url(src/skating.png);
|
9
|
+
}
|
10
|
+
|
11
|
+
body {
|
12
|
+
width: 600px;
|
13
|
+
margin: 1em auto;
|
14
|
+
padding: 1em 2em;
|
15
|
+
border: black solid 1px;
|
16
|
+
background-color: #D8E8FF;
|
17
|
+
font: normal 14px/1.6 Arial, Helvetica, sans-serif;
|
18
|
+
}
|
Binary file
|
@@ -1,28 +1,48 @@
|
|
1
|
+
gem 'sinatra', '~>0.9.2'
|
1
2
|
require 'sinatra/base'
|
2
3
|
|
3
|
-
gem 'emk-sinatra-url-for'
|
4
|
+
gem 'emk-sinatra-url-for', '>=0.2.1'
|
4
5
|
require 'sinatra/url_for'
|
5
6
|
|
6
7
|
module Sinatra
|
7
8
|
module StaticAssets
|
8
|
-
|
9
|
+
|
10
|
+
# In HTML the <img> tag has no end tag:
|
11
|
+
#
|
12
|
+
# image_tag "/images/foo.png", :alt => "Foo itself"
|
13
|
+
#
|
14
|
+
# In XHTML the <img /> tag must be properly closed:
|
15
|
+
#
|
16
|
+
# image_tag "/images/foo.png", :alt => "Foo itself", :closed => true
|
17
|
+
#
|
9
18
|
def image_tag(source, options = {})
|
19
|
+
closed = options.delete(:closed)
|
10
20
|
options[:src] = url_for(source)
|
11
|
-
tag("img", options)
|
21
|
+
tag("img", options, closed)
|
12
22
|
end
|
13
|
-
|
23
|
+
|
24
|
+
# In HTML the <link> tag has no end tag:
|
25
|
+
#
|
26
|
+
# stylesheet_link_tag "/stylesheets/screen.css", "/stylesheets/print.css"
|
27
|
+
#
|
28
|
+
# In XHTML the <link> tag must be properly closed:
|
29
|
+
#
|
30
|
+
# stylesheet_link_tag "/stylesheets/screen.css", :closed => true
|
31
|
+
#
|
14
32
|
def stylesheet_link_tag(*sources)
|
15
|
-
|
33
|
+
list, options = extract_options(sources)
|
34
|
+
closed = options.delete(:closed)
|
35
|
+
list.collect { |source| stylesheet_tag(source, options, closed) }.join("\n")
|
16
36
|
end
|
17
|
-
|
18
|
-
def
|
37
|
+
|
38
|
+
def javascript_script_tag(*sources)
|
19
39
|
# TODO
|
20
40
|
end
|
21
41
|
|
22
42
|
private
|
23
43
|
|
24
|
-
def tag(name, options =
|
25
|
-
"<#{name}#{tag_options(options) if options}#{
|
44
|
+
def tag(name, options = {}, closed = false)
|
45
|
+
"<#{name}#{tag_options(options) if options}#{closed ? " />" : ">"}"
|
26
46
|
end
|
27
47
|
|
28
48
|
def tag_options(options)
|
@@ -33,17 +53,21 @@ module Sinatra
|
|
33
53
|
end
|
34
54
|
end
|
35
55
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
"href" => html_escape(path_to_stylesheet(source)) }.merge(options), false)
|
56
|
+
def stylesheet_tag(source, options, closed = false)
|
57
|
+
tag("link", { :type => "text/css",
|
58
|
+
:charset => "utf-8", :media => "screen", :rel => "stylesheet",
|
59
|
+
:href => url_for(source) }.merge(options), closed)
|
41
60
|
end
|
42
61
|
|
43
|
-
def
|
62
|
+
def javascript_tag(source, options)
|
44
63
|
# append onto tag </script>
|
45
64
|
end
|
46
65
|
|
66
|
+
def extract_options(a)
|
67
|
+
opts = a.last.is_a?(::Hash) ? a.pop : {}
|
68
|
+
[a, opts]
|
69
|
+
end
|
70
|
+
|
47
71
|
end
|
48
72
|
|
49
73
|
helpers StaticAssets
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sinatra-static-assets}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["W\305\202odek Bzyl"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-23}
|
10
10
|
s.description = %q{Sinatra extension providing helper methods to output tags for static assets.}
|
11
11
|
s.email = %q{matwb@univ.gda.pl}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
"README.markdown",
|
20
20
|
"Rakefile",
|
21
21
|
"VERSION.yml",
|
22
|
-
"examples/app1/
|
22
|
+
"examples/app1/app1.rb",
|
23
23
|
"examples/app1/config.ru",
|
24
24
|
"examples/app1/public/images/tatry1.jpg",
|
25
25
|
"examples/app1/public/javascripts/app1.js",
|
@@ -28,11 +28,12 @@ Gem::Specification.new do |s|
|
|
28
28
|
"examples/app1/tmp/always_restart.txt",
|
29
29
|
"examples/app1/views/index.erb",
|
30
30
|
"examples/app1/views/layout.erb",
|
31
|
-
"examples/app2/
|
31
|
+
"examples/app2/app2.rb",
|
32
32
|
"examples/app2/config.ru",
|
33
33
|
"examples/app2/public/images/tatry2.jpg",
|
34
34
|
"examples/app2/public/javascripts/app2.js",
|
35
|
-
"examples/app2/public/stylesheets/
|
35
|
+
"examples/app2/public/stylesheets/app2.css",
|
36
|
+
"examples/app2/public/stylesheets/src/skating.png",
|
36
37
|
"examples/app2/tmp/always_restart.txt",
|
37
38
|
"examples/app2/views/index.erb",
|
38
39
|
"examples/app2/views/layout.erb",
|
@@ -49,8 +50,8 @@ Gem::Specification.new do |s|
|
|
49
50
|
s.test_files = [
|
50
51
|
"test/test_helper.rb",
|
51
52
|
"test/sinatra_static_assets_test.rb",
|
52
|
-
"examples/app2/
|
53
|
-
"examples/app1/
|
53
|
+
"examples/app2/app2.rb",
|
54
|
+
"examples/app1/app1.rb"
|
54
55
|
]
|
55
56
|
|
56
57
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbzyl-sinatra-static-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "W\xC5\x82odek Bzyl"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- README.markdown
|
38
38
|
- Rakefile
|
39
39
|
- VERSION.yml
|
40
|
-
- examples/app1/
|
40
|
+
- examples/app1/app1.rb
|
41
41
|
- examples/app1/config.ru
|
42
42
|
- examples/app1/public/images/tatry1.jpg
|
43
43
|
- examples/app1/public/javascripts/app1.js
|
@@ -46,11 +46,12 @@ files:
|
|
46
46
|
- examples/app1/tmp/always_restart.txt
|
47
47
|
- examples/app1/views/index.erb
|
48
48
|
- examples/app1/views/layout.erb
|
49
|
-
- examples/app2/
|
49
|
+
- examples/app2/app2.rb
|
50
50
|
- examples/app2/config.ru
|
51
51
|
- examples/app2/public/images/tatry2.jpg
|
52
52
|
- examples/app2/public/javascripts/app2.js
|
53
|
-
- examples/app2/public/stylesheets/
|
53
|
+
- examples/app2/public/stylesheets/app2.css
|
54
|
+
- examples/app2/public/stylesheets/src/skating.png
|
54
55
|
- examples/app2/tmp/always_restart.txt
|
55
56
|
- examples/app2/views/index.erb
|
56
57
|
- examples/app2/views/layout.erb
|
@@ -87,5 +88,5 @@ summary: Sinatra extension providing helper methods to output tags for static as
|
|
87
88
|
test_files:
|
88
89
|
- test/test_helper.rb
|
89
90
|
- test/sinatra_static_assets_test.rb
|
90
|
-
- examples/app2/
|
91
|
-
- examples/app1/
|
91
|
+
- examples/app2/app2.rb
|
92
|
+
- examples/app1/app1.rb
|
Binary file
|