stylus 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.4.0 (2011-11-23)
4
+ [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.3.0...v.0.4.0)
5
+
6
+ * `@import` directives will be added as dependencies to Sprockets (based on the work by @metaskills on the less-rails).
7
+
3
8
  ### 0.3.0 (2011-10-17)
4
- [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.2.2...v.0.30)
9
+ [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.2.2...v.0.3.0)
5
10
 
6
11
  * This gem now uses the [stylus-source](https://github.com/railsjedi/ruby-stylus-source) gem to bundle the latest [NPM](http://search.npmjs.org/#/stylus) package of Stylus, so there's no setup required to install stylus via `npm install` or cloning it into the `node_modules` folder - Thanks @railsjedi.
7
12
  * Added a `debug` configuration option, that enables the `linenos` and `firebug` flags on Stylus. Inside Rails, this configuration option will be copied from the `config.assets.debug`;
data/README.md CHANGED
@@ -42,14 +42,25 @@ Stylus.debug = true
42
42
  ```
43
43
  ### With the Rails 3.1 Asset Pipeline.
44
44
 
45
- Adding `stylus` to your Gemfile should let you work with `.styl` files with the Rails 3.1 Pipeline. Any asset generated with `rails generate` will be created with a `.css.styl` extension.
45
+ First of all, remember to add `gem 'stylus'` to your Gemfile inside the `:assets` group, So Rails will require the gem according to your current environment - on production you should serve precompiled versions of your assets instead of compiling on the fly.
46
46
 
47
- While [Stylus](https://github.com/LearnBoost/stylus) has a `@import` directive, inside a Rails application you should use the `//= require` directive from Sprockets, so the caching mechanism will look after the changes made on the required file. If you're using mixins (for vendor prefixes or any common statements) or plugins inside your `.styl` files, you should use [Stylus](https://github.com/LearnBoost/stylus) `@import` **and** Sprockets `//= depend_on`. The latter is to ensure the proper dependency management on the Sprockets side.
47
+ Adding `stylus` to your Gemfile should let you work with `.styl` files with the Rails 3.1 Pipeline. Any asset generated with `rails generate` will be created with a `.css.styl` extension.
48
48
 
49
- Any `.styl` file on the Sprockets load path (`app/assets`, `lib/assets`, `vendor/assets` or `assets` folder inside any other gem) will be available via the `@import` directive.
49
+ Any `@import` directive will add the stylesheet as a sprockets dependency, so you can update external libraries and it will reflect on your assets fingerprints. Also, the Sprockets laod path (usually `app/assets`, `lib/assets`, `vendor/assets` and the `assets` folder inside any other gem) will be available to your stylesheets.
50
50
 
51
51
  If the `config.assets.debug` is turned on, Stylus will emit exta comments on your stylesheets to help debugging and inspection using the `linenos` and `firebug` options. Check the [FireStylus extension for Firebug](https://github.com/LearnBoost/stylus/blob/master/docs/firebug.md) for more info.
52
52
 
53
+ ### `@import` and file extensions.
54
+
55
+ Stylus and Sprockets file lookup differ on the subject of handling file extensions, and that may hurt a bit.
56
+
57
+ If you use Stylus `@import` to expose variables, mixins or just to concatenate code, you should use only the `.styl` extension on your imported files. If you use the `.css.styl` form (a convention from Sprockets), Stylus will treat it as a plain CSS file since it has `.css` on its name.
58
+
59
+ ```sass
60
+ // imports the mixins.styl
61
+ @import 'mixins'
62
+ ```
63
+
53
64
  ## Plugins
54
65
 
55
66
  [Stylus](https://github.com/LearnBoost/stylus) exposes a nice API to create plugins written on [node.js](http://nodejs.org), like [nib](https://github.com/visionmedia/nib). The installation process should be same as described above for [Stylus](https://github.com/LearnBoost/stylus) (since they're all npm packages after all). You can hook them'up on your Ruby code with `Stylus.use`:
data/lib/stylus.rb CHANGED
@@ -41,11 +41,11 @@ module Stylus
41
41
  # Stores a list of stylesheets to import on every compile process.
42
42
  def import(*paths)
43
43
  if paths.any?
44
- @@imports = @@imports.concat(paths)
45
- end
44
+ @@imports = @@imports.concat(paths)
45
+ end
46
46
  @@imports
47
- end
48
- alias :imports :import
47
+ end
48
+ alias :imports :import
49
49
 
50
50
  # Retrieves all the registered plugins.
51
51
  def plugins
@@ -0,0 +1,22 @@
1
+ # Based on the ImportProcessor from the less-rails gem, by @metaskills
2
+ module Stylus
3
+ class ImportProcessor < Tilt::Template
4
+
5
+ IMPORT_SCANNER = /@import\s*['"]([^'"]+)['"]\s*/.freeze
6
+
7
+ def prepare
8
+ end
9
+
10
+ def evaluate(context, locals, &block)
11
+ dependencies = data.scan(IMPORT_SCANNER).flatten.compact.uniq
12
+
13
+ dependencies.each do |path|
14
+ asset = context.environment[path]
15
+ if asset
16
+ context.depend_on_asset(asset.pathname)
17
+ end
18
+ end
19
+ data
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,6 @@
1
1
  require 'stylus/tilt'
2
+ require 'stylus/import_processor'
3
+
2
4
  module Stylus
3
5
  ### Stylus Railtie
4
6
  #
@@ -7,8 +9,9 @@ module Stylus
7
9
 
8
10
  config.app_generators.stylesheet_engine :stylus
9
11
 
10
- initializer :setup_stylus do |app|
12
+ initializer :setup_stylus, :after => 'sprockets.environment' do |app|
11
13
  app.assets.register_engine '.styl', Tilt::StylusTemplate
14
+ app.assets.register_preprocessor 'text/css', Stylus::ImportProcessor
12
15
  end
13
16
 
14
17
  # After initialization block to inspect the `Sprockets` configuration
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stylus::ImportProcessor do
4
+
5
+ let(:app) { create_app }
6
+ let(:env) { app.assets }
7
+ let(:context) { double(:environment => env) }
8
+
9
+ it 'adds an imported stylesheet as a dependency' do
10
+ source = fixture(:import).first
11
+ asset = env['import']
12
+ template = Stylus::ImportProcessor.new { source }
13
+ dependency = Pathname.new(fixture_path('mixins/vendor'))
14
+
15
+ context.should_receive(:depend_on_asset).with(dependency)
16
+ template.render(context)
17
+ end
18
+
19
+ end
@@ -43,8 +43,8 @@ module Generators
43
43
  module InstanceMethods
44
44
 
45
45
  def file(relative)
46
- File.expand_path(relative, destination_root)
47
- end
46
+ File.expand_path(relative, destination_root)
47
+ end
48
48
 
49
49
  def method_missing(method_sym, *arguments, &block)
50
50
  self.test_case_instance.send(method_sym, *arguments, &block)
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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-17 00:00:00.000000000Z
12
+ date: 2011-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
16
- requirement: &70345063766460 !ruby/object:Gem::Requirement
16
+ requirement: &2156670840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70345063766460
24
+ version_requirements: *2156670840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: stylus-source
27
- requirement: &70345063761640 !ruby/object:Gem::Requirement
27
+ requirement: &2156670400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70345063761640
35
+ version_requirements: *2156670400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70345063759280 !ruby/object:Gem::Requirement
38
+ requirement: &2156669900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70345063759280
46
+ version_requirements: *2156669900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: railties
49
- requirement: &70345063757120 !ruby/object:Gem::Requirement
49
+ requirement: &2156669380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.1.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70345063757120
57
+ version_requirements: *2156669380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: tzinfo
60
- requirement: &70345063756220 !ruby/object:Gem::Requirement
60
+ requirement: &2156668980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70345063756220
68
+ version_requirements: *2156668980
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
- requirement: &70345063754580 !ruby/object:Gem::Requirement
71
+ requirement: &2156668520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70345063754580
79
+ version_requirements: *2156668520
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rocco
82
- requirement: &70345063752320 !ruby/object:Gem::Requirement
82
+ requirement: &2156668100 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70345063752320
90
+ version_requirements: *2156668100
91
91
  description: Bridge library to compile .styl stylesheets from ruby code.
92
92
  email:
93
93
  - luc4smazza@gmail.com
@@ -107,6 +107,7 @@ files:
107
107
  - lib/rails/generators/stylus/scaffold/scaffold_generator.rb
108
108
  - lib/stylus.rb
109
109
  - lib/stylus/compiler.js
110
+ - lib/stylus/import_processor.rb
110
111
  - lib/stylus/railtie.rb
111
112
  - lib/stylus/runner.js
112
113
  - lib/stylus/tilt.rb
@@ -130,6 +131,7 @@ files:
130
131
  - spec/generators/assets_generator_spec.rb
131
132
  - spec/generators/controller_generator_spec.rb
132
133
  - spec/generators/scaffold_generator_spec.rb
134
+ - spec/import_processor_spec.rb
133
135
  - spec/spec_helper.rb
134
136
  - spec/sprockets_spec.rb
135
137
  - spec/stylus_spec.rb
@@ -182,6 +184,7 @@ test_files:
182
184
  - spec/generators/assets_generator_spec.rb
183
185
  - spec/generators/controller_generator_spec.rb
184
186
  - spec/generators/scaffold_generator_spec.rb
187
+ - spec/import_processor_spec.rb
185
188
  - spec/spec_helper.rb
186
189
  - spec/sprockets_spec.rb
187
190
  - spec/stylus_spec.rb