sprockets-vendor_gems 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -16
- data/lib/sprockets-vendor_gems.rb +15 -1
- data/lib/sprockets-vendor_gems/extend_all.rb +14 -0
- data/sprockets-vendor_gems.gemspec +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -1,6 +1,49 @@
|
|
1
1
|
# Get at available assets in loaded gems in Sprockets
|
2
2
|
|
3
|
-
|
3
|
+
Who says you need Rails Engines to use the vendored assets in gems? All you need is
|
4
|
+
`sprockets-vendor_gems`. Use those cool vendored JavaScript & CSS gems in anything!
|
5
|
+
|
6
|
+
The easiest way? Punch Sprockets right in the duck!
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
require 'sprockets-vendor_gems/extend_all'
|
10
|
+
```
|
11
|
+
|
12
|
+
So, for instance, in Sinatra with [sinatra-sprockets](https://github.com/amarshall/sinatra-sprockets):
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
# config.ru
|
16
|
+
|
17
|
+
require 'sinatra/base'
|
18
|
+
require 'sprockets-vendor_gems/extend_all'
|
19
|
+
require 'sinatra/sprockets'
|
20
|
+
|
21
|
+
class MyApp < Sinatra::Base
|
22
|
+
register Sinatra::Sprockets
|
23
|
+
|
24
|
+
get '/' do
|
25
|
+
"hi"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
map "/assets" do
|
30
|
+
run Sinatra::Sprockets.environment
|
31
|
+
end
|
32
|
+
|
33
|
+
run MyApp
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
*Every* `Sprockets::Environment` instance now has every vendored gems asset path added!
|
38
|
+
By default, that's the `javascripts`, `stylesheets`, and `images` directories. Need more?
|
39
|
+
|
40
|
+
``` ruby
|
41
|
+
Sprockets::VendorGems.default_types << "coolthings"
|
42
|
+
```
|
43
|
+
|
44
|
+
Do that before any `Sprockets::Environment`s get instantiated.
|
45
|
+
|
46
|
+
Want more manual control? Either get the list of asset paths:
|
4
47
|
|
5
48
|
``` ruby
|
6
49
|
require 'sprockets-vendor_gems'
|
@@ -11,7 +54,7 @@ Sprockets.find_gem_vendor_paths(:for => :javascript).each do |path|
|
|
11
54
|
end
|
12
55
|
```
|
13
56
|
|
14
|
-
or get an Environment with those paths in there already:
|
57
|
+
or, instead of duck punching all of Sprockets, get an Environment with those paths in there already:
|
15
58
|
|
16
59
|
``` ruby
|
17
60
|
require 'sprockets-vendor_gems'
|
@@ -21,17 +64,5 @@ env = Sprockets::EnvironmentWithVendoredGems.new
|
|
21
64
|
|
22
65
|
Yeah!
|
23
66
|
|
24
|
-
|
25
|
-
|
26
|
-
Add this line to your application's Gemfile:
|
27
|
-
|
28
|
-
gem 'sprockets-vendor_gems'
|
29
|
-
|
30
|
-
And then execute:
|
31
|
-
|
32
|
-
$ bundle
|
33
|
-
|
34
|
-
Or install it yourself as:
|
35
|
-
|
36
|
-
$ gem install sprockets-vendor_gems
|
37
|
-
|
67
|
+
You may have to futz a bit with `require` and fake classes for particular gems, especially if they really
|
68
|
+
rely on Rails to get their job done.
|
@@ -2,10 +2,18 @@ require 'sprockets'
|
|
2
2
|
require 'rubygems'
|
3
3
|
|
4
4
|
module ::Sprockets
|
5
|
+
module VendorGems
|
6
|
+
class << self
|
7
|
+
attr_accessor :default_types
|
8
|
+
end
|
9
|
+
|
10
|
+
self.default_types = %w{javascripts stylesheets images}
|
11
|
+
end
|
12
|
+
|
5
13
|
def self.find_gem_vendor_paths(options = {})
|
6
14
|
options = { :paths => %w{vendor lib app} }.merge(options)
|
7
15
|
|
8
|
-
for_types = [ options[:for] ||
|
16
|
+
for_types = [ options[:for] || ::Sprockets::VendorGems.default_types ].flatten
|
9
17
|
|
10
18
|
paths = []
|
11
19
|
|
@@ -24,6 +32,12 @@ module ::Sprockets
|
|
24
32
|
def initialize(*args)
|
25
33
|
super(*args)
|
26
34
|
|
35
|
+
extend_with_vendored_gems
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Environment
|
40
|
+
def extend_with_vendored_gems
|
27
41
|
Sprockets.find_gem_vendor_paths.each { |path| append_path(path) }
|
28
42
|
end
|
29
43
|
end
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
12
|
gem.name = "sprockets-vendor_gems"
|
13
13
|
gem.require_paths = ["lib"]
|
14
|
-
gem.version = '0.1.
|
14
|
+
gem.version = '0.1.3'
|
15
15
|
|
16
16
|
gem.add_dependency 'sprockets'
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-vendor_gems
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- README.md
|
105
105
|
- Rakefile
|
106
106
|
- lib/sprockets-vendor_gems.rb
|
107
|
+
- lib/sprockets-vendor_gems/extend_all.rb
|
107
108
|
- spec/spec_helper.rb
|
108
109
|
- spec/sprockets-vendor_gems_spec.rb
|
109
110
|
- sprockets-vendor_gems.gemspec
|