sprockets-plugin 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +45 -38
- data/lib/sprockets/plugin.rb +11 -8
- data/lib/sprockets/plugin/aware.rb +0 -16
- data/lib/sprockets/plugin/version.rb +1 -1
- data/spec/sprockets-plugin_spec.rb +45 -80
- data/sprockets-plugin.gemspec +2 -2
- metadata +39 -15
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
sprockets-plugin
|
2
2
|
================
|
3
3
|
|
4
|
-
Package assets into gems for non-Rails applications.
|
4
|
+
Package assets into gems for non-Rails Sprockets 2.x applications.
|
5
5
|
|
6
6
|
|
7
7
|
Installation
|
@@ -12,61 +12,68 @@ $ gem install sprockets-plugin
|
|
12
12
|
```
|
13
13
|
|
14
14
|
|
15
|
-
Usage
|
16
|
-
|
15
|
+
Usage in Applications
|
16
|
+
---------------------
|
17
17
|
|
18
|
-
|
18
|
+
To use Sprockets plugins, you only need to do 3 things:
|
19
19
|
|
20
|
+
1. Require "sprockets-plugin" to hook everything up.
|
21
|
+
_This may be required by the plugins themselves, but it's best practice to also require this in your application._
|
22
|
+
2. Require any plugins you want to use.
|
23
|
+
3. Call Sprockets::Environment#append_plugin_paths after setting up your application paths.
|
24
|
+
_Sprockets::Plugin **does not** automatically append paths to the environment. This is because the plugin paths would take precedence over your application's paths._
|
25
|
+
|
26
|
+
Here's an example:
|
27
|
+
|
20
28
|
``` ruby
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
require "sprockets"
|
30
|
+
require "sprockets-plugin" # 1.
|
31
|
+
require "my_plugin" # 2.
|
32
|
+
|
33
|
+
map "/assets" do
|
34
|
+
env = Sprockets::Environment.new
|
35
|
+
env.append_path "assets/images"
|
36
|
+
env.append_path "assets/javascripts"
|
37
|
+
env.append_path "assets/stylesheets"
|
38
|
+
env.append_plugin_paths # 3.
|
39
|
+
run env
|
24
40
|
end
|
25
41
|
```
|
26
42
|
|
27
|
-
|
43
|
+
Usage in Gems
|
44
|
+
-------------
|
28
45
|
|
29
|
-
|
30
|
-
require "sprockets-plugin"
|
46
|
+
Sprockets::Plugin is meant to be used within gems, to package assets for reuse. Again, there's only 3 things to do to set this up.
|
31
47
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
append_path "lib/assets/images"
|
36
|
-
append_path "lib/assets/javascripts"
|
37
|
-
append_path "lib/assets/stylesheets"
|
38
|
-
end
|
39
|
-
```
|
48
|
+
1. Add it as a dependency in your gemspec.
|
49
|
+
2. Extend Sprockets::Plugin.
|
50
|
+
3. Add the necessary paths.
|
40
51
|
|
41
|
-
|
52
|
+
`my_plugin.gemspec`:
|
42
53
|
|
43
54
|
``` ruby
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
map "/assets" do
|
48
|
-
environment = Sprockets::Environment.new
|
49
|
-
# The assets from MyPlugin will be automatically appended.
|
50
|
-
environment.append_path "assets/images"
|
51
|
-
environment.append_path "assets/javascripts"
|
52
|
-
environment.append_path "assets/stylesheets"
|
53
|
-
run environment
|
55
|
+
Gem::Specification.new do |s|
|
56
|
+
# ...
|
57
|
+
s.add_runtime_dependency "sprockets-plugin" # 1.
|
54
58
|
end
|
55
59
|
```
|
56
60
|
|
57
|
-
|
58
|
-
--------------
|
59
|
-
|
60
|
-
You can package assets for Rails and non-Rails applications in the following way:
|
61
|
+
`my_plugin.rb`:
|
61
62
|
|
62
63
|
``` ruby
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
require "sprockets-plugin"
|
65
|
+
|
66
|
+
class MyPlugin < Sprockets::Plugin # 2.
|
67
|
+
# Set the root path to use relative paths in `.append_path`
|
68
|
+
root File.expand_path("../..", __FILE__)
|
69
|
+
|
70
|
+
append_path "lib/assets/images" # 3.
|
71
|
+
append_path "lib/assets/javascripts" # 3.
|
72
|
+
append_path "lib/assets/stylesheets" # 3.
|
73
|
+
end
|
68
74
|
```
|
69
75
|
|
76
|
+
|
70
77
|
Copyright
|
71
78
|
---------
|
72
79
|
|
data/lib/sprockets/plugin.rb
CHANGED
@@ -31,15 +31,16 @@ module Sprockets
|
|
31
31
|
# later be appended to the Sprockets::Environment.
|
32
32
|
def append_paths(*paths)
|
33
33
|
self.paths.push *normalize_paths(paths)
|
34
|
+
self
|
34
35
|
end
|
35
36
|
alias_method :append_path, :append_paths
|
36
37
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
# Append each path in the given directory.
|
39
|
+
def append_paths_in(path)
|
40
|
+
path = normalize_path(path)
|
41
|
+
append_paths(*path.children.select(&:directory?)) if path.directory?
|
42
|
+
self
|
41
43
|
end
|
42
|
-
alias_method :prepend_path, :prepend_paths
|
43
44
|
|
44
45
|
# All of the paths registered by the plugin.
|
45
46
|
def paths
|
@@ -48,12 +49,14 @@ module Sprockets
|
|
48
49
|
|
49
50
|
protected
|
50
51
|
|
52
|
+
def normalize_path(path)
|
53
|
+
Pathname.new(path).expand_path(root)
|
54
|
+
end
|
55
|
+
|
51
56
|
def normalize_paths(paths)
|
52
57
|
normalized_paths = []
|
53
58
|
paths.each do |path|
|
54
|
-
path =
|
55
|
-
path = root.join(path) if root && path.relative?
|
56
|
-
path = path.expand_path
|
59
|
+
path = normalize_path(path)
|
57
60
|
normalized_paths.push(path.to_s) if path.exist?
|
58
61
|
end
|
59
62
|
normalized_paths
|
@@ -3,22 +3,6 @@ require "sprockets/environment"
|
|
3
3
|
module Sprockets
|
4
4
|
class Plugin
|
5
5
|
module Aware
|
6
|
-
def self.included(base)
|
7
|
-
base.extend ClassMethods
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
# Overrides .new to append Plugin paths after
|
12
|
-
# initialization.
|
13
|
-
#
|
14
|
-
# Is there a better way to do this?
|
15
|
-
def new(*args)
|
16
|
-
super(*args) do |env|
|
17
|
-
env.append_plugin_paths
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
6
|
# Appends the paths from each Sprockets::Plugin
|
23
7
|
# to the Sprockets::Environment.
|
24
8
|
def append_plugin_paths
|
@@ -5,40 +5,44 @@ describe Sprockets::Plugin do
|
|
5
5
|
Sprockets::Plugin.send :class_variable_set, :@@plugins, nil
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
describe "#append_plugin_paths" do
|
9
|
+
it "adds paths from plugins to environments" do
|
10
|
+
dir_1 = @sandbox.directory "plugin_1/assets"
|
11
|
+
dir_2 = @sandbox.directory "plugin_2/assets"
|
12
|
+
dir_3 = @sandbox.directory "plugin_3/assets"
|
13
|
+
|
14
|
+
plugin_1 = Class.new Sprockets::Plugin
|
15
|
+
plugin_1.append_path dir_1
|
16
|
+
plugin_2 = Class.new Sprockets::Plugin
|
17
|
+
plugin_2.append_path dir_2
|
18
|
+
plugin_3 = Class.new Sprockets::Plugin
|
19
|
+
plugin_3.append_path dir_3
|
20
|
+
|
21
|
+
env = Sprockets::Environment.new
|
22
|
+
env.append_plugin_paths
|
23
|
+
env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
it "does not add duplicate paths" do
|
27
|
+
dir_1 = @sandbox.directory "plugin_1/assets"
|
28
|
+
dir_2 = @sandbox.directory "plugin_2/assets"
|
29
|
+
dir_3 = @sandbox.directory "plugin_3/assets"
|
30
|
+
|
31
|
+
plugin_1 = Class.new Sprockets::Plugin
|
32
|
+
plugin_1.append_path dir_1
|
33
|
+
|
34
|
+
env = Sprockets::Environment.new
|
35
|
+
env.append_plugin_paths
|
36
|
+
env.paths.should == [dir_1].map(&:to_s)
|
37
|
+
|
38
|
+
plugin_2 = Class.new Sprockets::Plugin
|
39
|
+
plugin_2.append_path dir_2
|
40
|
+
plugin_3 = Class.new Sprockets::Plugin
|
41
|
+
plugin_3.append_path dir_3
|
42
|
+
|
43
|
+
env.append_plugin_paths
|
44
|
+
env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
describe ".append_path" do
|
@@ -92,55 +96,16 @@ describe Sprockets::Plugin do
|
|
92
96
|
end
|
93
97
|
end
|
94
98
|
|
95
|
-
describe ".
|
96
|
-
it "adds paths" do
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
describe ".append_paths_in" do
|
100
|
+
it "adds paths within the given path" do
|
101
|
+
assets_dir = @sandbox.directory "plugin/assets"
|
102
|
+
dir_1 = assets_dir.directory "images"
|
103
|
+
dir_2 = assets_dir.directory "javascripts"
|
104
|
+
dir_3 = assets_dir.directory "stylesheets"
|
100
105
|
|
101
106
|
plugin = Class.new Sprockets::Plugin
|
102
|
-
plugin.
|
103
|
-
plugin.
|
104
|
-
plugin.prepend_path dir_3
|
105
|
-
plugin.paths.should == [dir_3, dir_2, dir_1].map(&:to_s)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "adds the paths relative to the plugin root" do
|
109
|
-
dir_1 = @sandbox.directory "plugin/assets/images"
|
110
|
-
dir_2 = @sandbox.directory "plugin/assets/javascripts"
|
111
|
-
dir_3 = @sandbox.directory "plugin/assets/stylesheets"
|
112
|
-
|
113
|
-
plugin = Class.new Sprockets::Plugin
|
114
|
-
plugin.root @sandbox.join "plugin"
|
115
|
-
plugin.prepend_path "assets/images"
|
116
|
-
plugin.prepend_path "assets/javascripts"
|
117
|
-
plugin.prepend_path "assets/stylesheets"
|
118
|
-
plugin.paths.should == [dir_3, dir_2, dir_1].map(&:to_s)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "only adds existing paths" do
|
122
|
-
dir_1 = @sandbox.directory "plugin/assets/images"
|
123
|
-
dir_2 = @sandbox.directory "plugin/assets/javascripts"
|
124
|
-
dir_3 = @sandbox.join "plugin/assets/stylesheets"
|
125
|
-
|
126
|
-
plugin = Class.new Sprockets::Plugin
|
127
|
-
plugin.prepend_path dir_1
|
128
|
-
plugin.prepend_path dir_2
|
129
|
-
plugin.prepend_path dir_3
|
130
|
-
plugin.paths.should == [dir_2, dir_1].map(&:to_s)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe ".prepends_paths" do
|
135
|
-
it "adds multiple paths at once" do
|
136
|
-
dir_1 = @sandbox.directory "plugin/assets/images"
|
137
|
-
dir_2 = @sandbox.directory "plugin/assets/javascripts"
|
138
|
-
dir_3 = @sandbox.directory "plugin/assets/stylesheets"
|
139
|
-
|
140
|
-
plugin = Class.new Sprockets::Plugin
|
141
|
-
plugin.append_path dir_1
|
142
|
-
plugin.prepend_paths dir_2 ,dir_3
|
143
|
-
plugin.paths.should == [dir_2, dir_3, dir_1].map(&:to_s)
|
107
|
+
plugin.append_paths_in assets_dir
|
108
|
+
plugin.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
|
144
109
|
end
|
145
110
|
end
|
146
111
|
|
data/sprockets-plugin.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Pete Browne"]
|
9
9
|
s.email = ["me@petebrowne.com"]
|
10
10
|
s.homepage = "https://github.com/petebrowne/sprockets-plugin"
|
11
|
-
s.summary = %q{Package assets into gems for non-Rails applications.}
|
12
|
-
s.description = %q{Package assets into gems for non-Rails applications.}
|
11
|
+
s.summary = %q{Package assets into gems for non-Rails Sprockets 2.x applications.}
|
12
|
+
s.description = %q{Package assets into gems for non-Rails Sprockets 2.x applications.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "sprockets-plugin"
|
15
15
|
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Pete Browne
|
@@ -10,53 +15,72 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-05 00:00:00 Z
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
|
21
|
+
type: :runtime
|
17
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
18
23
|
none: false
|
19
24
|
requirements:
|
20
25
|
- - ~>
|
21
26
|
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
22
31
|
version: "2.0"
|
23
|
-
type: :runtime
|
24
32
|
prerelease: false
|
33
|
+
name: sprockets
|
25
34
|
version_requirements: *id001
|
26
35
|
- !ruby/object:Gem::Dependency
|
27
|
-
|
36
|
+
type: :development
|
28
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
29
38
|
none: false
|
30
39
|
requirements:
|
31
40
|
- - ~>
|
32
41
|
- !ruby/object:Gem::Version
|
42
|
+
hash: 15
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 4
|
46
|
+
- 0
|
33
47
|
version: 0.4.0
|
34
|
-
type: :development
|
35
48
|
prerelease: false
|
49
|
+
name: appraisal
|
36
50
|
version_requirements: *id002
|
37
51
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
52
|
+
type: :development
|
39
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
40
54
|
none: false
|
41
55
|
requirements:
|
42
56
|
- - ~>
|
43
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 6
|
62
|
+
- 0
|
44
63
|
version: 2.6.0
|
45
|
-
type: :development
|
46
64
|
prerelease: false
|
65
|
+
name: rspec
|
47
66
|
version_requirements: *id003
|
48
67
|
- !ruby/object:Gem::Dependency
|
49
|
-
|
68
|
+
type: :development
|
50
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
51
70
|
none: false
|
52
71
|
requirements:
|
53
72
|
- - ~>
|
54
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 31
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 2
|
78
|
+
- 0
|
55
79
|
version: 1.2.0
|
56
|
-
type: :development
|
57
80
|
prerelease: false
|
81
|
+
name: test-construct
|
58
82
|
version_requirements: *id004
|
59
|
-
description: Package assets into gems for non-Rails applications.
|
83
|
+
description: Package assets into gems for non-Rails Sprockets 2.x applications.
|
60
84
|
email:
|
61
85
|
- me@petebrowne.com
|
62
86
|
executables: []
|
@@ -95,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
119
|
requirements:
|
96
120
|
- - ">="
|
97
121
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
122
|
+
hash: 3
|
99
123
|
segments:
|
100
124
|
- 0
|
101
125
|
version: "0"
|
@@ -104,17 +128,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
128
|
requirements:
|
105
129
|
- - ">="
|
106
130
|
- !ruby/object:Gem::Version
|
107
|
-
hash:
|
131
|
+
hash: 3
|
108
132
|
segments:
|
109
133
|
- 0
|
110
134
|
version: "0"
|
111
135
|
requirements: []
|
112
136
|
|
113
137
|
rubyforge_project: sprockets-plugin
|
114
|
-
rubygems_version: 1.8.
|
138
|
+
rubygems_version: 1.8.11
|
115
139
|
signing_key:
|
116
140
|
specification_version: 3
|
117
|
-
summary: Package assets into gems for non-Rails applications.
|
141
|
+
summary: Package assets into gems for non-Rails Sprockets 2.x applications.
|
118
142
|
test_files:
|
119
143
|
- spec/spec_helper.rb
|
120
144
|
- spec/sprockets-plugin_spec.rb
|