padrino-assets 0.2.2 → 0.3.0
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/.gitignore +6 -4
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +10 -0
- data/CHANGELOG.md +11 -8
- data/Gemfile +1 -1
- data/LICENSE +18 -18
- data/README.md +126 -64
- data/Rakefile +30 -7
- data/lib/padrino-assets.rb +154 -91
- data/lib/padrino-assets/helpers.rb +445 -379
- data/lib/padrino-assets/version.rb +5 -4
- data/lib/tasks/cleanup.rake +8 -7
- data/lib/tasks/clobber.rake +7 -6
- data/lib/tasks/compress.rake +14 -13
- data/lib/tasks/precompile.rake +32 -29
- data/padrino-assets.gemspec +25 -24
- data/spec/assets_spec.rb +61 -0
- data/spec/fixtures/assets/application.css +11 -0
- data/spec/fixtures/assets/application.js +1 -0
- data/spec/fixtures/assets/pony.jpg +0 -0
- data/spec/fixtures/compiled_assets/application-b8588c6975a4539fbf2c11471870bdca.css +11 -0
- data/spec/fixtures/compiled_assets/manifest.json +1 -0
- data/spec/helpers_spec.rb +293 -0
- data/spec/spec.rb +37 -0
- data/spec/tasks_spec.rb +114 -0
- metadata +39 -21
- data/examples/nginx.md +0 -11
- data/test/test.rb +0 -52
- data/test/test_helpers.rb +0 -339
data/lib/tasks/cleanup.rake
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
manifest.
|
|
7
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
namespace :assets do
|
|
3
|
+
desc 'Removes backups for existing assets'
|
|
4
|
+
task :cleanup, :quanity do |task, args|
|
|
5
|
+
quanity = args['quanity'] || 2
|
|
6
|
+
manifest = Padrino::Assets.manifest
|
|
7
|
+
manifest.cleanup(quanity)
|
|
8
|
+
end
|
|
8
9
|
end
|
data/lib/tasks/clobber.rake
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
manifest.
|
|
6
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
namespace :assets do
|
|
3
|
+
desc 'Deletes all compiled assets'
|
|
4
|
+
task :clobber do
|
|
5
|
+
manifest = Padrino::Assets.manifest
|
|
6
|
+
manifest.clobber
|
|
7
|
+
end
|
|
7
8
|
end
|
data/lib/tasks/compress.rake
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
namespace :assets do
|
|
3
|
+
desc 'Compresses all compiled assets'
|
|
4
|
+
task :compress do
|
|
5
|
+
environment = Padrino::Assets.environment
|
|
6
|
+
manifest = Padrino::Assets.manifest
|
|
7
|
+
|
|
8
|
+
manifest.assets.each do |asset, digested_asset|
|
|
9
|
+
if asset = environment[asset]
|
|
10
|
+
compressed_asset = File.join(manifest.dir, digested_asset)
|
|
11
|
+
asset.write_to(compressed_asset + '.gz') if compressed_asset =~ /\.(?:css|html|js|svg|txt|xml)$/
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
14
15
|
end
|
data/lib/tasks/precompile.rake
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
apps
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
namespace :assets do
|
|
3
|
+
desc 'Compiles all assets'
|
|
4
|
+
task :precompile do
|
|
5
|
+
environment = Padrino::Assets.environment
|
|
6
|
+
manifest = Padrino::Assets.manifest
|
|
7
|
+
apps = Padrino.mounted_apps
|
|
8
|
+
apps.each do |app|
|
|
9
|
+
app = app.app_obj
|
|
10
|
+
|
|
11
|
+
next unless app.extensions.include?(Padrino::Assets)
|
|
12
|
+
|
|
13
|
+
app.precompile_assets.each do |path|
|
|
14
|
+
environment.each_logical_path.each do |logical_path|
|
|
15
|
+
case path
|
|
16
|
+
when Regexp
|
|
17
|
+
next unless path.match(logical_path)
|
|
18
|
+
when Proc
|
|
19
|
+
next unless path.call(logical_path)
|
|
20
|
+
else
|
|
21
|
+
next unless File.fnmatch(path.to_s, logical_path)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
manifest.compile(logical_path)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if app.compress_assets?
|
|
29
|
+
Rake::Task['assets:compress'].invoke
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
30
33
|
end
|
data/padrino-assets.gemspec
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
-
require 'padrino-assets/version'
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |s|
|
|
6
|
-
s.name = 'padrino-assets'
|
|
7
|
-
s.version = Padrino::Assets::VERSION
|
|
8
|
-
s.authors = ['Benjamin Bloch']
|
|
9
|
-
s.email = ['cirex@gamesol.org']
|
|
10
|
-
s.homepage = 'https://github.com/Cirex/padrino-assets'
|
|
11
|
-
s.description = 'A plugin for the Padrino web framework which uses Sprockets to manage and compile assets'
|
|
12
|
-
s.summary = s.description
|
|
13
|
-
|
|
14
|
-
s.files = `git ls-files`.split("\n")
|
|
15
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
-
s.require_paths = ['lib']
|
|
18
|
-
|
|
19
|
-
s.add_dependency 'sprockets', '~> 2.3.0'
|
|
20
|
-
s.add_dependency 'padrino-core'
|
|
21
|
-
s.add_dependency 'padrino-helpers'
|
|
22
|
-
|
|
23
|
-
s.add_development_dependency '
|
|
24
|
-
s.add_development_dependency '
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
+
require 'padrino-assets/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = 'padrino-assets'
|
|
7
|
+
s.version = Padrino::Assets::VERSION
|
|
8
|
+
s.authors = ['Benjamin Bloch']
|
|
9
|
+
s.email = ['cirex@gamesol.org']
|
|
10
|
+
s.homepage = 'https://github.com/Cirex/padrino-assets'
|
|
11
|
+
s.description = 'A plugin for the Padrino web framework which uses Sprockets to manage and compile assets'
|
|
12
|
+
s.summary = s.description
|
|
13
|
+
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
s.require_paths = ['lib']
|
|
18
|
+
|
|
19
|
+
s.add_dependency 'sprockets', '~> 2.3.0'
|
|
20
|
+
s.add_dependency 'padrino-core'
|
|
21
|
+
s.add_dependency 'padrino-helpers'
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency 'rake'
|
|
24
|
+
s.add_development_dependency 'rspec', '>= 2.0.0'
|
|
25
|
+
s.add_development_dependency 'rspec-html-matchers'
|
|
25
26
|
end
|
data/spec/assets_spec.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require_relative 'spec'
|
|
2
|
+
|
|
3
|
+
class TestCompressor; end
|
|
4
|
+
class AnotherCompressor; end
|
|
5
|
+
|
|
6
|
+
describe Padrino::Assets do
|
|
7
|
+
before do
|
|
8
|
+
app.set :css_compressor, nil
|
|
9
|
+
app.set :js_compressor, nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'can append paths to the Sprockets environment' do
|
|
13
|
+
Padrino::Assets.load_paths << my_path = File.dirname(__FILE__) + '/fixtures/paths_test'
|
|
14
|
+
|
|
15
|
+
Padrino.after_load.each(&:call)
|
|
16
|
+
Padrino.clear!
|
|
17
|
+
|
|
18
|
+
environment.paths.should include(my_path)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'can register a css compressor for use' do
|
|
22
|
+
Padrino::Assets.register_compressor :css, :test => 'TestCompressor'
|
|
23
|
+
Padrino::Assets.compressors[:css][:test].should == 'TestCompressor'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'can register a js compressor for use' do
|
|
27
|
+
Padrino::Assets.register_compressor :js, :another => 'AnotherCompressor'
|
|
28
|
+
Padrino::Assets.compressors[:js][:another].should == 'AnotherCompressor'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context '#find_registered_compressor' do
|
|
32
|
+
before { Padrino::Assets.compressors.clear }
|
|
33
|
+
|
|
34
|
+
it 'should allow you to manually locate a js compressor object' do
|
|
35
|
+
Padrino::Assets.register_compressor :js, :test => 'TestCompressor'
|
|
36
|
+
Padrino::Assets.register_compressor :js, :another => 'AnotherCompressor'
|
|
37
|
+
|
|
38
|
+
compressor = Padrino::Assets.find_registered_compressor(:js, :test)
|
|
39
|
+
compressor.class.should == TestCompressor
|
|
40
|
+
|
|
41
|
+
compressor = Padrino::Assets.find_registered_compressor(:js, :another)
|
|
42
|
+
compressor.class.should == AnotherCompressor
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'should allow you to manually locate a css compressor object' do
|
|
46
|
+
Padrino::Assets.register_compressor :css, :test => 'TestCompressor'
|
|
47
|
+
Padrino::Assets.register_compressor :css, :another => 'AnotherCompressor'
|
|
48
|
+
|
|
49
|
+
compressor = Padrino::Assets.find_registered_compressor(:css, :test)
|
|
50
|
+
compressor.class.should == TestCompressor
|
|
51
|
+
|
|
52
|
+
compressor = Padrino::Assets.find_registered_compressor(:css, :another)
|
|
53
|
+
compressor.class.should == AnotherCompressor
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should return nil when no compressor object is found' do
|
|
57
|
+
compressor = Padrino::Assets.find_registered_compressor(:css, :simple)
|
|
58
|
+
compressor.should be_nil
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alert('Hello World');
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"files":{"application-b8588c6975a4539fbf2c11471870bdca.css":{"logical_path":"application.css","mtime":"2012-02-13T05:18:43-05:00","digest":"b8588c6975a4539fbf2c11471870bdca"}},"assets":{"application.css":"application-b8588c6975a4539fbf2c11471870bdca.css"}}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
require_relative 'spec'
|
|
2
|
+
|
|
3
|
+
describe Padrino::Assets::Helpers do
|
|
4
|
+
include Padrino::Helpers::OutputHelpers
|
|
5
|
+
include Padrino::Helpers::TagHelpers
|
|
6
|
+
include Padrino::Assets::Helpers
|
|
7
|
+
|
|
8
|
+
context '#assets_path' do
|
|
9
|
+
before do
|
|
10
|
+
Padrino.after_load.each(&:call)
|
|
11
|
+
Padrino.clear!
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should prepend :assets_host when present' do
|
|
15
|
+
app.set :assets_host, 'http://www.test.com'
|
|
16
|
+
asset = asset_path('application.css')
|
|
17
|
+
asset.should == 'http://www.test.com/assets/application.css'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should allow :assets_host to use a Proc' do
|
|
21
|
+
app.set :assets_host, ->(asset, request) { 'http://test.com' }
|
|
22
|
+
asset = asset_path('application.css')
|
|
23
|
+
asset.should == 'http://test.com/assets/application.css'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'should pass the current source to :assets_host when a Proc is used' do
|
|
27
|
+
app.set :assets_host, ->(asset, request) do
|
|
28
|
+
if asset =~ /application.css/
|
|
29
|
+
'http://true.com'
|
|
30
|
+
else
|
|
31
|
+
'http://false.com'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
asset = asset_path('application.css')
|
|
35
|
+
asset.should == 'http://true.com/assets/application.css'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should pass the current request to :assets_host when a Proc is used' do
|
|
39
|
+
app.set :assets_host, ->(asset, request) do
|
|
40
|
+
if request.ssl?
|
|
41
|
+
'https://test.com'
|
|
42
|
+
else
|
|
43
|
+
'http://test.com'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
asset = asset_path('application.css')
|
|
47
|
+
asset.should == 'http://test.com/assets/application.css'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'should append extension when provided' do
|
|
51
|
+
asset = asset_path(:application, :css)
|
|
52
|
+
asset.should == '/assets/application.css'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'should not append extension when one is present' do
|
|
56
|
+
asset = asset_path('application.css', :css)
|
|
57
|
+
asset.should_not == '/assets/application.css.css'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'should prepend :assets_prefix when present' do
|
|
61
|
+
app.set :assets_prefix, '/test'
|
|
62
|
+
asset = asset_path('application.css')
|
|
63
|
+
asset.should == '/test/application.css'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should prepend a forward slash to :assets_prefix when missing' do
|
|
67
|
+
app.set :assets_prefix, 'test'
|
|
68
|
+
asset = asset_path('application.css')
|
|
69
|
+
asset.should == '/test/application.css'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'should not interfere with a reference URI' do
|
|
73
|
+
asset = asset_path('/application.css')
|
|
74
|
+
asset.should == '/application.css'
|
|
75
|
+
|
|
76
|
+
asset = asset_path('//test.com/application.css')
|
|
77
|
+
asset.should == '//test.com/application.css'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'should not interfere with an absolute URI' do
|
|
81
|
+
asset = asset_path('http://test.com/application.css')
|
|
82
|
+
asset.should == 'http://test.com/application.css'
|
|
83
|
+
|
|
84
|
+
asset = asset_path('https://test.com/application.css')
|
|
85
|
+
asset.should == 'https://test.com/application.css'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'should use precompiled asset when assets are indexed' do
|
|
89
|
+
app.enable :index_assets
|
|
90
|
+
asset = asset_path('application.css')
|
|
91
|
+
asset.should == '/assets/application-b8588c6975a4539fbf2c11471870bdca.css'
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should allow assets that have not been precompiled when assets are index' do
|
|
95
|
+
app.enable :index_assets
|
|
96
|
+
asset = asset_path('application.js')
|
|
97
|
+
asset.should == '/assets/application.js'
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context '#is_uri?' do
|
|
102
|
+
it 'should return true when given an absolute URI' do
|
|
103
|
+
is_uri?('https://example.com/application.css').should be_true
|
|
104
|
+
is_uri?('http://example.com/application.css').should be_true
|
|
105
|
+
is_uri?('ftp://example.com/application.css').should be_true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'should return true when given a reference URI' do
|
|
109
|
+
is_uri?('//example.com/assets/application.css').should be_true
|
|
110
|
+
is_uri?('/assets/application.css').should be_true
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'should return false when given a host without a protocol' do
|
|
114
|
+
is_uri?('example.com/assets/application.css').should be_false
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'should return false when given an asset' do
|
|
118
|
+
is_uri?('application.css').should be_false
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context '#stylesheet' do
|
|
123
|
+
it 'should accept multiple sources' do
|
|
124
|
+
stylesheets = stylesheets(:application, :theme)
|
|
125
|
+
stylesheets.should have_tag(:link, count: 1, with: { href: '/assets/application.css' })
|
|
126
|
+
stylesheets.should have_tag(:link, count: 1, with: { href: '/assets/theme.css' })
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'should accept multiple sources with attributes' do
|
|
130
|
+
stylesheets = stylesheets(:application, :theme, media: 'handheld')
|
|
131
|
+
stylesheets.should have_tag(:link, count: 1, with: { href: '/assets/application.css', media: 'handheld' })
|
|
132
|
+
stylesheets.should have_tag(:link, count: 1, with: { href: '/assets/theme.css', media: 'handheld' })
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'should accept a single source' do
|
|
136
|
+
stylesheet = stylesheet(:application)
|
|
137
|
+
stylesheet.should have_tag(:link, count: 1, with: { href: '/assets/application.css' })
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'should accept a single source with attributes' do
|
|
141
|
+
stylesheet = stylesheet(:application, media: 'handheld')
|
|
142
|
+
stylesheet.should have_tag(:link, count: 1, with: { href: '/assets/application.css', media: 'handheld' })
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'should be aliased for compatibility' do
|
|
146
|
+
respond_to?(:stylesheet_link_tag).should be_true
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context '#javascript' do
|
|
151
|
+
it 'should accept multiple sources' do
|
|
152
|
+
javascripts = javascripts(:application, :jquery)
|
|
153
|
+
javascripts.should have_tag(:script, count: 1, with: { src: '/assets/application.js' })
|
|
154
|
+
javascripts.should have_tag(:script, count: 1, with: { src: '/assets/jquery.js' })
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it 'should accept a single source' do
|
|
158
|
+
javascripts = javascript(:application)
|
|
159
|
+
javascripts.should have_tag(:script, count: 1, with: { src: '/assets/application.js' })
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'should be aliased for compatibility' do
|
|
163
|
+
respond_to?(:javascript_include_tag).should be_true
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
context '#image' do
|
|
168
|
+
it 'should accept multiple sources' do
|
|
169
|
+
images = images('application.jpg', 'application.png')
|
|
170
|
+
images.should have_tag(:img, count: 1, with: { src: '/assets/application.jpg' })
|
|
171
|
+
images.should have_tag(:img, count: 1, with: { src: '/assets/application.png' })
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'should accept multiple sources with attributes' do
|
|
175
|
+
images = images('application.jpg', 'application.png', width: 40, height: 40)
|
|
176
|
+
images.should have_tag(:img, count: 1, with: { src: '/assets/application.jpg', width: 40, height: 40 })
|
|
177
|
+
images.should have_tag(:img, count: 1, with: { src: '/assets/application.png', width: 40, height: 40 })
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'should accept a single source' do
|
|
181
|
+
image = image('application.jpg')
|
|
182
|
+
image.should have_tag(:img, count: 1, with: { src: '/assets/application.jpg' })
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'should accept a single source with attributes' do
|
|
186
|
+
image = image('application.jpg', width: 40, height: 40)
|
|
187
|
+
image.should have_tag(:img, count: 1, with: { src: '/assets/application.jpg', width: 40, height: 40 })
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'should allow you to set the :width and :height with :size' do
|
|
191
|
+
image = image('application.jpg', size: '40x40')
|
|
192
|
+
image.should have_tag(:img, with: { width: 40, height: 40 })
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it 'should allow you to use an array with :size' do
|
|
196
|
+
image = image('application.jpg', size: [40, 40])
|
|
197
|
+
image.should have_tag(:img, with: { width: 40, height: 40 })
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it 'should automatically set an alternate text when none present' do
|
|
201
|
+
images = images('application.jpg', 'test.jpg')
|
|
202
|
+
images.should have_tag(:img, with: { alt: 'Application' })
|
|
203
|
+
images.should have_tag(:img, with: { alt: 'Test' })
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it 'should allow you to manually set the alternate text' do
|
|
207
|
+
image = image('application.jpg', alt: 'My Little Pony')
|
|
208
|
+
image.should have_tag(:img, with: { alt: 'My Little Pony' })
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'should be aliased for compatibility' do
|
|
212
|
+
respond_to?(:image_tag).should be_true
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
context '#alternate_text' do
|
|
217
|
+
it 'should capitalize the first letter' do
|
|
218
|
+
alternate_text = alternate_text('application.jpg')
|
|
219
|
+
alternate_text.should == 'Application'
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it 'should seperate underscores' do
|
|
223
|
+
alternate_text = alternate_text('my_pony.jpg')
|
|
224
|
+
alternate_text.should == 'My pony'
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context '#video' do
|
|
229
|
+
it 'should accept multiple sources' do
|
|
230
|
+
videos = videos('test.webm', 'test.mov')
|
|
231
|
+
videos.should have_tag(:video, count: 1) do
|
|
232
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.webm' })
|
|
233
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.mov' })
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'should accept multiple sources with attributes' do
|
|
238
|
+
videos = videos('test.webm', 'test.mov', width: 40, height: 40)
|
|
239
|
+
videos.should have_tag(:video, count: 1, with: { width: 40, height: 40 }) do
|
|
240
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.webm' })
|
|
241
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.mov' })
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'should accept a single source' do
|
|
246
|
+
video = video('test.webm')
|
|
247
|
+
video.should have_tag(:video, count: 1, with: { src: '/assets/test.webm' })
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'should accept a single source with attributes' do
|
|
251
|
+
video = video('test.webm', width: 40, height: 40)
|
|
252
|
+
video.should have_tag(:video, count: 1, with: { src: '/assets/test.webm', width: 40, height: 40 })
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it 'should allow you to set the :width and :height with :size' do
|
|
256
|
+
video = video('test.webm', size: '40x40')
|
|
257
|
+
video.should have_tag(:video, with: { width: 40, height: 40 })
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
it 'should allow you to use an array with :size' do
|
|
261
|
+
video = video('test.webm', size: [40, 40])
|
|
262
|
+
video.should have_tag(:video, with: { width: 40, height: 40 })
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
context '#audio' do
|
|
267
|
+
it 'should accept multiple sources' do
|
|
268
|
+
audios = audios('test.ogg', 'test.aac')
|
|
269
|
+
audios.should have_tag(:audio, count: 1) do
|
|
270
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.ogg' })
|
|
271
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.aac' })
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it 'should accept multiple sources with attributes' do
|
|
276
|
+
audios = audios('test.ogg', 'test.aac', id: 'audio')
|
|
277
|
+
audios.should have_tag(:audio, count: 1, with: { id: 'audio' }) do
|
|
278
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.ogg' })
|
|
279
|
+
with_tag(:source, count: 1, with: { src: '/assets/test.aac' })
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
it 'should accept a single source' do
|
|
284
|
+
audio = audio('test.ogg')
|
|
285
|
+
audio.should have_tag(:audio, count: 1, with: { src: '/assets/test.ogg' })
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it 'should accept a single source with attributes' do
|
|
289
|
+
audio = audio('test.ogg', id: 'audio')
|
|
290
|
+
audio.should have_tag(:audio, count: 1, with: { src: '/assets/test.ogg', id: 'audio' })
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|