sprockets-urlrewriter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/sprockets-urlrewriter.rb +2 -2
- data/lib/sprockets-urlrewriter/version.rb +1 -1
- data/spec/urlrewriter_spec.rb +26 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -8,9 +8,9 @@ Example usage
|
|
8
8
|
|
9
9
|
gem install sprockets-urlrewriter
|
10
10
|
|
11
|
-
In rails:
|
11
|
+
In rails, within your own initializer:
|
12
12
|
|
13
|
-
|
13
|
+
Rails.application.assets.register_preprocessor 'text/css', Sprockets::UrlRewriter
|
14
14
|
|
15
15
|
In config.ru (if you're using Sinatra)
|
16
16
|
|
@@ -13,10 +13,10 @@ module Sprockets
|
|
13
13
|
logical_path = context.instance_variable_get(:@logical_path)
|
14
14
|
|
15
15
|
rel = Pathname.new(logical_path).parent
|
16
|
-
data.gsub
|
16
|
+
data.gsub /:\s*url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/i do |url|
|
17
17
|
next url if URI.parse($1).absolute?
|
18
18
|
new_path = rel.join Pathname.new($1)
|
19
|
-
"url(#{new_path}#{$2})"
|
19
|
+
": url(#{new_path}#{$2})"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/spec/urlrewriter_spec.rb
CHANGED
@@ -15,6 +15,32 @@ describe 'UrlRewriter' do
|
|
15
15
|
@css = "body { background-url: url('http://example.com/bg.jpg?1232') }"
|
16
16
|
assert_equal @css, subject
|
17
17
|
end
|
18
|
+
|
19
|
+
it 'leaves SASS image-url helpers as is' do
|
20
|
+
@css = "body { background-url: image-url('image.png') }"
|
21
|
+
assert_equal @css, subject
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'leaves Rails image_url helpers as is' do
|
25
|
+
@css = "body { background-url: image_url('image.png') }"
|
26
|
+
assert_equal @css, subject
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'ignores case of url' do
|
30
|
+
@css = "body { background-url: URL('image.png') }"
|
31
|
+
assert_equal "body { background-url: url(/assets/css/image.png) }", subject
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'ignores whitespace between : and url' do
|
35
|
+
@css = "body { background-url: url('image.png') }"
|
36
|
+
assert_equal "body { background-url: url(/assets/css/image.png) }", subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'ignores newline between : and url' do
|
40
|
+
@css = "body { background-url:
|
41
|
+
url('image.png') }"
|
42
|
+
assert_equal "body { background-url: url(/assets/css/image.png) }", subject
|
43
|
+
end
|
18
44
|
end
|
19
45
|
|
20
46
|
class FakeContext
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-urlrewriter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70268489188320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70268489188320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70268489187780 !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: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70268489187780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sprockets
|
38
|
-
requirement: &
|
38
|
+
requirement: &70268489187280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70268489187280
|
47
47
|
description: ! ' Replaces all instances of url() in CSS files Sprockets concats, if
|
48
48
|
the url is relative. '
|
49
49
|
email:
|