sprockets-urlrewriter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sprockets-urlrewriter.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ Example usage
2
+ =============
3
+
4
+ gem install sprockets-urlrewriter
5
+
6
+ In config.ru
7
+
8
+ map '/assets' do
9
+ s = Sprockets::Environment.new
10
+ s.append_path 'assets/css'
11
+ s.append_path 'assets/js'
12
+ s.append_path 'vendor/js'
13
+ s.register_preprocessor 'text/css', Sprockets::UrlRewriter
14
+ s.cache = Sprockets::Cache::FileStore.new("tmp/sprockets")
15
+ run s
16
+ end
17
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/*_spec.rb"
6
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Urlrewriter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'sprockets-urlrewriter/version'
2
+ require 'sprockets'
3
+ require 'pathname'
4
+ require 'uri'
5
+
6
+ module Sprockets
7
+ class UrlRewriter < Processor
8
+ def evaluate(context, locals)
9
+ rel = Pathname.new(context.logical_path).parent
10
+ data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
11
+ return url if URI.parse($1).absolute?
12
+ new_path = rel.join Pathname.new($1)
13
+ "url(#{new_path})"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'minitest/autorun'
2
+ require './lib/sprockets-urlrewriter'
3
+
4
+ describe 'UrlRewriter' do
5
+ class FakeContext
6
+ attr_accessor :logical_path
7
+ end
8
+
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
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sprockets-urlrewriter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sprockets-urlrewriter"
7
+ s.version = Sprockets::Urlrewriter::VERSION
8
+ s.authors = ["Carl Hörberg"]
9
+ s.email = ["carl.hoerberg@gmail.com"]
10
+ s.homepage = "http://github.com/carlhoerberg/sprockets-urlrewriter"
11
+ s.summary = %q{Makes absolut urls in CSS files generated by Sprockets}
12
+ s.description = %q{ Replaces all instances of url() in CSS files Sprockets concats, if the url is relative. }
13
+
14
+ s.rubyforge_project = "sprockets-urlrewriter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "minitest"
22
+ s.add_runtime_dependency "sprockets"
23
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-urlrewriter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Carl Hörberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &70266638663940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70266638663940
25
+ - !ruby/object:Gem::Dependency
26
+ name: sprockets
27
+ requirement: &70266638663520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70266638663520
36
+ description: ! ' Replaces all instances of url() in CSS files Sprockets concats, if
37
+ the url is relative. '
38
+ email:
39
+ - carl.hoerberg@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - lib/sprockets-urlrewriter.rb
49
+ - lib/sprockets-urlrewriter/version.rb
50
+ - spec/urlrewriter_spec.rb
51
+ - sprockets-urlrewriter.gemspec
52
+ homepage: http://github.com/carlhoerberg/sprockets-urlrewriter
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: sprockets-urlrewriter
72
+ rubygems_version: 1.8.6
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Makes absolut urls in CSS files generated by Sprockets
76
+ test_files:
77
+ - spec/urlrewriter_spec.rb