sprockets-sass 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -8
- data/lib/sprockets/sass/importer.rb +36 -5
- data/lib/sprockets/sass/version.rb +1 -1
- data/spec/sprockets-sass_spec.rb +24 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -10,18 +10,12 @@ _Note: This works in Rails 3.1, thanks to the [sass-rails gem](http://github.com
|
|
10
10
|
### Features
|
11
11
|
|
12
12
|
* Imports Sass _partials_ (filenames prepended with "_").
|
13
|
-
* Import paths work exactly like `require` directives
|
13
|
+
* Import paths work exactly like `require` directives.
|
14
14
|
* Imports either Sass syntax, or just regular CSS files.
|
15
15
|
* Imported files are preprocessed by Sprockets, so `.css.scss.erb` files can be imported.
|
16
16
|
Directives from within imported files also work as expected.
|
17
17
|
* Standard Sass load paths are not touched, so Compass extensions will work as expected.
|
18
|
-
|
19
|
-
_* Glob support coming in 0.2.0_
|
20
|
-
|
21
|
-
### TODO
|
22
|
-
|
23
|
-
* Glob support (as mentioned above)
|
24
|
-
* Asset path helpers
|
18
|
+
* Supports glob imports, like sass-rails.
|
25
19
|
|
26
20
|
|
27
21
|
Installation
|
@@ -4,6 +4,8 @@ require "pathname"
|
|
4
4
|
module Sprockets
|
5
5
|
module Sass
|
6
6
|
class Importer < ::Sass::Importers::Base
|
7
|
+
GLOB = /\*|\[.+\]/
|
8
|
+
|
7
9
|
# Reference to the Sprockets context
|
8
10
|
attr_reader :context
|
9
11
|
|
@@ -13,8 +15,12 @@ module Sprockets
|
|
13
15
|
end
|
14
16
|
|
15
17
|
# @see Sass::Importers::Base#find_relative
|
16
|
-
def find_relative(path,
|
17
|
-
|
18
|
+
def find_relative(path, base_path, options)
|
19
|
+
if path =~ GLOB
|
20
|
+
engine_from_glob(path, base_path, options)
|
21
|
+
else
|
22
|
+
engine_from_path(path, options)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
# @see Sass::Importers::Base#find
|
@@ -45,7 +51,6 @@ module Sprockets
|
|
45
51
|
protected
|
46
52
|
|
47
53
|
# Create a Sass::Engine from the given path.
|
48
|
-
# This is where all the magic happens!
|
49
54
|
def engine_from_path(path, options)
|
50
55
|
pathname = resolve(path) or return nil
|
51
56
|
context.depend_on pathname
|
@@ -56,6 +61,22 @@ module Sprockets
|
|
56
61
|
)
|
57
62
|
end
|
58
63
|
|
64
|
+
# Create a Sass::Engine that will handle importing
|
65
|
+
# a glob of files.
|
66
|
+
def engine_from_glob(glob, base_path, options)
|
67
|
+
imports = resolve_glob(glob, base_path).inject("") do |imports, path|
|
68
|
+
context.depend_on path
|
69
|
+
relative_path = path.relative_path_from Pathname.new(context.root_path)
|
70
|
+
imports << %(@import "#{relative_path}";\n)
|
71
|
+
end
|
72
|
+
return nil if imports.empty?
|
73
|
+
::Sass::Engine.new imports, options.merge(
|
74
|
+
:filename => base_path.to_s,
|
75
|
+
:syntax => :scss,
|
76
|
+
:importer => self
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
59
80
|
# Finds an asset from the given path. This is where
|
60
81
|
# we make Sprockets behave like Sass, and import partial
|
61
82
|
# style paths.
|
@@ -63,11 +84,21 @@ module Sprockets
|
|
63
84
|
path = Pathname.new(path) unless path.is_a?(Pathname)
|
64
85
|
partial = path.dirname.join("_#{path.basename}")
|
65
86
|
|
66
|
-
|
87
|
+
resolve_path(path) || resolve_path(partial)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Finds all of the assets using the given glob.
|
91
|
+
def resolve_glob(glob, base_path)
|
92
|
+
base_path = Pathname.new(base_path)
|
93
|
+
path_with_glob = base_path.dirname.join(glob).to_s
|
94
|
+
|
95
|
+
Pathname.glob(path_with_glob).sort.select do |path|
|
96
|
+
path != context.pathname && context.asset_requirable?(path)
|
97
|
+
end
|
67
98
|
end
|
68
99
|
|
69
100
|
# Finds the asset using the context from Sprockets.
|
70
|
-
def
|
101
|
+
def resolve_path(path)
|
71
102
|
context.resolve(path, :content_type => :self)
|
72
103
|
rescue ::Sprockets::FileNotFound, ::Sprockets::ContentTypeMismatch
|
73
104
|
nil
|
data/spec/sprockets-sass_spec.rb
CHANGED
@@ -95,8 +95,16 @@ describe Sprockets::Sass do
|
|
95
95
|
asset = @env["main.css.scss"]
|
96
96
|
asset.to_s.should == "body {\n color: blue; }\n"
|
97
97
|
end
|
98
|
+
|
99
|
+
it "imports globbed files" do
|
100
|
+
@assets.file "main.css.scss", %(@import "folder/*";\nbody { color: $color; background: $bg-color; })
|
101
|
+
@assets.file "folder/dep1.css.scss", "$color: blue;"
|
102
|
+
@assets.file "folder/dep2.css.scss", "$bg-color: red;"
|
103
|
+
asset = @env["main.css.scss"]
|
104
|
+
asset.to_s.should == "body {\n color: blue;\n background: red; }\n"
|
105
|
+
end
|
98
106
|
|
99
|
-
it "adds
|
107
|
+
it "adds dependencies when imported" do
|
100
108
|
@assets.file "main.css.scss", %(@import "dep";\nbody { color: $color; })
|
101
109
|
dep = @assets.file "dep.css.scss", "$color: blue;"
|
102
110
|
|
@@ -109,4 +117,19 @@ describe Sprockets::Sass do
|
|
109
117
|
|
110
118
|
asset.should be_stale
|
111
119
|
end
|
120
|
+
|
121
|
+
it "adds dependencies when imported from a glob" do
|
122
|
+
@assets.file "main.css.scss", %(@import "folder/*";\nbody { color: $color; background: $bg-color; })
|
123
|
+
@assets.file "folder/dep1.css.scss", "$color: blue;"
|
124
|
+
dep = @assets.file "folder/dep2.css.scss", "$bg-color: red;"
|
125
|
+
|
126
|
+
asset = @env["main.css.scss"]
|
127
|
+
asset.should be_fresh
|
128
|
+
|
129
|
+
mtime = Time.now + 1
|
130
|
+
dep.open("w") { |f| f.write "$bg-color: white;" }
|
131
|
+
dep.utime mtime, mtime
|
132
|
+
|
133
|
+
asset.should be_stale
|
134
|
+
end
|
112
135
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pete Browne
|