wbzyl-sinatra-static-assets 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem *sinatra-static-assets* implements the following helpers methods:
4
4
 
5
+ * `image_tag`
5
6
  * `stylesheet_link_tag`
6
7
  * `javascript_script_tag`
7
- * `image_tag`
8
8
  * `link_tag`
9
9
 
10
- To install it, run from the command line:
10
+ To install it, run:
11
11
 
12
12
  sudo gem install wbzyl-sinatra-static-assets -s http://gems.github.com
13
13
 
14
- All methods are simple wrappers around the `url_for` method
15
- from the [sinatra-url-for](http://github.com/emk/sinatra-url-for/).
14
+ All these methods are simple wrappers around the `url_for` method
15
+ from the [sinatra-url-for](http://github.com/emk/sinatra-url-for/) gem.
16
16
 
17
17
  ## When will you need it?
18
18
 
@@ -21,15 +21,21 @@ Whenever you use the
21
21
  or use `Rack::URLMap` to dispatch an application to
22
22
  sub URI.
23
23
 
24
- Suppose that we already have a virtual host `hitch.local`
25
- and two Sinatra application which live in
24
+ Example: Suppose that we already have a virtual host `hitch.local`
25
+ and two Sinatra applications that live in
26
26
  `/home/me/www/summer` and `/home/me/www/winter`
27
27
  directories, respectively.
28
- We want our Sinatra applications to be accessible from the URLs:
29
- `http://hitch.local/summer` and `http://hitch.local/winter`.
28
+ We want our Sinatra applications to be accessible from
29
+ the following sub URI:
30
+
31
+ http://hitch.local/summer
32
+
33
+ and
34
+
35
+ http://hitch.local/winter
30
36
 
31
37
  To configure Apache2 and Passenger to serve our applications
32
- we create a new configuration file with the content:
38
+ we need to create a new configuration file with the following content:
33
39
 
34
40
  <VirtualHost *:80>
35
41
  ServerName hitch.local
@@ -39,52 +45,55 @@ we create a new configuration file with the content:
39
45
  RackBaseURI /winter
40
46
  </VirtualHost>
41
47
 
42
- and link the applications directories in `/srv/www/hitch.local`:
48
+ and a link to the applications directories in `/srv/www/hitch.local`:
43
49
 
44
50
  ln -s /home/me/www/summer/public /srv/www/hitch.local/summer
45
51
  ln -s /home/me/www/winter/public /srv/www/hitch.local/winter
46
52
 
47
- After restarting the Apache2 server and visiting, for example the
48
- first application at `http://hitch.local/summer` we see that links to
53
+ After restarting an Apache2 server and visiting, for example, the first
54
+ application at `http://hitch.local/summer` we see that links to
49
55
  images, stylesheets and javascripts are broken.
50
56
 
51
- The hitch here is that in Sinatra apps we usually refer to
57
+ The hitch here is that in Sinatra applications we usually refer to
52
58
  images/stylesheets/javascripts with absolute URI:
53
59
 
54
60
  /images/tatry1.jpg /stylesheets/app.css /javascripts/app.js
55
61
 
56
62
  That setup **works** whenever we are running applications locally.
57
- The absolute URI above tells browser to load images
63
+ The absolute URI above tells a browser to request images
58
64
  (stylesheets and javascripts) from:
59
65
 
60
66
  http://localhost:4567/images/tatry1.jpg
61
67
 
62
- which in turn refer to:
68
+ which in turn, tells a server to send a file:
63
69
 
64
70
  /home/me/www/summer/public/images/tatry1.jpg
65
71
 
66
- And this is the **correct** directory with the default setup of Sinatra
67
- application.
72
+ The `public` directory is the default directory where static files
73
+ should be served from.
74
+ So, the `/images/tatry1.jpg` picture will be there and will be served
75
+ unless we had changed that default directory.
68
76
 
69
- But these absolute URIs do not work whenever, for example,
70
- the *summer* application is dispatched to sub URI.
71
- Now, images are at:
77
+ But these absolute URIs do not work when, for example,
78
+ the *summer* application is dispatched to `/summer` sub URI.
79
+ As a result the images are at:
72
80
 
73
81
  http://hitch.local/summer/images/tatry1.jpg
74
82
 
75
- but we request images from:
83
+ but we request them from:
76
84
 
77
85
  http://hitch.local/images/tatry1.jpg
78
86
 
79
- And this **does not work** beacause there is no application
87
+ And this **does not work** because there is no application
80
88
  dispatched to *images* sub URI.
81
89
 
82
- The recommended way to cope with broken links is to use helper
83
- methods which automatically take of *prepending*
84
- the *RackBaseURI* that we have dispatched application to.
90
+ The recommended way to deal with an absolute URI
91
+ is to use a helper method that automatically converts
92
+ `/images/tatry1.jpg` to `/summer/images/tatry1.jpg`
93
+ for application dispatched to `/summer` sub URI.
85
94
 
86
- In the above example you would simply remove the `<img>` HTML tag
87
- and replace it with inline Ruby like this:
95
+ In the above example you can simply remove the `<img>`
96
+ HTML tag and replace it with a Ruby inline code like this:
88
97
 
89
98
  <%= image_tag("/images/tatry1.jpg", :alt => "Błyszcz, 2159 m") %>
90
99
 
@@ -93,15 +102,41 @@ deployments](http://www.modrails.com/documentation/Users%20guide%20Apache.html#s
93
102
 
94
103
  ## Usage examples
95
104
 
96
- To use, include it in a Sinatra application:
105
+ In HTML `<link>` and `<img>` tags have no end tag.
106
+ In XHTML, on the contrary, these tags must be properly closed.
107
+
108
+ We can choose the appropriate behaviour with *closed* option:
109
+
110
+ image_tag "/images/tatry1.jpg", :alt => "Błyszcz, 2159 m", :closed => true
111
+
112
+ The default value of *closed* option is `false`.
113
+
114
+ stylesheet_link_tag "/stylesheets/screen.css", "/stylesheets/summer.css", :media => "projection"
115
+ javascript_script_tag "/javascripts/jquery.js", "/javascripts/summer.js", :charset => "iso-8859-2"
116
+ link_to "Tatry Mountains Rescue Team", "/topr"
117
+
118
+ In order to use include the following in a Sinatra application:
119
+
120
+ gem 'wbzyl-sinatra-static-assets'
121
+ require 'sinatra/static_assets'
122
+
123
+ Or, if subclassing `Sinatra::Base`, include helpers manually:
97
124
 
98
- require 'rubygems'
99
125
  gem 'wbzyl-sinatra-static-assets'
100
126
  require 'sinatra/static_assets'
127
+
128
+ class Summer < Sinatra::Base
129
+ helpers Sinatra::StaticAssets
130
+ # ...
131
+ end
101
132
 
102
133
 
103
134
  ## Miscellaneous stuff
104
135
 
105
- [UNIX] To create virual host, add to */etc/hosts*:
136
+ 1. The `examples` directory contains *summer* and *winter* applications.
137
+
138
+ 2. In order to create a virual host add the following to */etc/hosts/*:
106
139
 
107
140
  127.0.0.1 localhost.localdomain localhost hitch.local
141
+
142
+ 3. TODO: write tests
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 9
4
+ :patch: 10
@@ -9,3 +9,8 @@ get "/?" do
9
9
  @title = "Tatra Mountains, Błyszcz (2159 m)"
10
10
  erb :index
11
11
  end
12
+
13
+ get "/:page" do
14
+ @title = "#{params[:page]}"
15
+ erb :"#{params[:page]}"
16
+ end
@@ -1,3 +1,6 @@
1
1
  <h2><%= @title %></h2>
2
2
 
3
3
  <p><%= image_tag "/images/tatry1.jpg", :closed => true, :alt => @title, :title => @title %></p>
4
+
5
+ <p><a href="/winter">Tatra Mountain in Winter</a></p>
6
+ <p><%= link_to "Tatry Mountains Rescue Team", "/topr" %></p>
@@ -0,0 +1,5 @@
1
+ <h3>Tatry Mountains Rescue Team</h3>
2
+
3
+ <p>The home page: <a href="http://www.topr.pl/">TOPR</a></a>
4
+
5
+ <p>The emergency telephone: +48 601 100 300</p>
@@ -6,34 +6,21 @@ require 'sinatra/url_for'
6
6
 
7
7
  module Sinatra
8
8
  module StaticAssets
9
+ # In HTML <link> and <img> tags have no end tag.
10
+ # In XHTML, on the contrary, these tags must be properly closed.
9
11
  #
10
- # TODO
11
- #
12
- # option: doctype => html -> closed == false
13
- # option: doctype => xhtml -> closed == true
14
- #
15
- # In HTML the <img> tag has no end tag:
16
- #
17
- # image_tag "/images/foo.png", :alt => "Foo itself"
18
- #
19
- # In XHTML the <img /> tag must be properly closed:
12
+ # We can choose the appropriate behaviour with +closed+ option:
20
13
  #
21
14
  # image_tag "/images/foo.png", :alt => "Foo itself", :closed => true
22
15
  #
16
+ # The default value of +closed+ option is +false+.
17
+ #
23
18
  def image_tag(source, options = {})
24
19
  closed = options.delete(:closed)
25
20
  options[:src] = url_for(source)
26
21
  tag("img", options, closed)
27
22
  end
28
23
 
29
- # In HTML the <link> tag has no end tag:
30
- #
31
- # stylesheet_link_tag "/stylesheets/screen.css", "/stylesheets/print.css"
32
- #
33
- # In XHTML the <link> tag must be properly closed:
34
- #
35
- # stylesheet_link_tag "/stylesheets/screen.css", :closed => true
36
- #
37
24
  def stylesheet_link_tag(*sources)
38
25
  list, options = extract_options(sources)
39
26
  closed = options.delete(:closed)
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wlodek Bzyl
@@ -92,6 +92,7 @@ files:
92
92
  - examples/summer/tmp/always_restart.txt
93
93
  - examples/summer/views/index.erb
94
94
  - examples/summer/views/layout.erb
95
+ - examples/summer/views/topr.erb
95
96
  - examples/winter/app2.rb
96
97
  - examples/winter/config.ru
97
98
  - examples/winter/public/images/tatry2.jpg