sinatra-assets 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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kematzy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,77 @@
1
+ = Sinatra::Assets
2
+
3
+ Methods for working with assets like images, links etc.
4
+
5
+ == Getting Started
6
+
7
+ To start caching your app's ouput, just require and register
8
+ the extension in your sub-classed Sinatra app:
9
+
10
+ require 'sinatra/assets'
11
+
12
+ class YourApp < Sinatra::Base
13
+
14
+ register(Sinatra::Assets)
15
+
16
+ <snip...>
17
+
18
+ end
19
+
20
+
21
+ In your "classic" Sinatra app, you just require the extension and set some key settings, like this:
22
+
23
+ require 'rubygems'
24
+ require 'sinatra'
25
+ require 'sinatra/assets'
26
+
27
+ # NB! you need to set the root of the app first
28
+ set :root, '/path/2/the/root/of/your/app'
29
+ set :public, '/path/2/public'
30
+
31
+ <snip...>
32
+
33
+
34
+ See the method definitions for further information.
35
+
36
+ === Dependencies:
37
+
38
+ This extension depends on the following:
39
+
40
+ ==== Ruby Gems:
41
+
42
+ * alt/rext/hash/conversions
43
+ * Methods used:
44
+ * :to_html_attributes
45
+
46
+ ==== Extensions:
47
+
48
+ None
49
+
50
+ === Configurations:
51
+
52
+ None
53
+
54
+ === Routes:
55
+
56
+ None
57
+
58
+ === Code Inspirations:
59
+
60
+ * The Chicago gem by Thumble Monks
61
+ * The ActiveSupport gem by DHH & Rails Core Team
62
+ * sinatra-url-for by Eric Kidd
63
+
64
+
65
+ == Note on Patches/Pull Requests
66
+
67
+ * Fork the project.
68
+ * Make your feature addition or bug fix.
69
+ * Add tests for it. This is important so I don't break it in a
70
+ future version unintentionally.
71
+ * Commit, do not mess with rakefile, version, or history.
72
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
73
+ * Send me a pull request. Bonus points for topic branches.
74
+
75
+ == Copyright
76
+
77
+ Copyright (c) 2010 kematzy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,87 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sinatra-assets"
8
+ gem.summary = %Q{A Sinatra Extension that makes working with Assets easy.}
9
+ gem.description = %Q{A Sinatra Extension that makes working with Assets easy.}
10
+ gem.email = "kematzy@gmail.com"
11
+ gem.homepage = "http://github.com/kematzy/sinatra-assets"
12
+ gem.authors = ["kematzy"]
13
+ gem.add_development_dependency "rspec", ">= 1.3.0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_opts = ["--color", "--format", "nested", "--require", "spec/spec_helper.rb"]
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ namespace :spec do
36
+
37
+ desc "Run all specifications quietly"
38
+ Spec::Rake::SpecTask.new(:quiet) do |t|
39
+ t.libs << "lib"
40
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
41
+ end
42
+
43
+ desc "Run specific spec verbosely (SPEC=/path/2/file)"
44
+ Spec::Rake::SpecTask.new(:select) do |t|
45
+ t.libs << "lib"
46
+ t.spec_files = [ENV["SPEC"]]
47
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
48
+ end
49
+
50
+ end
51
+
52
+ task :spec => :check_dependencies
53
+
54
+ task :default => :spec
55
+
56
+ require 'rake/rdoctask'
57
+ Rake::RDocTask.new do |rdoc|
58
+ version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "Sinatra::Assets v#{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
65
+
66
+ desc 'Build the rdoc HTML Files'
67
+ task :docs do
68
+ version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
69
+
70
+ sh "sdoc -N --title 'Sinatra::Assets v#{version}' lib/ README.rdoc"
71
+ end
72
+
73
+ namespace :docs do
74
+
75
+ desc 'Remove rdoc products'
76
+ task :remove => [:clobber_rdoc]
77
+
78
+ desc 'Force a rebuild of the RDOC files'
79
+ task :rebuild => [:rerdoc]
80
+
81
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
82
+ task :open => [:docs] do
83
+ browser = ENV["BROWSER"] || "safari"
84
+ sh "open -a #{browser} doc/index.html"
85
+ end
86
+
87
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,301 @@
1
+
2
+ #--
3
+ # DEPENDENCIES
4
+ #++
5
+ # %w().each {|lib| require lib }
6
+ require 'sinatra/assets/core_ext.rb'
7
+
8
+ # #--
9
+ # ## SINATRA EXTENSIONS
10
+ # #++
11
+ # %w().each {|lib| require lib }
12
+
13
+
14
+ module Sinatra
15
+
16
+ # == Sinatra::Assets
17
+ #
18
+ # Methods for working with assets like images, links etc.
19
+ #
20
+ # === Usage:
21
+ #
22
+ # Just add the extension as a helper in your sub-classed Sinatra application.
23
+ #
24
+ # class YourApp < Sinatra::Base
25
+ #
26
+ # register( Sinatra::Assets )
27
+ # <snip...>
28
+ # end
29
+ #
30
+ # See the method definitions for further information.
31
+ #
32
+ # === Dependencies:
33
+ #
34
+ # This extension depends on the following:
35
+ #
36
+ # ==== Ruby Gems:
37
+ #
38
+ # * alt/rext/hash/conversions
39
+ # * Methods used:
40
+ # * :to_html_attributes
41
+ #
42
+ # ==== Extensions:
43
+ #
44
+ # None
45
+ #
46
+ # === Configurations:
47
+ #
48
+ # None
49
+ #
50
+ # === Routes:
51
+ #
52
+ # None
53
+ #
54
+ # === Code Inspirations:
55
+ #
56
+ # * The Chicago gem by Thumble Monks
57
+ # * The ActiveSupport gem by DHH & Rails Core Team
58
+ # * sinatra-url-for by Eric Kidd
59
+ #
60
+ module Assets
61
+
62
+ VERSION = '0.1.1' unless const_defined?(:VERSION)
63
+ def self.version; "Sinatra::Assets v#{VERSION}"; end
64
+
65
+
66
+ module Helpers
67
+
68
+ ##
69
+ # Construct a link to +url_fragment+, which should be given relative to
70
+ # the base of this Sinatra app.
71
+ #
72
+ # The mode should be either <code>:path_only</code>, which will generate an absolute path
73
+ # within the current domain (the default), or <code>:full</code>, which will include
74
+ # the site name and port number. (The latter is typically necessary for links in RSS feeds.)
75
+ #
76
+ # Code inspiration from [ http://github.com/emk/sinatra-url-for/ ] by Eric Kidd
77
+ #
78
+ # ==== Examples
79
+ #
80
+ # When <tt>request.script_name => ''</tt> => map '/' do...
81
+ #
82
+ # url_for() # Returns "/"
83
+ # url_for('') # Returns "/"
84
+ # url_for(nil) # Returns "/"
85
+ #
86
+ # url_for "/" # Returns "/"
87
+ # url_for("/", :root) # Returns "/" at the root of the app system
88
+ #
89
+ # url_for "path" # Returns "/path"
90
+ # url_for "/path" # Returns "/path"
91
+ #
92
+ # url_for "path", :full # Returns "http://example.com/path"
93
+ # url_for "/path", :full # Returns "http://example.com/path"
94
+ #
95
+ # This also work with apps that are mounted Rack apps:
96
+ #
97
+ # # config.ru
98
+ # map '/somepath' do
99
+ # run MyApp
100
+ # end
101
+ #
102
+ # url_for '/blog' => /somepath/blog
103
+ #
104
+ #
105
+ # <b>NB! '/urlmap' represents the URL Map path given by request.script_name</b>
106
+ #
107
+ # When <tt>request.script_name => '/urlmap'</tt> => map '/urlmap' do...
108
+ #
109
+ # url_for() # Returns "/urlmap/"
110
+ # url_for('') # Returns "/urlmap/"
111
+ # url_for(nil) # Returns "/urlmap/"
112
+ #
113
+ # url_for "/" # Returns "/urlmap/"
114
+ # url_for("/", :root) # Returns "/" at the root of the app system
115
+ #
116
+ # url_for "path" # Returns "/urlmap/path"
117
+ # url_for "/path" # Returns "/path"
118
+ #
119
+ # url_for "path", :full # Returns "http://example.com/urlmap/path"
120
+ # url_for "/path", :full # Returns "http://example.com/path"
121
+ #
122
+ # @api public
123
+ def url_for(path='/', url_params = {}, mode = nil)
124
+ mode, url_params = url_params, {} if url_params.is_a?(Symbol)
125
+
126
+ # Acceptable paths at this stage are:
127
+ # -- '' # empty string
128
+ # -- '/'
129
+ # -- '/path/2/something'
130
+ # -- 'path/2/something'
131
+
132
+ # ensure our path is present & correct
133
+ if path.nil?
134
+ warn "url_for() method given a nil value"
135
+ out_path = '/'
136
+
137
+ # do we have an empty string?
138
+ elsif (path.to_s == '' )
139
+ # this means we're looking to stay at root of our current app
140
+ out_path = request.script_name.empty? ? '/' : "#{request.script_name}/"
141
+
142
+ # do we have a starting slash ?
143
+ elsif (path.to_s[0,1] == '/')
144
+ # yes, we have. is it longer than 1 char (ie: not cleaned up nil value)
145
+ if path.length > 1
146
+ # root path, so ignore script_name
147
+ out_path = path
148
+ else
149
+ # no, short path, so are we
150
+ # -- having a script_name value
151
+ # -- having a mode identifier
152
+ out_path = request.script_name.empty? ? path : "#{request.script_name}#{path}"
153
+ end
154
+ else
155
+ # no, we are staying locally within our app
156
+ out_path = request.script_name.empty? ? "/#{path}" : "#{request.script_name}/#{path}"
157
+ end
158
+ case mode
159
+ when :full
160
+ port = (request.scheme =~ /https?/ && request.port.to_s =~ /(80|443)/) ? "" : ":#{request.port}"
161
+ base = "#{request.scheme}://#{request.host}#{port}#{request.script_name}"
162
+ when :root
163
+ base = '' # ignoring the script_name path
164
+ else
165
+ base = ''
166
+ end
167
+ "#{base}#{out_path}"
168
+ end
169
+
170
+ ##
171
+ # Return image tag to _path_.
172
+ #
173
+ # ==== Examples
174
+ #
175
+ # image 'foo.png'
176
+ # # => <img src="/images/foo.png" />
177
+ #
178
+ # image '/foo.png', :alt => 'Kung-foo'
179
+ # # => <img src="/foo.png" alt="Kung-foo">
180
+ #
181
+ # @api public
182
+ def image(source, attrs = {})
183
+ attrs[:src] = (source[0,1] == '/') ? url_for(source) : url_for("/images/#{source}")
184
+ attrs[:alt] ||= File.basename(source,'.*').split('.').first.to_s.capitalize
185
+ if size = attrs.delete(:size)
186
+ attrs[:width], attrs[:height] = size.split("x") if size =~ %r{^\d+%?x\d+%?$}
187
+ end
188
+ %Q[<img #{attrs.to_html_attributes}>]
189
+ end
190
+ alias_method :image_tag, :image
191
+
192
+ ##
193
+ # A basic link helper
194
+ #
195
+ # ==== Examples
196
+ #
197
+ # link_to('FAQs', '#faqs')
198
+ # => <a href="#faqs">FAQs/a>
199
+ #
200
+ # link_to('Apple', 'http://apple.com')
201
+ # => <a href="http://apple.com">Apple</a>
202
+ #
203
+ # link_to('Apple', 'http://apple.com', :title => 'go buy a new computer')
204
+ # => <a href="http://apple.com" title="go buy a new computer">Apple</a>
205
+ #
206
+ # @api public
207
+ def link_to(link_text, url, attrs={})
208
+ unless url[0,1] == '#' # tag
209
+ url = url_for(url) unless remote_asset?(url)
210
+ end
211
+
212
+ attrs = {:href => url }.merge(attrs)
213
+ %Q[<a #{attrs.to_html_attributes}>#{link_text}</a>]
214
+ end
215
+
216
+
217
+ ##
218
+ # Simple helper method that redirects the edit/new page Cancel button
219
+ # back to the previous page, or if no previous page, then back to URL given.
220
+ #
221
+ # ==== Examples
222
+ #
223
+ # redirect_back_or(url)
224
+ # =>
225
+ #
226
+ # @api public
227
+ def redirect_back_or(path = nil, do_redirect = false)
228
+
229
+ past = request.nil? ? nil : (request.env['HTTP_REFERER'] ||= nil)
230
+ path = past.nil? ? path : past.sub(host,'')
231
+ do_redirect ? redirect(path) : path
232
+ end
233
+ alias_method :redirect_back, :redirect_back_or
234
+
235
+ ##
236
+ # Convenience method for the full Host URL
237
+ #
238
+ # <b>NB!</b> The path must be returned without a trailing slash '/' or
239
+ # else the <tt>:redirect_back_or()</tt> method outputs the wrong paths
240
+ #
241
+ # ==== Examples
242
+ #
243
+ # <%= host %> => 'http://example.org'
244
+ #
245
+ # @api public
246
+ def host
247
+ port = (request.scheme =~ /https?/ && request.port.to_s =~ /(80|443)/) ? "" : ":#{request.port}"
248
+ "#{protocol}://#{request.env['SERVER_NAME']}#{port}"
249
+ # "#{protocol}://#{request.env['SERVER_NAME']}"
250
+ end
251
+ alias_method :server, :host
252
+
253
+ ##
254
+ # Convenience helper method that returns the URL protocol used
255
+ #
256
+ # ==== Examples
257
+ #
258
+ # <%= protocol %> => 'http'
259
+ #
260
+ # @api public
261
+ def protocol
262
+ request.env['rack.url_scheme']
263
+ end
264
+
265
+ protected
266
+
267
+ ##
268
+ # returns true/false based upon if the URL is prefixed by ' ://'
269
+ #
270
+ # ==== Examples
271
+ #
272
+ # url = url_for(url) unless remote_asset?(url)
273
+ #
274
+ # @api private
275
+ def remote_asset?(uri)
276
+ uri =~ %r[^\w+://.+]
277
+ end
278
+
279
+ end #/ Helpers
280
+
281
+ # add your general methods here
282
+
283
+
284
+ def self.registered(app)
285
+ app.helpers Assets::Helpers
286
+
287
+ ## add the extension specific options to those inspectable by :settings_inspect method
288
+ # provided by the Sinatra::Settings extension
289
+ # if app.respond_to?(:sinatra_settings_for_inspection)
290
+ # %w().each do |m|
291
+ # app.sinatra_settings_for_inspection << m
292
+ # end
293
+ # end
294
+
295
+ end #/ self.registered
296
+
297
+ end #/ Assets
298
+
299
+ # register(Sinatra::Assets)
300
+
301
+ end #/ Sinatra
@@ -0,0 +1,2 @@
1
+
2
+ require 'alt/rext/hash/conversions' unless Hash.new.respond_to?(:to_html_attributes)
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra-assets}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kematzy"]
12
+ s.date = %q{2010-08-10}
13
+ s.description = %q{A Sinatra Extension that makes working with Assets easy.}
14
+ s.email = %q{kematzy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/sinatra/assets.rb",
27
+ "lib/sinatra/assets/core_ext.rb",
28
+ "sinatra-assets.gemspec",
29
+ "spec/sinatra/assets_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/kematzy/sinatra-assets}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{A Sinatra Extension that makes working with Assets easy.}
37
+ s.test_files = [
38
+ "spec/sinatra/assets_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
53
+ end
54
+ end
55
+
@@ -0,0 +1,167 @@
1
+
2
+ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/spec_helper"
3
+
4
+ describe "Sinatra" do
5
+
6
+ describe "Assets" do
7
+
8
+ class MyTestApp
9
+ register(Sinatra::Assets)
10
+ end
11
+
12
+ describe "VERSION" do
13
+
14
+ it "should return the VERSION string" do
15
+ Sinatra::Assets::VERSION.should be_a_kind_of(String)
16
+ Sinatra::Assets::VERSION.should match(/\d\.\d+\.\d+(\.\d)?/)
17
+ end
18
+
19
+ end #/ VERSION
20
+
21
+ describe "#self.version" do
22
+
23
+ it "should return a string with the version number" do
24
+ Sinatra::Assets.version.should match(/Sinatra::Assets v\d\.\d\.\d/)
25
+ end
26
+
27
+ end #/ #self.version
28
+
29
+ describe "Helpers" do
30
+
31
+ describe "#url_for" do
32
+
33
+ it "should return a '/' without args" do
34
+ erb_app '<%= url_for() %>'
35
+ body.should == '/'
36
+ end
37
+
38
+ it "should return a '/' with an empty string" do
39
+ erb_app '<%= url_for('') %>'
40
+ body.should == '/'
41
+ end
42
+
43
+ it "should return a '/' when given nil" do
44
+ erb_app '<%= url_for(nil) %>'
45
+ body.should == '/'
46
+ end
47
+
48
+ it "should return a '/path' without args" do
49
+ erb_app '<%= url_for("/path") %>'
50
+ body.should == '/path'
51
+ end
52
+
53
+ it "should return a '/path' when given 'path' as args" do
54
+ erb_app '<%= url_for("path") %>'
55
+ body.should == '/path'
56
+ end
57
+
58
+ it "should return a '/path' when given a symbol as args" do
59
+ erb_app '<%= url_for(:path) %>'
60
+ body.should == '/path'
61
+ end
62
+
63
+ it "should return a full URL when given with the :full args" do
64
+ erb_app '<%= url_for("/admin", :full) %>'
65
+ body.should == "http://example.org/admin"
66
+ end
67
+
68
+ describe "with url_map" do
69
+
70
+ it "should have tests with url_map functionality from request.script_name "
71
+
72
+ # it "should description" do
73
+ # request = mock("request", :null_object => true)
74
+ # request.stub!(:script_name).and_return('/admin')
75
+ # request.script_name.should == '/admin'
76
+ # erb_app '<%= url_for("path") %>'
77
+ # body.should == '/admin/path'
78
+ # end
79
+
80
+ end #/ with url_map
81
+
82
+ end #/ #url_for
83
+
84
+ describe "#link_to" do
85
+
86
+ it "should handle a simple anchor tag" do
87
+ erb_app %Q{<%= link_to('Div1', '#div1') %>}
88
+ body.should have_tag('a[@href=#div1]', 'Div1')
89
+ end
90
+
91
+ it "should return a simple link without a defined title tag" do
92
+ erb_app %Q{<%= link_to("Link",'/link') %>}
93
+ body.should have_tag('a[@href=/link]', 'Link')
94
+ end
95
+
96
+ it "should return a link with title and class attributes" do
97
+ erb_app %Q{<%= link_to("Apple", 'http://www.apple.com/', :title => "Apple.com", :class => "link-external" ) %>}
98
+ body.should have_tag('a.link-external[@href=http://www.apple.com/]', 'Apple')
99
+ body.should have_tag('a.link-external[@title=Apple.com]')
100
+ end
101
+
102
+ it "should return an internal link with title and class attributes" do
103
+ erb_app %Q{<%= link_to("Login", '/login/', :title => "Login", :class => "btn span-8" ) %>}
104
+ # body.should have_tag(:debug)
105
+ body.should have_tag('a.btn[@href=/login/]', 'Login')
106
+ body.should have_tag('a.span-8[@title=Login]')
107
+ end
108
+
109
+ end #/ #link_to
110
+
111
+ describe "#image" do
112
+
113
+ it "should prepend '/images/ when the path is provided without a starting '/' " do
114
+ erb_app %Q{<%= image('foo.png') %>}
115
+
116
+ body.should have_tag('img[@src=/images/foo.png]')
117
+ body.should have_tag('img[@alt=Foo]')
118
+ end
119
+
120
+ it "should set path as absolute when first char in param is a '/' " do
121
+ erb_app %Q{<%= image('/foo.png') %>}
122
+
123
+ body.should have_tag('img[@src=/foo.png]')
124
+ body.should have_tag('img[@alt=Foo]')
125
+ end
126
+
127
+ it "should accept a hash of attributes" do
128
+ erb_app %Q{<%= image('foo.png', :alt => 'Kung-foo') %>}
129
+ body.should have_tag('img[@alt=Kung-foo]')
130
+ end
131
+
132
+ end
133
+
134
+ describe "#redirect_back_or" do
135
+
136
+ it "should redirect back" do
137
+ pending "how to construct this test ???"
138
+ erb_app "<%= redirect_back_or('/go') %>"
139
+ response.should == 'adfsa'
140
+ # body.should have_tag('debug')
141
+ end
142
+
143
+ end #/ #redirect_back_or
144
+
145
+ describe "#host" do
146
+
147
+ it "should return the host address without a trailing slash" do
148
+ erb_app "<%= host %>"
149
+ body.should == 'http://example.org'
150
+ end
151
+
152
+ end #/ #host
153
+
154
+ describe "#protocol" do
155
+
156
+ it "should return 'http' " do
157
+ erb_app "<%= protocol %>"
158
+ body.should == 'http'
159
+ end
160
+
161
+ end #/ #protocol
162
+
163
+ end #/ Helpers
164
+
165
+ end #/ Assets
166
+
167
+ end #/ Sinatra
@@ -0,0 +1,59 @@
1
+
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+
7
+ #--
8
+ # DEPENDENCIES
9
+ #++
10
+ %w(
11
+ sinatra/base
12
+ ).each {|lib| require lib }
13
+
14
+ #--
15
+ ## SINATRA EXTENSIONS
16
+ #++
17
+ %w(
18
+ sinatra/tests
19
+ sinatra/assets
20
+ ).each {|ext| require ext }
21
+
22
+
23
+ Spec::Runner.configure do |config|
24
+ config.include RspecHpricotMatchers
25
+ config.include Sinatra::Tests::TestCase
26
+ config.include Sinatra::Tests::RSpec::SharedSpecs
27
+ end
28
+
29
+
30
+ # quick convenience methods..
31
+
32
+ def fixtures_path
33
+ "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
34
+ end
35
+
36
+ def public_fixtures_path
37
+ "#{fixtures_path}/public"
38
+ end
39
+
40
+
41
+ class MyTestApp < Sinatra::Base
42
+
43
+ set :app_dir, "#{fixtures_path}/app"
44
+ set :public, "#{public_fixtures_path}"
45
+ # set :views, "#{fixtures_path}/app/views"
46
+ set :views, "#{app_dir}/views"
47
+
48
+ register(Sinatra::Tests)
49
+
50
+ enable :raise_errors
51
+
52
+ end #/class MyTestApp
53
+
54
+ def app ; MyTestApp; end
55
+
56
+
57
+ class Test::Unit::TestCase
58
+ Sinatra::Base.set :environment, :test
59
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-assets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - kematzy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-10 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A Sinatra Extension that makes working with Assets easy.
38
+ email: kematzy@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/sinatra/assets.rb
54
+ - lib/sinatra/assets/core_ext.rb
55
+ - sinatra-assets.gemspec
56
+ - spec/sinatra/assets_spec.rb
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/kematzy/sinatra-assets
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A Sinatra Extension that makes working with Assets easy.
92
+ test_files:
93
+ - spec/sinatra/assets_spec.rb
94
+ - spec/spec_helper.rb