padrino-assets 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,13 +30,13 @@ end
30
30
 
31
31
  By default, Sprockets is configured to load assets from your project's `app/assets` and `lib/assets` directories. Any files stored in these directories are readily available to the included helpers and will be served by the Sprockets middleware.
32
32
 
33
- The following directories are no longer used and will instead be served statically:
33
+ Because of this the following directories are no longer used and will instead be served statically:
34
34
 
35
35
  * `public/images`
36
36
  * `public/stylesheets`
37
37
  * `public/javascripts`
38
38
 
39
- Because of this you should now be storing your assets in the following directories:
39
+ You should now be storing your assets in the following directories:
40
40
 
41
41
  * `app/assets/images`
42
42
  * `app/assets/stylesheets`
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require 'bundler/gem_tasks'
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.test_files = FileList['test/**/test_*.rb']
6
+ test.verbose = true
7
+ end
@@ -35,8 +35,8 @@
35
35
  tag(:link, options.reverse_merge(href: asset_path(source, :css)))
36
36
  end.join("\n")
37
37
  end
38
- alias_method :include_stylesheets, :include_stylesheet
39
- alias_method :stylesheet_include_tag, :include_stylesheet
38
+ alias_method :include_stylesheets, :include_stylesheet
39
+ alias_method :stylesheet_link_tag, :include_stylesheet
40
40
 
41
41
  ##
42
42
  # Returns an HTML script tag for the specified sources
@@ -298,9 +298,11 @@
298
298
  # @since 0.1.0
299
299
  # @api public
300
300
  def is_uri?(source)
