stylus 0.6.2 → 0.7.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/.gitignore +3 -1
- data/CHANGELOG.md +8 -0
- data/README.md +31 -2
- data/lib/stylus.rb +1 -2
- data/lib/stylus/import_processor.rb +22 -5
- data/lib/stylus/sprockets.rb +4 -2
- data/lib/stylus/version.rb +1 -1
- data/spec/import_processor_spec.rb +41 -8
- data/spec/stylesheets/indexed/first_dep.styl +2 -0
- data/spec/stylesheets/indexed/index.styl +2 -0
- data/spec/stylesheets/indexed/second_dep.styl +3 -0
- data/spec/stylesheets/indexed_nested_import.styl +1 -0
- data/spec/stylesheets/indexed_recursive_import.styl +1 -0
- data/spec/stylesheets/mixins/nested.styl +1 -0
- data/spec/stylesheets/nested_import.styl +1 -0
- data/spec/support/helpers.rb +6 -0
- metadata +16 -2
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### HEAD
|
4
|
+
|
5
|
+
### 0.7.0 (2013-01-27)
|
6
|
+
[Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.6.2...v0.7.0)
|
7
|
+
|
8
|
+
* `ImportProcessor` tracks `@import` definitions recursively.
|
9
|
+
* `Tilt` shouldn't a hard dependency.
|
10
|
+
|
3
11
|
### 0.6.2 (2012-06-01)
|
4
12
|
[Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.6.1...v0.6.2)
|
5
13
|
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Ruby Stylus
|
2
2
|
|
3
3
|
[](http://travis-ci.org/lucasmazza/ruby-stylus)
|
4
|
-
[](https://gemnasium.com/lucasmazza/ruby-stylus)
|
5
4
|
|
6
5
|
`stylus` is a bridge between your Ruby code and the [Stylus](https://github.com/LearnBoost/stylus) library that runs on [node.js](http://nodejs.org). It has support for the Rails 3.1 asset pipeline (thanks to a [Tilt](https://github.com/rtomayko/tilt) Template) and it's backed by the [ExecJS](https://github.com/sstephenson/execjs) gem.
|
7
6
|
|
@@ -62,6 +61,36 @@ If you use Stylus `@import` to expose variables, mixins or just to concatenate c
|
|
62
61
|
@import 'mixins'
|
63
62
|
```
|
64
63
|
|
64
|
+
### `@import` dependency resolution
|
65
|
+
|
66
|
+
Because of how sprockets handles dependency resolution for computing
|
67
|
+
file changes and expiring caches, it is necessary to specify the full import path in your import statements.
|
68
|
+
|
69
|
+
That is, given:
|
70
|
+
|
71
|
+
app/assets/stylesheets/
|
72
|
+
app/assets/stylesheets/file.styl
|
73
|
+
app/assets/stylesheets/some_directory/other_file.styl
|
74
|
+
app/assets/stylesheets/some_directory/another_file.styl
|
75
|
+
|
76
|
+
Imports should be specified with the full path relative to
|
77
|
+
`app/assets/stylesheets` regardless of where the file calling the import is. In this example we use the `app/assets` directory, but this also applies to `vendor/assets` and `lib/assets`.
|
78
|
+
|
79
|
+
`app/assets/stylesheets/file.styl`
|
80
|
+
|
81
|
+
@import "some_directory/other_file.styl"
|
82
|
+
...
|
83
|
+
|
84
|
+
`app/assets/stylesheets/some_directory/other_file.styl`
|
85
|
+
|
86
|
+
@import "some_directory/another_file.styl"
|
87
|
+
...
|
88
|
+
|
89
|
+
This will ensure that all changes get reflected when any of the imported
|
90
|
+
files change. If you don't do this, sprockets will not accurately be
|
91
|
+
able to keep track of your dependencies.
|
92
|
+
|
93
|
+
|
65
94
|
### Standalone Sprockets usage
|
66
95
|
|
67
96
|
If you're using Sprockets outside Rails, on Sinatra or on a plain Rack app, you can wire up Stylus inside a instance of `Sprockets::Environment` with the `Stylus.setup` method.
|
@@ -128,4 +157,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
128
157
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
129
158
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
130
159
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
131
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
160
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/stylus.rb
CHANGED
@@ -2,7 +2,6 @@ require 'stylus/runtime'
|
|
2
2
|
require 'stylus/source'
|
3
3
|
require 'stylus/sprockets'
|
4
4
|
require 'stylus/version'
|
5
|
-
require 'stylus/tilt' if defined?(::Tilt)
|
6
5
|
require 'stylus/railtie' if defined?(::Rails)
|
7
6
|
## Stylus
|
8
7
|
#
|
@@ -154,5 +153,5 @@ module Stylus
|
|
154
153
|
|
155
154
|
# Exports the `.node_modules` folder on the working directory so npm can
|
156
155
|
# require modules installed locally.
|
157
|
-
ENV['NODE_PATH'] = "#{File.expand_path('node_modules')}:#{bundled_path}:#{ENV['NODE_PATH']}"
|
156
|
+
ENV['NODE_PATH'] = "#{File.expand_path('node_modules')}:#{File.expand_path('vendor/node_modules')}:#{bundled_path}:#{ENV['NODE_PATH']}"
|
158
157
|
end
|
@@ -17,9 +17,22 @@ module Stylus
|
|
17
17
|
def prepare
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
21
|
-
#
|
20
|
+
# Public: Scans the current stylesheet to track down Stylus
|
21
|
+
# '@import' calls as dependencies.
|
22
|
+
#
|
23
|
+
# Returns the stylesheet content, unmodified.
|
22
24
|
def evaluate(context, locals, &block)
|
25
|
+
depend_on(context, data)
|
26
|
+
data
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Internal: Scan the stylesheet body, looking for '@import' calls to
|
32
|
+
# declare them as a dependency on the context using 'depend_on' method.
|
33
|
+
# This method will recursively scans all dependency to ensure that
|
34
|
+
# the current stylesheet tracks down nested dependencies.
|
35
|
+
def depend_on(context, data)
|
23
36
|
dependencies = data.scan(IMPORT_SCANNER).flatten.compact.uniq
|
24
37
|
|
25
38
|
dependencies.each do |path|
|
@@ -27,9 +40,9 @@ module Stylus
|
|
27
40
|
|
28
41
|
if asset
|
29
42
|
context.depend_on(asset)
|
43
|
+
depend_on(context, File.read(asset))
|
30
44
|
end
|
31
45
|
end
|
32
|
-
data
|
33
46
|
end
|
34
47
|
|
35
48
|
# Internal: Resolves the given 'path' with the Sprockets context, but
|
@@ -40,7 +53,11 @@ module Stylus
|
|
40
53
|
def resolve(context, path)
|
41
54
|
context.resolve(path, :content_type => 'text/css')
|
42
55
|
rescue ::Sprockets::FileNotFound
|
43
|
-
|
56
|
+
begin
|
57
|
+
context.resolve(path + '/index', :content_type => 'text/css')
|
58
|
+
rescue
|
59
|
+
nil
|
60
|
+
end
|
44
61
|
end
|
45
62
|
end
|
46
|
-
end
|
63
|
+
end
|
data/lib/stylus/sprockets.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'stylus/
|
1
|
+
if defined?(::Tilt)
|
2
|
+
require 'stylus/tilt'
|
3
|
+
require 'stylus/import_processor'
|
4
|
+
end
|
3
5
|
|
4
6
|
# Public: The setup logic to configure both Stylus and Sprockets on any
|
5
7
|
# kind of application - Rails, Sinatra or Rack.
|
data/lib/stylus/version.rb
CHANGED
@@ -1,24 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stylus::ImportProcessor do
|
4
|
+
let(:env) do
|
5
|
+
Sprockets::Environment.new do |assets|
|
6
|
+
assets.append_path fixture_root
|
7
|
+
Stylus.setup(assets)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
it 'adds an imported stylesheet as a dependency' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
12
|
+
asset = env['import']
|
13
|
+
dependencies = dependencies_on(asset)
|
14
|
+
|
15
|
+
dependencies.should include(fixture_path('mixins/vendor'))
|
16
|
+
end
|
17
|
+
|
18
|
+
context "nested dependencies" do
|
19
|
+
it 'walks the dependency chain of imported files' do
|
20
|
+
asset = env['nested_import']
|
21
|
+
dependencies = dependencies_on(asset)
|
22
|
+
|
23
|
+
dependencies.should include(fixture_path('mixins/nested'))
|
24
|
+
dependencies.should include(fixture_path('mixins/vendor'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "adds files referenced in a directory's index file" do
|
28
|
+
asset = env['indexed_nested_import']
|
29
|
+
dependencies = dependencies_on(asset)
|
30
|
+
|
31
|
+
dependencies.should include(fixture_path('indexed/index'))
|
32
|
+
dependencies.should include(fixture_path('indexed/first_dep'))
|
33
|
+
dependencies.should include(fixture_path('indexed/second_dep'))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "walks dependency chains through indexes" do
|
37
|
+
asset = env['indexed_recursive_import']
|
38
|
+
dependencies = dependencies_on(asset)
|
9
39
|
|
10
|
-
|
11
|
-
|
40
|
+
dependencies.should include(fixture_path('indexed_nested_import'))
|
41
|
+
dependencies.should include(fixture_path('indexed/index'))
|
42
|
+
dependencies.should include(fixture_path('indexed/first_dep'))
|
43
|
+
dependencies.should include(fixture_path('indexed/second_dep'))
|
44
|
+
end
|
12
45
|
end
|
13
46
|
|
14
47
|
it "swallows errors from files outside the Sprockets paths" do
|
15
48
|
source = "@import 'nib'"
|
16
49
|
template = Stylus::ImportProcessor.new { source }
|
17
50
|
sprockets = double()
|
18
|
-
sprockets.should_receive(:resolve).and_raise(::Sprockets::FileNotFound)
|
51
|
+
sprockets.should_receive(:resolve).twice.and_raise(::Sprockets::FileNotFound)
|
19
52
|
|
20
53
|
expect {
|
21
54
|
template.render(sprockets)
|
22
55
|
}.to_not raise_error(::Sprockets::FileNotFound)
|
23
56
|
end
|
24
|
-
end
|
57
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
@import 'indexed'
|
@@ -0,0 +1 @@
|
|
1
|
+
@import 'indexed_nested_import'
|
@@ -0,0 +1 @@
|
|
1
|
+
@import 'mixins/vendor'
|
@@ -0,0 +1 @@
|
|
1
|
+
@import 'mixins/nested'
|
data/spec/support/helpers.rb
CHANGED
@@ -45,4 +45,10 @@ module Helpers
|
|
45
45
|
def fixture_path(name)
|
46
46
|
File.join(fixture_root, "#{name}.styl")
|
47
47
|
end
|
48
|
+
|
49
|
+
def dependencies_on(asset)
|
50
|
+
context = env.context_class.new(env, asset.logical_path, asset.pathname)
|
51
|
+
context.evaluate(asset.pathname)
|
52
|
+
context._dependency_paths
|
53
|
+
end
|
48
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
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:
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
@@ -154,7 +154,14 @@ files:
|
|
154
154
|
- spec/stylesheets/debug.styl
|
155
155
|
- spec/stylesheets/implicit.styl
|
156
156
|
- spec/stylesheets/import.styl
|
157
|
+
- spec/stylesheets/indexed/first_dep.styl
|
158
|
+
- spec/stylesheets/indexed/index.styl
|
159
|
+
- spec/stylesheets/indexed/second_dep.styl
|
160
|
+
- spec/stylesheets/indexed_nested_import.styl
|
161
|
+
- spec/stylesheets/indexed_recursive_import.styl
|
162
|
+
- spec/stylesheets/mixins/nested.styl
|
157
163
|
- spec/stylesheets/mixins/vendor.styl
|
164
|
+
- spec/stylesheets/nested_import.styl
|
158
165
|
- spec/stylesheets/nib.styl
|
159
166
|
- spec/stylesheets/plugin.styl
|
160
167
|
- spec/stylesheets/simple.styl
|
@@ -213,7 +220,14 @@ test_files:
|
|
213
220
|
- spec/stylesheets/debug.styl
|
214
221
|
- spec/stylesheets/implicit.styl
|
215
222
|
- spec/stylesheets/import.styl
|
223
|
+
- spec/stylesheets/indexed/first_dep.styl
|
224
|
+
- spec/stylesheets/indexed/index.styl
|
225
|
+
- spec/stylesheets/indexed/second_dep.styl
|
226
|
+
- spec/stylesheets/indexed_nested_import.styl
|
227
|
+
- spec/stylesheets/indexed_recursive_import.styl
|
228
|
+
- spec/stylesheets/mixins/nested.styl
|
216
229
|
- spec/stylesheets/mixins/vendor.styl
|
230
|
+
- spec/stylesheets/nested_import.styl
|
217
231
|
- spec/stylesheets/nib.styl
|
218
232
|
- spec/stylesheets/plugin.styl
|
219
233
|
- spec/stylesheets/simple.styl
|