sprockets-urlrewriter 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ *.swp
@@ -0,0 +1,3 @@
1
+ module SprocketsUrlRewriter
2
+ VERSION = "0.1.0"
3
+ end
@@ -4,14 +4,19 @@ require 'uri'
4
4
 
5
5
  module Sprockets
6
6
  class UrlRewriter < Processor
7
- VERSION = "0.0.3"
8
-
9
7
  def evaluate(context, locals)
10
- rel = Pathname.new(context.logical_path).parent
8
+ # FIXME: Accessing logical_path instance variable directly instead of
9
+ # using public method, since the public method incorrectly chops paths
10
+ # with periods in them: https://github.com/sstephenson/sprockets/pull/299
11
+ #
12
+ # logical_path = context.logical_path
13
+ logical_path = context.instance_variable_get(:@logical_path)
14
+
15
+ rel = Pathname.new(logical_path).parent
11
16
  data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
12
- return url if URI.parse($1).absolute?
13
- new_path = rel.join Pathname.new($1)
14
- "url(#{new_path})"
17
+ next url if URI.parse($1).absolute?
18
+ new_path = rel.join Pathname.new($1)
19
+ "url(#{new_path}#{$2})"
15
20
  end
16
21
  end
17
22
  end
@@ -2,16 +2,24 @@ require 'minitest/autorun'
2
2
  require './lib/sprockets-urlrewriter'
3
3
 
4
4
  describe 'UrlRewriter' do
5
- class FakeContext
6
- attr_accessor :logical_path
5
+ let(:context) { FakeContext.new "/assets/css/jada.css" }
6
+ let(:rewriter) { Sprockets::UrlRewriter.new { @css } }
7
+ subject { rewriter.evaluate context, {} }
8
+
9
+ it 'finds relatives urls and makes them absolute' do
10
+ @css = "body { background-url: url('bg.jpg?1232') }"
11
+ assert_equal "body { background-url: url(/assets/css/bg.jpg?1232) }", subject
12
+ end
13
+
14
+ it 'leaves absolute URLs as is' do
15
+ @css = "body { background-url: url('http://example.com/bg.jpg?1232') }"
16
+ assert_equal @css, subject
7
17
  end
18
+ end
8
19
 
9
- it 'finds relatives urls and makes them absolut' do
10
- ctx = FakeContext.new
11
- ctx.logical_path = "/assets/css/jada.css"
12
- css = "body { background-url: url('bg.jpg?1232') }"
13
- ur = Sprockets::UrlRewriter.new { css }
14
- result = ur.evaluate ctx, {}
15
- assert_equal "body { background-url: url(/assets/css/bg.jpg) }", result
20
+ class FakeContext
21
+ attr_accessor :logical_path
22
+ def initialize(lpath)
23
+ @logical_path = lpath
16
24
  end
17
25
  end
@@ -1,10 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "sprockets-urlrewriter"
3
+ require "sprockets-urlrewriter/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "sprockets-urlrewriter"
7
- s.version = Sprockets::UrlRewriter::VERSION
7
+ s.version = SprocketsUrlRewriter::VERSION
8
8
  s.authors = ["Carl Hoerberg"]
9
9
  s.email = ["carl.hoerberg@gmail.com"]
10
10
  s.homepage = "http://github.com/carlhoerberg/sprockets-urlrewriter"
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency "minitest"
22
+ s.add_development_dependency "rake"
22
23
  s.add_runtime_dependency "sprockets"
23
24
  end
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.0.3
4
+ version: 0.1.0
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-31 00:00:00.000000000 Z
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70319700411940 !ruby/object:Gem::Requirement
16
+ requirement: &70294673074580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70319700411940
24
+ version_requirements: *70294673074580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70294673073000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70294673073000
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: sprockets
27
- requirement: &70319700411240 !ruby/object:Gem::Requirement
38
+ requirement: &70294673072280 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70319700411240
46
+ version_requirements: *70294673072280
36
47
  description: ! ' Replaces all instances of url() in CSS files Sprockets concats, if
37
48
  the url is relative. '
38
49
  email:
@@ -46,6 +57,7 @@ files:
46
57
  - README.md
47
58
  - Rakefile
48
59
  - lib/sprockets-urlrewriter.rb
60
+ - lib/sprockets-urlrewriter/version.rb
49
61
  - spec/urlrewriter_spec.rb
50
62
  - sprockets-urlrewriter.gemspec
51
63
  homepage: http://github.com/carlhoerberg/sprockets-urlrewriter
@@ -68,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
80
  version: '0'
69
81
  requirements: []
70
82
  rubyforge_project: sprockets-urlrewriter
71
- rubygems_version: 1.8.10
83
+ rubygems_version: 1.8.17
72
84
  signing_key:
73
85
  specification_version: 3
74
86
  summary: Makes absolut urls in CSS files generated by Sprockets