sinatra-static-assets 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-static-assets.gemspec
4
+ gemspec
@@ -1,4 +1,4 @@
1
- \# Sinatra Extension: StaticAssets
1
+ # Sinatra Extension: StaticAssets
2
2
 
3
3
  Gem *sinatra-static-assets* implements the following helpers methods:
4
4
 
@@ -11,8 +11,8 @@ To install it, run:
11
11
 
12
12
  sudo gem install sinatra-static-assets -s http://gemcutter.org
13
13
 
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.
14
+ All these methods are simple wrappers around the `uri` method
15
+ from the [sinatra](http://github.com/sinatra/sinatra) gem.
16
16
 
17
17
  ## When will you need it?
18
18
 
@@ -23,12 +23,12 @@ sub URI.
23
23
 
24
24
  Example: Suppose that we already have a virtual host `hitch.local`
25
25
  and two Sinatra applications that live in
26
- `/home/me/www/summer` and `/home/me/www/winter`
26
+ `/home/me/www/summer` and `/home/me/www/winter`
27
27
  directories, respectively.
28
- We want our Sinatra applications to be accessible from
29
- the following sub URI:
28
+ We want our Sinatra applications to be accessible from
29
+ the following sub URI:
30
30
 
31
- http://hitch.local/summer
31
+ http://hitch.local/summer
32
32
 
33
33
  and
34
34
 
@@ -40,7 +40,7 @@ we need to create a new configuration file with the following content:
40
40
  <VirtualHost *:80>
41
41
  ServerName hitch.local
42
42
  DocumentRoot /srv/www/hitch.local
43
-
43
+
44
44
  RackBaseURI /summer
45
45
  RackBaseURI /winter
46
46
  </VirtualHost>
@@ -50,7 +50,7 @@ and a link to the applications directories in `/srv/www/hitch.local`:
50
50
  ln -s /home/me/www/summer/public /srv/www/hitch.local/summer
51
51
  ln -s /home/me/www/winter/public /srv/www/hitch.local/winter
52
52
 
53
- After restarting an Apache2 server and visiting, for example, the first
53
+ After restarting an Apache2 server and visiting, for example, the first
54
54
  application at `http://hitch.local/summer` we see that links to
55
55
  images, stylesheets and javascripts are broken.
56
56
 
@@ -60,7 +60,7 @@ images/stylesheets/javascripts with absolute URI:
60
60
  /images/tatry1.jpg /stylesheets/app.css /javascripts/app.js
61
61
 
62
62
  That setup **works** whenever we are running applications locally.
63
- The absolute URI above tells a browser to request images
63
+ The absolute URI above tells a browser to request images
64
64
  (stylesheets and javascripts) from:
65
65
 
66
66
  http://localhost:4567/images/tatry1.jpg
@@ -80,57 +80,55 @@ As a result the images are at:
80
80
 
81
81
  http://hitch.local/summer/images/tatry1.jpg
82
82
 
83
- but we request them from:
83
+ but we request them from:
84
84
 
85
85
  http://hitch.local/images/tatry1.jpg
86
86
 
87
- And this **does not work** because there is no application
87
+ And this **does not work** because there is no application
88
88
  dispatched to *images* sub URI.
89
89
 
90
- The recommended way to deal with an absolute URI
90
+ The recommended way to deal with an absolute URI
91
91
  is to use a helper method that automatically converts
92
92
  `/images/tatry1.jpg` to `/summer/images/tatry1.jpg`
93
- for application dispatched to `/summer` sub URI.
93
+ for application dispatched to `/summer` sub URI.
94
94
 
95
- In the above example you can simply remove the `<img>`
96
- HTML tag and replace it with a Ruby inline code 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:
97
97
 
98
98
  <%= image_tag("/images/tatry1.jpg", :alt => "Błyszcz, 2159 m") %>
99
99
 
100
- See also, [How to fix broken images/CSS/JavaScript URIs in sub-URI
100
+ See also, [How to fix broken images/CSS/JavaScript URIs in sub-URI
101
101
  deployments](http://www.modrails.com/documentation/Users%20guide%20Apache.html#sub_uri_deployment_uri_fix)
102
102
 
103
103
  ## Usage examples
104
104
 
105
- In HTML `<link>` and `<img>` tags have no end tag.
105
+ In HTML (and HTML5) `<link>` and `<img>` tags have no end tag.
106
106
  In XHTML, on the contrary, these tags must be properly closed.
107
107
 
108
108
  We can choose the appropriate behaviour with *closed* option:
109
109
 
110
110
  image_tag "/images/tatry1.jpg", :alt => "Błyszcz, 2159 m", :closed => true
111
111
 
112
- The default value of *closed* option is `false`.
112
+ The default value of *closed* option is `false`. We can change the default value with:
113
+
114
+ enable :xhtml
115
+
116
+ We can pass mutliple stylesheets or scripts:
113
117
 
114
118
  stylesheet_link_tag "/stylesheets/screen.css", "/stylesheets/summer.css", :media => "projection"
115
119
  javascript_script_tag "/javascripts/jquery.js", "/javascripts/summer.js", :charset => "iso-8859-2"
116
120
  link_to "Tatry Mountains Rescue Team", "/topr"
117
121
 
118
- In order to use include the following in a Sinatra application:
122
+ In order to use include the following in a Sinatra application:
119
123
 
120
- gem 'sinatra-static-assets'
121
124
  require 'sinatra/static_assets'
122
125
 
123
126
  Or, if subclassing `Sinatra::Base`, include helpers manually:
124
127
 
125
- gem 'emk-sinatra-url-for'
126
- require 'sinatra/url_for'
127
-
128
- gem 'sinatra-static-assets'
129
128
  require 'sinatra/static_assets'
130
-
129
+
131
130
  class Summer < Sinatra::Base
132
- helpers Sinatra::UrlForHelper
133
- helpers Sinatra::StaticAssets
131
+ register Sinatra::StaticAssets
134
132
  # ...
135
133
  end
136
134
 
@@ -151,11 +149,11 @@ dispatches these applications to `/summer` and `/winter` sub URI:
151
149
 
152
150
  $LOAD_PATH.unshift('rwinter')
153
151
  require 'winter'
154
-
152
+
155
153
  map '/summer' do
156
154
  run Sinatra::Summer.new
157
155
  end
158
-
156
+
159
157
  map '/winter' do
160
158
  run Sinatra::Winter.new
161
159
  end
@@ -182,10 +180,10 @@ Next, create directories required by Passenger:
182
180
  and, finally, copy `config.ru` into `/srv/www/hitch.local` and
183
181
  update `LOAD_PATH` in the copied file.
184
182
 
185
- With everything in place, after restarting Apache2,
183
+ With everything in place, after restarting Apache2,
186
184
  the applications are accessible from the
187
185
 
188
- http://hitch.local/summer
186
+ http://hitch.local/summer
189
187
 
190
188
  and
191
189
 
@@ -197,9 +195,9 @@ respectively.
197
195
 
198
196
  1\. The `examples` directory contains *summer* and *winter* applications.
199
197
 
200
- 2\. In order to create a virual host add the following to */etc/hosts/*:
198
+ 2\. In order to create a virual host add the following to */etc/hosts/*:
201
199
 
202
200
  127.0.0.1 localhost.localdomain localhost hitch.local
203
201
 
204
- or, read [editing /etc/hosts is waste of my
202
+ or, read [editing /etc/hosts is waste of my
205
203
  time](http://www.taylorluk.com/articles/2009/08/12/hey-pac-man-sup-subdomains).
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -1,4 +1,4 @@
1
- require 'summer'
1
+ require './summer'
2
2
 
3
3
  use Rack::ShowExceptions
4
4
  use Rack::Lint
@@ -1,18 +1,15 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'sinatra/base'
4
-
5
- gem 'sinatra-static-assets'
6
4
  require 'sinatra/static_assets'
7
5
 
8
6
  module Sinatra
9
7
  class Summer < Sinatra::Base
10
- helpers Sinatra::UrlForHelper
11
- helpers Sinatra::StaticAssets
12
-
8
+ register Sinatra::StaticAssets
9
+
13
10
  set :app_file, __FILE__
14
- set :static, true
15
-
11
+ set :static, true
12
+
16
13
  get '/?' do
17
14
  @title = "Tatra Mountains, Błyszcz (2159 m)"
18
15
  erb :index
@@ -7,12 +7,11 @@ require 'sinatra/static_assets'
7
7
 
8
8
  module Sinatra
9
9
  class Winter < Sinatra::Base
10
- helpers Sinatra::UrlForHelper
11
- helpers Sinatra::StaticAssets
12
-
10
+ register Sinatra::StaticAssets
11
+
13
12
  set :app_file, __FILE__
14
- set :static, true
15
-
13
+ set :static, true
14
+
16
15
  get '/?' do
17
16
  @title = "Tatra Mountains, Dolina Gąsienicowa (1500 m)"
18
17
  erb :index
@@ -1,4 +1,4 @@
1
- require 'summer'
1
+ require './summer'
2
2
 
3
3
  use Rack::ShowExceptions
4
4
  run Sinatra::Application
@@ -1,8 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'sinatra'
4
-
5
- gem 'sinatra-static-assets'
6
4
  require 'sinatra/static_assets'
7
5
 
8
6
  get "/?" do
@@ -1,4 +1,4 @@
1
- require 'winter'
1
+ require './winter'
2
2
 
3
3
  use Rack::ShowExceptions
4
4
  run Sinatra::Application
@@ -3,7 +3,6 @@
3
3
  require 'rubygems'
4
4
  require 'sinatra'
5
5
 
6
- gem 'sinatra-static-assets'
7
6
  require 'sinatra/static_assets'
8
7
 
9
8
  get "/?" do
@@ -1,5 +1,4 @@
1
1
  require 'sinatra/base'
2
- require 'sinatra/url_for'
3
2
 
4
3
  module Sinatra
5
4
  module StaticAssets
@@ -28,6 +27,8 @@ module Sinatra
28
27
  list.collect { |source| javascript_tag(source, options) }.join("\n")
29
28
  end
30
29
 
30
+ alias :javascript_include_tag :javascript_script_tag
31
+
31
32
  def link_to(desc, url, options = {})
32
33
  tag("a", options.merge(:href => url_for(url))) do
33
34
  desc
@@ -36,6 +37,10 @@ module Sinatra
36
37
 
37
38
  private
38
39
 
40
+ def url_for(addr, absolute = false)
41
+ uri(addr, absolute == :full ? true : false, true)
42
+ end
43
+
39
44
  def tag(name, local_options = {})
40
45
  start_tag = "<#{name}#{tag_options(local_options) if local_options}"
41
46
  if block_given?
@@ -49,7 +54,8 @@ module Sinatra
49
54
  def tag_options(options)
50
55
  unless options.empty?
51
56
  attrs = []
52
- attrs = options.map { |key, value| %(#{key}="#{Rack::Utils.escape_html(value)}") }
57
+ #attrs = options.map { |key, value| %(#{key}="#{Rack::Utils.escape_html(value)}") }
58
+ attrs = options.map { |key, value| %(#{key}="#{value}") }
53
59
  " #{attrs.sort * ' '}" unless attrs.empty?
54
60
  end
55
61
  end
@@ -68,7 +74,7 @@ module Sinatra
68
74
 
69
75
  def extract_options(a)
70
76
  opts = a.last.is_a?(::Hash) ? a.pop : {}
71
- [a, opts]
77
+ [a, opts]
72
78
  end
73
79
 
74
80
  end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module StaticAssets
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sinatra-static-assets"
7
+ s.version = "1.0.0"
8
+ s.authors = ["Włodek Bzyl"]
9
+ s.email = ["matwb@ug.edu.pl"]
10
+ s.homepage = ""
11
+ s.summary = %q{A Sinatra extension.}
12
+ s.description = %q{This Sinatra extensions provides following helper methods:
13
+ - image_tag
14
+ - stylesheet_link_tag
15
+ - javascript_script_tag}
16
+
17
+ s.add_runtime_dependency 'sinatra', '>= 1.1.0'
18
+
19
+ s.add_development_dependency 'rack'
20
+ s.add_development_dependency 'rack-test'
21
+
22
+ s.rubyforge_project = "sinatra-static-assets"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
26
+ s.require_paths = ["lib"]
27
+ end
@@ -4,7 +4,6 @@ $:.unshift(path) unless $:.include?(path)
4
4
  require 'rubygems'
5
5
 
6
6
  require 'sinatra'
7
- require 'sinatra/url_for'
8
7
  require 'sinatra/static_assets'
9
8
 
10
9
  get "/url_for" do
@@ -8,11 +8,10 @@ require 'sinatra/static_assets'
8
8
 
9
9
  module Sinatra
10
10
  class XHTML < Sinatra::Base
11
- helpers Sinatra::UrlForHelper
12
11
  register Sinatra::StaticAssets
13
12
 
14
13
  enable :xhtml
15
-
14
+
16
15
  get '/image_tag' do
17
16
  content_type "text/plain"
18
17
  "#{image_tag("/images/foo.jpg")}"
@@ -1,4 +1,4 @@
1
- require 'sinatra_app'
1
+ require './test/sinatra_app'
2
2
  require 'test/unit'
3
3
  require 'rack/test'
4
4
 
@@ -20,7 +20,7 @@ class SintraStaticAssetsTest < Test::Unit::TestCase
20
20
  http://example.org/bar/foo
21
21
  EOD
22
22
  end
23
-
23
+
24
24
  def test_image_tag_returns_sub_uri
25
25
  get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
26
26
  assert last_response.ok?
@@ -37,7 +37,7 @@ EOD
37
37
  <link charset="utf-8" href="/bar/stylesheets/summer.css" media="projection" rel="stylesheet" type="text/css">
38
38
  EOD
39
39
  end
40
-
40
+
41
41
  def test_javascript_script_tag_returns_sub_uri
42
42
  get '/javascript_script_tag', {}, 'SCRIPT_NAME' => '/bar'
43
43
  assert last_response.ok?
@@ -45,7 +45,7 @@ EOD
45
45
  <script charset="iso-8859-2" src="/bar/javascripts/summer.js" type="text/javascript"></script>
46
46
  EOD
47
47
  end
48
-
48
+
49
49
  def test_link_to_tag_returns_sub_uri
50
50
  get '/link_to_tag', {}, 'SCRIPT_NAME' => '/bar'
51
51
  assert last_response.ok?
@@ -53,5 +53,5 @@ EOD
53
53
  <a href="/bar/topr">Tatry Mountains Rescue Team</a>
54
54
  EOD
55
55
  end
56
-
56
+
57
57
  end
@@ -1,4 +1,4 @@
1
- require 'sinatra_baseapp'
1
+ require './test/sinatra_baseapp'
2
2
  require 'test/unit'
3
3
  require 'rack/test'
4
4
 
@@ -6,9 +6,9 @@ class SintraStaticAssetsXHTMLTest < Test::Unit::TestCase
6
6
  include Rack::Test::Methods
7
7
 
8
8
  def app
9
- Sinatra::XHTML.new
9
+ Sinatra::XHTML.new
10
10
  end
11
-
11
+
12
12
  def test_image_tag_closes
13
13
  get '/image_tag'
14
14
  assert last_response.ok?
@@ -21,5 +21,5 @@ class SintraStaticAssetsXHTMLTest < Test::Unit::TestCase
21
21
  assert_equal last_response.body,
22
22
  "<link charset=\"utf-8\" href=\"/stylesheets/winter.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\"/>"
23
23
  end
24
-
24
+
25
25
  end
metadata CHANGED
@@ -1,73 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra-static-assets
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
- - Wlodek Bzyl
7
+ authors:
8
+ - Włodek Bzyl
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-11-23 00:00:00 +01:00
12
+ date: 2011-07-10 00:00:00.000000000 +02:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.0.0
24
- version:
25
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
26
16
  name: sinatra
17
+ requirement: &21435680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.0
27
23
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.9.1
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: emk-sinatra-url-for
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.2.1
44
- version:
45
- - !ruby/object:Gem::Dependency
24
+ prerelease: false
25
+ version_requirements: *21435680
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ requirement: &21435280 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *21435280
37
+ - !ruby/object:Gem::Dependency
46
38
  name: rack-test
39
+ requirement: &21434720 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
47
45
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 0.3.0
54
- version:
55
- description: |
56
- This Sinatra extensions provides following helper methods:
57
- - image_tag
58
- - stylesheet_link_tag
59
- - javascript_script_tag
60
-
61
- email: matwb@univ.gda.pl
46
+ prerelease: false
47
+ version_requirements: *21434720
48
+ description: ! "This Sinatra extensions provides following helper methods:\n -
49
+ image_tag\n - stylesheet_link_tag\n - javascript_script_tag"
50
+ email:
51
+ - matwb@ug.edu.pl
62
52
  executables: []
63
-
64
53
  extensions: []
65
-
66
- extra_rdoc_files:
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
67
58
  - LICENSE
68
- - README.markdown
69
- files:
70
- - VERSION.yml
59
+ - README.md
60
+ - Rakefile
71
61
  - examples/rconfig.ru
72
62
  - examples/rsummer/config.ru
73
63
  - examples/rsummer/public/images/tatry1.jpg
@@ -107,46 +97,35 @@ files:
107
97
  - examples/winter/views/layout.erb
108
98
  - examples/winter/winter.rb
109
99
  - lib/sinatra/static_assets.rb
100
+ - lib/sinatra/version.rb
101
+ - sinatra-static-assets.gemspec
110
102
  - test/sinatra_app.rb
111
103
  - test/sinatra_baseapp.rb
112
104
  - test/sinatra_static_assets_test.rb
113
105
  - test/sinatra_static_assets_xhtml_test.rb
114
- - LICENSE
115
- - README.markdown
116
106
  has_rdoc: true
117
- homepage: http://github.com/wbzyl/sinatra-static-assets
107
+ homepage: ''
118
108
  licenses: []
119
-
120
109
  post_install_message:
121
- rdoc_options:
122
- - --charset=UTF-8
123
- require_paths:
110
+ rdoc_options: []
111
+ require_paths:
124
112
  - lib
125
- required_ruby_version: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: "0"
130
- version:
131
- required_rubygems_version: !ruby/object:Gem::Requirement
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- version: "0"
136
- version:
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
137
125
  requirements: []
138
-
139
126
  rubyforge_project: sinatra-static-assets
140
- rubygems_version: 1.3.5
127
+ rubygems_version: 1.6.2
141
128
  signing_key:
142
129
  specification_version: 3
143
- summary: Sinatra extension providing helper methods to output tags for static assetgemspec.
144
- test_files:
145
- - test/sinatra_static_assets_xhtml_test.rb
146
- - test/sinatra_app.rb
147
- - test/sinatra_static_assets_test.rb
148
- - test/sinatra_baseapp.rb
149
- - examples/summer/summer.rb
150
- - examples/rwinter/winter.rb
151
- - examples/winter/winter.rb
152
- - examples/rsummer/summer.rb
130
+ summary: A Sinatra extension.
131
+ test_files: []
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 0
3
- :minor: 5
4
- :patch: 0
5
- :build: