stylus 0.2.2 → 0.3.0.pre

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.3.0
4
+ [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.2.2...master)
5
+
6
+ * 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`;
7
+ * Added a global array `import` that handles other stylesheets to include on every compilation process;
8
+ * Added a shorthand `Stylus.nib = true` to use the plugin and import it on every processed stylesheet.
9
+
3
10
  ### 0.2.2 (2011-09-14)
4
11
  [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.2.1...v0.2.2)
5
12
 
data/README.md CHANGED
@@ -40,6 +40,11 @@ Stylus.convert(File.new('file.css'))
40
40
 
41
41
  # Importing plugins directly from Node.js, like nib.
42
42
  Stylus.use :nib
43
+
44
+ # Enabling debug info, which sends the 'linenos' and 'firebug' options to Stylus.
45
+ # If you provide a raw content String to the `Stylus.compile` method, remember to send
46
+ # a `:filename` option so Stylus can locate your stylesheet for proper inspection.
47
+ Stylus.debug = true
43
48
  ```
44
49
  ### With the Rails 3.1 Asset Pipeline.
45
50
 
@@ -49,6 +54,8 @@ While [Stylus](https://github.com/LearnBoost/stylus) has a `@import` directive,
49
54
 
50
55
  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.
51
56
 
57
+ 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.
58
+
52
59
  ## Plugins
53
60
 
54
61
  [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
@@ -24,8 +24,10 @@ require 'stylus/railtie' if defined?(::Rails)
24
24
  module Stylus
25
25
  class << self
26
26
  @@compress = false
27
- @@paths = []
28
- @@plugins = {}
27
+ @@debug = false
28
+ @@paths = []
29
+ @@imports = []
30
+ @@plugins = {}
29
31
 
30
32
  # Stores a list of plugins to import inside `Stylus`, with an optional hash.
31
33
  def use(*options)
@@ -36,6 +38,15 @@ module Stylus
36
38
  end
37
39
  alias :plugin :use
38
40
 
41
+ # Stores a list of stylesheets to import on every compile process.
42
+ def import(*paths)
43
+ if paths.any?
44
+ @@imports = @@imports.concat(paths)
45
+ end
46
+ @@imports
47
+ end
48
+ alias :imports :import
49
+
39
50
  # Retrieves all the registered plugins.
40
51
  def plugins
41
52
  @@plugins
@@ -51,22 +62,48 @@ module Stylus
51
62
  @@paths = Array(val)
52
63
  end
53
64
 
65
+ # Returns the `debug` flag used to set the `linenos` and `firebug` option for Stylus.
66
+ def debug
67
+ @@debug
68
+ end
69
+ alias :debug? :debug
70
+
71
+ # Marks the `nib` plugin to be loaded and included on every stylesheet.
72
+ def nib=(flag)
73
+ if flag
74
+ use :nib
75
+ import :nib
76
+ end
77
+ end
78
+
79
+ # Sets the `debug` flag.
80
+ def debug=(val)
81
+ @@debug = val
82
+ end
83
+
54
84
  # Returns the global compress flag.
55
85
  def compress
56
86
  @@compress
57
87
  end
88
+ alias :compress? :compress
58
89
 
59
90
  # Sets the global flag for the `compress` option.
60
91
  def compress=(val)
61
92
  @@compress = val
62
93
  end
63
94
 
64
- # Compiles a given input - a `File`, `StringIO`, `String` or anything that responds to `read`.
65
- # Also accepts a hash of options that will be merged with the global configuration.
95
+ # Compiles a given input - a plain String, `File` or some sort of IO object that
96
+ # responds to `read`.
97
+ # It accepts a hash of options that will be merged with the global configuration.
98
+ # If the source has a `path`, it will be expanded and used as the :filename option
99
+ # So the debug options can be used.
66
100
  def compile(source, options = {})
67
- source = source.read if source.respond_to?(:read)
101
+ if source.respond_to?(:path) && source.path
102
+ options[:filename] ||= File.expand_path(source.path)
103
+ end
104
+ source = source.read if source.respond_to?(:read)
68
105
  options = merge_options(options)
69
- context.call('compiler', source, options, plugins)
106
+ context.call('compiler', source, options, plugins, imports)
70
107
  end
71
108
 
72
109
  # Converts back an input of plain CSS to the `Stylus` syntax. The source object can be
@@ -79,15 +116,27 @@ module Stylus
79
116
  # Returns a `Hash` of the given `options` merged with the default configuration.
80
117
  # It also concats the global load path with a given `:paths` option.
81
118
  def merge_options(options)
82
- _paths = options.delete(:paths)
119
+ filename = options[:filename]
120
+
121
+ _paths = options.delete(:paths)
83
122
  options = defaults.merge(options)
84
123
  options[:paths] = paths.concat(Array(_paths))
124
+ if filename
125
+ options = options.merge(debug_options)
126
+ end
85
127
  options
86
128
  end
87
129
 
88
- # Returns the default `Hash` of options.
130
+ # Returns the default `Hash` of options:
131
+ # the compress flag and the global load path.
89
132
  def defaults
90
- { :compress => self.compress, :paths => self.paths }
133
+ { :compress => self.compress?, :paths => self.paths }
134
+ end
135
+
136
+ # Returns a Hash with the debug options to pass to
137
+ # Stylus.
138
+ def debug_options
139
+ { :linenos => self.debug?, :firebug => self.debug? }
91
140
  end
92
141
 
93
142
  # Return the gem version alongside with the current `Stylus` version of your system.
@@ -1,6 +1,6 @@
1
1
  var stylus = require('stylus');
2
2
 
3
- function compiler(str, options, plugins) {
3
+ function compiler(str, options, plugins, imports) {
4
4
  var style = stylus(str, options);
5
5
  var output = '';
6
6
 
@@ -8,6 +8,9 @@ function compiler(str, options, plugins) {
8
8
  var fn = require(name);
9
9
  style.use(fn(plugins[name]));
10
10
  }
11
+ imports.forEach(function(path) {
12
+ style.import(path);
13
+ })
11
14
 
12
15
  style.render(function(error, css) {
13
16
  if(error) throw error;
@@ -2,8 +2,7 @@ require 'stylus/tilt'
2
2
  module Stylus
3
3
  ### Stylus Railtie
4
4
  #
5
- # `Railtie` responsible for injecting `stylus` inside the
6
- # Rails application and the `Sprockets` Asset Pipeline.
5
+ # `Railtie` that hooks `stylus` inside a Rails application.
7
6
  class Railtie < ::Rails::Railtie
8
7
 
9
8
  config.app_generators.stylesheet_engine :stylus
@@ -12,10 +11,13 @@ module Stylus
12
11
  app.assets.register_engine '.styl', Tilt::StylusTemplate
13
12
  end
14
13
 
15
- # Includes the `Rails` asset load path into `stylus` so any
16
- # `.styl` file inside it can be imported by the `stylus` API.
14
+ # After initialization block to inspect the `Sprockets` configuration
15
+ # And reflect it on the `Stylus` module;
16
+ # It also includes the `Rails` asset load path into `Stylus` so any
17
+ # `.styl` file inside it can be imported by the `Stylus` API.
17
18
  config.after_initialize do |app|
18
19
  Stylus.compress = app.config.assets.compress
20
+ Stylus.debug = app.config.assets.debug
19
21
  Stylus.paths.concat app.assets.paths
20
22
  end
21
23
  end
data/lib/stylus/tilt.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'tilt'
2
2
 
3
3
  module Tilt
4
- ### Stylus template implementation for `Tilt`.
4
+ ### stylus template implementation for `Tilt`.
5
5
  #
6
- # It can be used by the `Rails` Asset Pipeline or `Sinatra` applications.
6
+ # It can be used by the `Rails` 3.1 or `Sinatra` applications.
7
7
  class StylusTemplate < Template
8
8
  self.default_mime_type = 'text/css'
9
9
 
@@ -11,12 +11,18 @@ module Tilt
11
11
  defined? ::Stylus
12
12
  end
13
13
 
14
- def prepare
14
+ def initialize_engine
15
15
  require_template_library 'stylus'
16
16
  end
17
17
 
18
+ def prepare
19
+ if self.file
20
+ options[:filename] ||= self.file
21
+ end
22
+ end
23
+
18
24
  def evaluate(scope, locals, &block)
19
- Stylus.compile(data, options)
25
+ @output ||= Stylus.compile(data, options)
20
26
  end
21
27
  end
22
28
  end
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0.pre"
3
3
  end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ a {
2
+ -moz-border-radius: 3px;
3
+ -webkit-border-radius: 3px;
4
+ border-radius: 3px;
5
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ background {
2
+ line-height: 1;
3
+ color: #000;
4
+ background: #fff;
5
+ }
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ body
2
+ color black
@@ -0,0 +1,2 @@
1
+ a
2
+ border-radius 3px
@@ -1,4 +1,2 @@
1
- @import 'nib'
2
-
3
1
  background
4
2
  reset-body()
@@ -0,0 +1,4 @@
1
+ @import 'nib'
2
+
3
+ background
4
+ reset-body()
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,9 @@ RSpec.configure do |config|
18
18
 
19
19
  config.after :each do
20
20
  Stylus.compress = false
21
+ Stylus.debug = false
21
22
  Stylus.paths = []
22
23
  Stylus.plugins.clear
24
+ Stylus.imports.clear
23
25
  end
24
26
  end
@@ -21,6 +21,18 @@ describe 'Sprockets and Rails integration' do
21
21
  app.assets['import'].to_s.should == result
22
22
  end
23
23
 
24
+ it 'skips debug info by default' do
25
+ app = create_app
26
+ asset = app.assets['simple']
27
+ asset.to_s.should_not match(/line 1 : #{asset.pathname}/)
28
+ end
29
+
30
+ it 'provides debug info if required' do
31
+ app = create_app(:debug => true)
32
+ asset = app.assets['simple']
33
+ asset.to_s.should match(/line 1 : #{asset.pathname}/)
34
+ end
35
+
24
36
  it 'compress the output if Rails is configured to compress them too' do
25
37
  result = fixture(:compressed).last
26
38
 
data/spec/stylus_spec.rb CHANGED
@@ -37,6 +37,13 @@ describe Stylus do
37
37
  Stylus.compile(input).should == output
38
38
  end
39
39
 
40
+ it 'implicit imports the given paths' do
41
+ path = File.expand_path('mixins/vendor.styl', fixture_root)
42
+ input, output = fixture :implicit
43
+ Stylus.import path
44
+ Stylus.compile(input).should == output
45
+ end
46
+
40
47
  it "outputs both gem and library version" do
41
48
  Stylus.version.should =~ /Stylus - gem .+ library .+/
42
49
  end
@@ -53,7 +60,38 @@ describe Stylus do
53
60
 
54
61
  it "includes the given plugins" do
55
62
  Stylus.use :nib
63
+ input, output = fixture :plugin
64
+ Stylus.compile(input).should == output
65
+ end
66
+
67
+ it "includes and imports 'nib' automatically" do
68
+ Stylus.nib = true
56
69
  input, output = fixture :nib
57
70
  Stylus.compile(input).should == output
58
71
  end
72
+
73
+ describe "The debug flag" do
74
+
75
+ let(:path) { fixture_path(:debug) }
76
+ let(:fixture) { File.read(path) }
77
+ let(:file) { File.new(path) }
78
+
79
+ before { Stylus.debug = true }
80
+
81
+ it "turns the 'linenos' option on" do
82
+ Stylus.compile(file).should match(/line 1 : #{path}/)
83
+ end
84
+
85
+ it "skips the 'linenos' option if no filename is given" do
86
+ Stylus.compile(fixture).should_not match(/line 1 : #{path}/)
87
+ end
88
+
89
+ it "turns the 'firebug' option on" do
90
+ Stylus.compile(file).should match(/@media -stylus-debug-info/)
91
+ end
92
+
93
+ it "skips the 'firebug' option if no filename is given" do
94
+ Stylus.compile(fixture).should_not match(/@media -stylus-debug-info/)
95
+ end
96
+ end
59
97
  end
@@ -8,10 +8,14 @@ module Helpers
8
8
 
9
9
  def create_app(options = {})
10
10
  Rails.application = nil
11
+
11
12
  Class.new(Rails::Application).tap do |app|
12
- app.config.assets.enabled = true
13
- app.config.assets.compress = true if options[:compress]
14
- app.config.assets.paths << fixture_root
13
+ assets = app.config.assets
14
+ assets.cache_store = :memory_store
15
+ assets.enabled = true
16
+ assets.compress = true if options[:compress]
17
+ assets.debug = true if options[:debug]
18
+ assets.paths << fixture_root
15
19
  app.config.active_support.deprecation = :log
16
20
  app.initialize!
17
21
  end
@@ -21,9 +25,23 @@ module Helpers
21
25
  File.expand_path('../../fixtures', __FILE__)
22
26
  end
23
27
 
28
+ def output_root
29
+ File.expand_path('../../cases', __FILE__)
30
+ end
31
+
24
32
  def fixture(name)
25
- stylus = File.read(File.join(fixture_root, "#{name}.styl"))
26
- css = File.read(File.join(fixture_root, "#{name}.css"))
27
- [stylus, css]
33
+ source = fixture_path(name)
34
+ output = css_path(name)
35
+ [source, output].map do |path|
36
+ File.read(path) if File.file?(path)
37
+ end
38
+ end
39
+
40
+ def css_path(name)
41
+ File.join(output_root, "#{name}.css")
42
+ end
43
+
44
+ def fixture_path(name)
45
+ File.join(fixture_root, "#{name}.styl")
28
46
  end
29
47
  end
metadata CHANGED
@@ -1,119 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: stylus
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0.pre
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Lucas Mazza
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-14 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: execjs
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153343380 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153343380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2153342840 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
29
+ requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 2
45
- - 0
46
- version: "2.0"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: railties
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2153342840
36
+ - !ruby/object:Gem::Dependency
37
+ name: railties
38
+ requirement: &2153342300 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
40
+ requirements:
55
41
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 3
60
- - 1
61
- - 0
42
+ - !ruby/object:Gem::Version
62
43
  version: 3.1.0
63
44
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: tzinfo
67
45
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2153342300
47
+ - !ruby/object:Gem::Dependency
48
+ name: tzinfo
49
+ requirement: &2153341920 !ruby/object:Gem::Requirement
69
50
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
77
55
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: yajl-ruby
81
56
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2153341920
58
+ - !ruby/object:Gem::Dependency
59
+ name: yajl-ruby
60
+ requirement: &2153341440 !ruby/object:Gem::Requirement
83
61
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
91
66
  type: :development
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: rocco
95
67
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2153341440
69
+ - !ruby/object:Gem::Dependency
70
+ name: rocco
71
+ requirement: &2153340900 !ruby/object:Gem::Requirement
97
72
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
105
77
  type: :development
106
- version_requirements: *id006
78
+ prerelease: false
79
+ version_requirements: *2153340900
107
80
  description: Bridge library to compile .styl stylesheets from ruby code.
108
- email:
81
+ email:
109
82
  - luc4smazza@gmail.com
110
83
  executables: []
111
-
112
84
  extensions: []
113
-
114
85
  extra_rdoc_files: []
115
-
116
- files:
86
+ files:
117
87
  - .gitignore
118
88
  - .travis.yml
119
89
  - CHANGELOG.md
@@ -130,16 +100,21 @@ files:
130
100
  - lib/stylus/runner.js
131
101
  - lib/stylus/tilt.rb
132
102
  - lib/stylus/version.rb
133
- - spec/fixtures/compressed.css
103
+ - spec/cases/compressed.css
104
+ - spec/cases/implicit.css
105
+ - spec/cases/import.css
106
+ - spec/cases/nib.css
107
+ - spec/cases/plugin.css
108
+ - spec/cases/simple.css
109
+ - spec/cases/stylesheet.css
134
110
  - spec/fixtures/compressed.styl
135
- - spec/fixtures/import.css
111
+ - spec/fixtures/debug.styl
112
+ - spec/fixtures/implicit.styl
136
113
  - spec/fixtures/import.styl
137
114
  - spec/fixtures/mixins/vendor.styl
138
- - spec/fixtures/nib.css
139
115
  - spec/fixtures/nib.styl
140
- - spec/fixtures/simple.css
116
+ - spec/fixtures/plugin.styl
141
117
  - spec/fixtures/simple.styl
142
- - spec/fixtures/stylesheet.css
143
118
  - spec/fixtures/stylesheet.styl
144
119
  - spec/generators/assets_generator_spec.rb
145
120
  - spec/generators/controller_generator_spec.rb
@@ -154,48 +129,44 @@ files:
154
129
  - stylus.gemspec
155
130
  homepage: https://github.com/lucasmazza/ruby-stylus
156
131
  licenses: []
157
-
158
132
  post_install_message:
159
133
  rdoc_options: []
160
-
161
- require_paths:
134
+ require_paths:
162
135
  - lib
163
- required_ruby_version: !ruby/object:Gem::Requirement
136
+ required_ruby_version: !ruby/object:Gem::Requirement
164
137
  none: false
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- hash: 3
169
- segments:
170
- - 0
171
- version: "0"
172
- required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
143
  none: false
174
- requirements:
175
- - - ">="
176
- - !ruby/object:Gem::Version
177
- hash: 3
178
- segments:
179
- - 0
180
- version: "0"
144
+ requirements:
145
+ - - ! '>'
146
+ - !ruby/object:Gem::Version
147
+ version: 1.3.1
181
148
  requirements: []
182
-
183
149
  rubyforge_project:
184
150
  rubygems_version: 1.8.10
185
151
  signing_key:
186
152
  specification_version: 3
187
153
  summary: Ruby Stylus Compiler
188
- test_files:
189
- - spec/fixtures/compressed.css
154
+ test_files:
155
+ - spec/cases/compressed.css
156
+ - spec/cases/implicit.css
157
+ - spec/cases/import.css
158
+ - spec/cases/nib.css
159
+ - spec/cases/plugin.css
160
+ - spec/cases/simple.css
161
+ - spec/cases/stylesheet.css
190
162
  - spec/fixtures/compressed.styl
191
- - spec/fixtures/import.css
163
+ - spec/fixtures/debug.styl
164
+ - spec/fixtures/implicit.styl
192
165
  - spec/fixtures/import.styl
193
166
  - spec/fixtures/mixins/vendor.styl
194
- - spec/fixtures/nib.css
195
167
  - spec/fixtures/nib.styl
196
- - spec/fixtures/simple.css
168
+ - spec/fixtures/plugin.styl
197
169
  - spec/fixtures/simple.styl
198
- - spec/fixtures/stylesheet.css
199
170
  - spec/fixtures/stylesheet.styl
200
171
  - spec/generators/assets_generator_spec.rb
201
172
  - spec/generators/controller_generator_spec.rb