301
- !!(source =~ %r(^[a-z]+://|^//?))
301
+ !!(source =~ URI_REGEXP)
302
302
  end
303
303
 
304
+ URI_REGEXP = %r[^[a-z]+://|^//?]
305
+
304
306
  ##
305
307
  # Returns a modified asset source based on the current application settings
306
308
  #
@@ -1,5 +1,5 @@
1
1
  module Padrino
2
2
  module Assets
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ['lib']
18
18
 
19
19
  s.add_dependency 'sprockets', '~> 2.3.0'
20
-
21
20
  s.add_dependency 'padrino-core'
22
21
  s.add_dependency 'padrino-helpers'
22
+
23
+ s.add_development_dependency 'minitest'
24
+ s.add_development_dependency 'webrat'
23
25
  end
@@ -0,0 +1,52 @@
1
+ require 'webrat'
2
+ require 'padrino-assets'
3
+ require 'minitest/pride'
4
+ require 'minitest/autorun'
5
+
6
+ Padrino::Assets.load_paths << File.dirname(__FILE__) + '/fixtures/assets/**'
7
+
8
+ module MiniTest
9
+ class Spec
10
+ class << self
11
+ alias_method :context, :describe
12
+ end
13
+
14
+ def app
15
+ @app ||= Sinatra.new(Padrino::Application) do
16
+ register Padrino::Assets
17
+ set :environment, :test
18
+ end
19
+ end
20
+
21
+ def settings
22
+ app.settings
23
+ end
24
+
25
+ def request
26
+ nil
27
+ end
28
+ end
29
+
30
+ module Assertions
31
+ include Webrat::Matchers
32
+
33
+ def assert_has_tag(tag, html, attributes)
34
+ selector = HaveSelector.new(tag, attributes)
35
+ assert selector.matches?(html), selector.failure_message
36
+ end
37
+
38
+ def refute_has_tag(tag, html, attributes)
39
+ selector = HaveSelector.new(tag, attributes)
40
+ refute selector.matches?(html), selector.failure_message
41
+ end
42
+ end
43
+
44
+ module Expectations
45
+ infect_an_assertion :assert_has_tag, :must_have_tag
46
+ infect_an_assertion :refute_has_tag, :wont_have_tag
47
+ end
48
+ end
49
+
50
+ class Object
51
+ include MiniTest::Expectations
52
+ end
@@ -0,0 +1,200 @@
1
+ require_relative 'test'
2
+
3
+ describe 'Helpers' do
4
+ include Padrino::Helpers::OutputHelpers
5
+ include Padrino::Helpers::TagHelpers
6
+ include Padrino::Assets::Helpers
7
+
8
+ describe 'assets_path' do
9
+ it 'should prepend :assets_host when present' do
10
+ app.set :assets_host, 'http://www.test.com'
11
+ asset = asset_path('application.css')
12
+ asset.must_equal 'http://www.test.com/assets/application.css'
13
+ end
14
+
15
+ it 'should allow :assets_host to use a Proc' do
16
+ app.set :assets_host, ->(asset, request) { 'http://test.com' }
17
+ asset = asset_path('application.css')
18
+ asset.must_equal 'http://test.com/assets/application.css'
19
+ end
20
+
21
+ it 'should pass the current source to :assets_host when a Proc is used' do
22
+ app.set :assets_host, ->(source, request) do
23
+ if source =~ /application.css/
24
+ 'http://true.com'
25
+ else
26
+ 'http://false.com'
27
+ end
28
+ end
29
+ asset = asset_path('application.css')
30
+ asset.must_equal 'http://true.com/assets/application.css'
31
+ end
32
+
33
+ it 'should append extension when provided' do
34
+ asset = asset_path(:application, :css)
35
+ asset.must_equal '/assets/application.css'
36
+ end
37
+
38
+ it 'should not append extension when one is present' do
39
+ asset = asset_path('application.css', :css)
40
+ asset.wont_equal '/assets/application.css.css'
41
+ end
42
+
43
+ it 'should prepend :assets_prefix when present' do
44
+ app.set :assets_prefix, '/test'
45
+ asset = asset_path('application.css')
46
+ asset.must_equal '/test/application.css'
47
+ end
48
+
49
+ it 'should prepend a forward slash to :assets_prefix when missing' do
50
+ app.set :assets_prefix, 'test'
51
+ asset = asset_path('application.css')
52
+ asset.must_equal '/test/application.css'
53
+ end
54
+
55
+ it 'should not interfere with a direct URI' do
56
+ asset = asset_path('/application.css')
57
+ asset.must_equal '/application.css'
58
+
59
+ asset = asset_path('//test.com/application.css')
60
+ asset.must_equal '//test.com/application.css'
61
+
62
+ asset = asset_path('http://test.com/application.css')
63
+ asset.must_equal 'http://test.com/application.css'
64
+ end
65
+ end
66
+
67
+ describe 'is_uri?' do
68
+ it 'should return true when given an absolute URI' do
69
+ is_uri?('https://example.com/application.css').must_equal true
70
+ is_uri?('http://example.com/application.css').must_equal true
71
+ is_uri?('ftp://example.com/application.css').must_equal true
72
+ end
73
+
74
+ it 'should return true when given a reference URI' do
75
+ is_uri?('//example.com/assets/application.css').must_equal true
76
+ is_uri?('/assets/application.css').must_equal true
77
+ end
78
+
79
+ it 'should return false when given a host without a protocol' do
80
+ is_uri?('example.com/assets/application.css').must_equal false
81
+ end
82
+
83
+ it 'should return false when given an asset' do
84
+ is_uri?('application.css').must_equal false
85
+ end
86
+ end
87
+
88
+ describe 'include_stylesheet' do
89
+ it 'should accept multiple sources' do
90
+ stylesheets = include_stylesheets :application, :theme
91
+ stylesheets.must_have_tag :link, href: '/assets/application.css'
92
+ stylesheets.must_have_tag :link, href: '/assets/theme.css'
93
+ end
94
+
95
+ it 'should accept multiple sources with attributes' do
96
+ stylesheets = include_stylesheets :application, :theme, media: 'handheld'
97
+ stylesheets.must_have_tag :link, href: '/assets/application.css', media: 'handheld'
98
+ stylesheets.must_have_tag :link, href: '/assets/theme.css', media: 'handheld'
99
+ end
100
+
101
+ it 'should accept a single source' do
102
+ stylesheet = include_stylesheet :application
103
+ stylesheet.must_have_tag :link, href: '/assets/application.css'
104
+ end
105
+
106
+ it 'should accept a single source with attributes' do
107
+ stylesheet = include_stylesheet :application, media: 'handheld'
108
+ stylesheet.must_have_tag :link, href: '/assets/application.css', media: 'handheld'
109
+ end
110
+
111
+ it 'should allow a source with an extension' do
112
+ stylesheet = include_stylesheet 'application.css'
113
+ stylesheet.wont_have_tag :link, hreg: '/assets/application.css.css'
114
+ end
115
+
116
+ it 'should be aliased for compatibility' do
117
+ respond_to?(:stylesheet_link_tag).must_equal true
118
+ end
119
+ end
120
+
121
+ describe 'include_javascript' do
122
+ it 'should accept multiple sources' do
123
+ javascripts = include_javascripts :application, :jquery
124
+ javascripts.must_have_tag :script, src: '/assets/application.js'
125
+ javascripts.must_have_tag :script, src: '/assets/jquery.js'
126
+ end
127
+
128
+ it 'should accept a single source' do
129
+ javascripts = include_javascript :application
130
+ javascripts.must_have_tag :script, src: '/assets/application.js'
131
+ end
132
+
133
+ it 'should be aliased for compatibility' do
134
+ respond_to?(:javascript_include_tag).must_equal true
135
+ end
136
+ end
137
+
138
+ describe 'image' do
139
+ it 'should accept multiple sources' do
140
+ images = images 'application.jpg', 'application.png'
141
+ images.must_have_tag :img, src: '/assets/application.jpg'
142
+ images.must_have_tag :img, src: '/assets/application.png'
143
+ end
144
+
145
+ it 'should accept multiple sources with attributes' do
146
+ images = images 'application.jpg', 'application.png', width: '40', height: '40'
147
+ images.must_have_tag :img, src: '/assets/application.jpg', width: '40', height: '40'
148
+ images.must_have_tag :img, src: '/assets/application.png', width: '40', height: '40'
149
+ end
150
+
151
+ it 'should accept a single source' do
152
+ image = image 'application.jpg'
153
+ image.must_have_tag :img, src: '/assets/application.jpg'
154
+ end
155
+
156
+ it 'should accept a single source with attributes' do
157
+ image = image 'application.jpg', width: '40', height: '40'
158
+ image.must_have_tag :img, width: '40', height: '40'
159
+ end
160
+
161
+ it 'should allow you to set the width and height with size' do
162
+ image = image 'application.jpg', size: '40x40'
163
+ image.must_have_tag :img, width: '40', height: '40'
164
+ end
165
+
166
+ it 'should allow you to set the width' do
167
+ image = image 'application.jpg', width: '40'
168
+ image.must_have_tag :img, width: '40'
169
+ end
170
+
171
+ it 'should allow you to set the height' do
172
+ image = image 'application.jpg', height: '40'
173
+ image.must_have_tag :img, height: '40'
174
+ end
175
+
176
+ it 'should allow you to set the alternate text' do
177
+ image = image 'application.jpg', alt: 'My Little Pony'
178
+ image.must_have_tag :img, alt: 'My Little Pony'
179
+ end
180
+
181
+ it 'should automatically set an alternate text when none present' do
182
+ image = image 'application.jpg'
183
+ image.must_have_tag :img, alt: 'application'
184
+ end
185
+
186
+ it 'should allow you to set the class' do
187
+ image = image 'application.jpg', class: 'image'
188
+ image.must_have_tag :img, class: 'image'
189
+ end
190
+
191
+ it 'should allow you to set the identifier' do
192
+ image = image 'application.jpg', id: 'logo'
193
+ image.must_have_tag :img, id: 'logo'
194
+ end
195
+
196
+ it 'should be aliased for compatibility' do
197
+ respond_to?(:image_tag).must_equal true
198
+ end
199
+ end
200
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-17 00:00:00.000000000Z
12
+ date: 2012-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &9246510 !ruby/object:Gem::Requirement
16
+ requirement: &8090840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9246510
24
+ version_requirements: *8090840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: padrino-core
27
- requirement: &9246250 !ruby/object:Gem::Requirement
27
+ requirement: &8090580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9246250
35
+ version_requirements: *8090580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: padrino-helpers
38
- requirement: &9245990 !ruby/object:Gem::Requirement
38
+ requirement: &8090300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,29 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9245990
46
+ version_requirements: *8090300
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: &8090060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *8090060
58
+ - !ruby/object:Gem::Dependency
59
+ name: webrat
60
+ requirement: &8089830 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *8089830
47
69
  description: A plugin for the Padrino web framework which uses Sprockets to manage
48
70
  and compile assets
49
71
  email:
@@ -67,6 +89,8 @@ files:
67
89
  - lib/tasks/compress.rake
68
90
  - lib/tasks/precompile.rake
69
91
  - padrino-assets.gemspec
92
+ - test/test.rb
93
+ - test/test_helpers.rb
70
94
  homepage: https://github.com/Cirex/padrino-assets
71
95
  licenses: []
72
96
  post_install_message:
@@ -92,5 +116,7 @@ signing_key:
92
116
  specification_version: 3
93
117
  summary: A plugin for the Padrino web framework which uses Sprockets to manage and
94
118
  compile assets
95
- test_files: []
119
+ test_files:
120
+ - test/test.rb
121
+ - test/test_helpers.rb
96
122
  has_rdoc: