stylus 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1566bf07cbd7a850d8d71b919559eb5a2fb9b017
4
- data.tar.gz: 5125d3def706e75fd455a298b5bf9fb4885ad472
3
+ metadata.gz: a60b09a5dc38e150643c2c4d99b9f5c2108a3edc
4
+ data.tar.gz: 365863ee6e4bf807677fe6854edb132490c6306f
5
5
  SHA512:
6
- metadata.gz: 7049f9b42626a132a83daa1db13721e31fbc248410a5f844b5e626b322419eea3e828c746ab613b55a8f8ae3633184b13c88eae33a897cc22762f162685f1eba
7
- data.tar.gz: 17e72872fbbf27f0b64d2dfe3b5f5dbf7130398897a7f1965193b6a64256f632f56aacea71d5de5ad016f3d2f69f2de21edbbeba8987134c6caede12f326be54
6
+ metadata.gz: bccc161871310118e15ac03a5185b76e2f5368fb3d62f8f7f961d144623a4e0756360ddec5bef778ee432f5e75993cf91522c76438028cdab04d1065736e82f5
7
+ data.tar.gz: 1217da2209684e7433d57d142c870afb086f41da108d5d15077ac55eba633b11c3c08046098ebfef26ed7d23be54ea789a7631265a88d0b003709dbf3561db38
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2012 Lucas Mazza <luc4smazza@gmail.com>
3
+ Copyright (c) 2012-2015 Lucas Mazza; 2015 Forge Software, LLC.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
19
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
20
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
21
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Ruby Stylus
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/lucasmazza/ruby-stylus.png)](http://travis-ci.org/lucasmazza/ruby-stylus)
3
+ [![Gem Version](https://badge.fury.io/rb/stylus.svg)](http://badge.fury.io/rb/stylus)
4
+ [![Build Status](https://travis-ci.org/forgecrafted/ruby-stylus.svg?branch=master)](https://travis-ci.org/forgecrafted/ruby-stylus)
5
+ [![Coverage Status](https://coveralls.io/repos/forgecrafted/ruby-stylus/badge.svg)](https://coveralls.io/r/forgecrafted/ruby-stylus)
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 Rails 4 applications. (if you are working with Rails 3, check the [0-7-stable](https://github.com/lucasmazza/ruby-stylus/tree/0-7-stable) branch.)
7
+ `stylus` is a bridge between Ruby and the [Stylus](https://github.com/stylus/stylus) library that runs on [node.js](http://nodejs.org). It has support for Rails 4 applications. (if you are working with Rails 3, check the [0-7-stable](https://github.com/forgecrafted/ruby-stylus/tree/0-7-stable) branch.)
6
8
 
7
9
  ## Installation
8
10
 
@@ -12,17 +14,17 @@ If you have a `Gemfile`:
12
14
  gem 'stylus'
13
15
  ```
14
16
 
15
- or if you don't have a Gemfile, install it in your system:
17
+ or install it on your system:
16
18
 
17
19
  ```
18
20
  gem install stylus
19
21
  ```
20
22
 
21
- Since version 0.3.0, the [stylus-source](https://github.com/railsjedi/ruby-stylus-source) packages the Stylus source into a Rubygem, so it will be available after installing this gem. The `ruby-source` version will follow the Stylus releases and their versions.
23
+ The [ruby-stylus-source](https://github.com/forgecrafted/ruby-stylus-source) packages the Stylus source into a gem, and is installed as a dependency of this gem. Versions of `ruby-stylus-source` follow Stylus releases and their versions.
22
24
 
23
- You can replace the Stylus code by placing another version of Stylus on `./node_modules/stylus`, and it will be used instead of the version bundled inside the gem.
25
+ You can manually replace the Stylus code by placing another version of Stylus on `./node_modules/stylus`, and it will be used instead of the version bundled inside the gem.
24
26
 
25
- **But remember**, you still need the `node` command available on your runtime for this gem to work. `stylus` is also compatible with the Heroku Cedar stack, enabling asset compilation during the deployment of your apps. You can check the [Node.js wiki](https://github.com/joyent/node/wiki/Quick-and-easy-installation) for more info.
27
+ **REMEMBER**, you still need the `node` command available on your runtime for this gem to work. This gem is also compatible with the Heroku Cedar stack, enabling asset compilation during the deployment of your apps. You can check the [Node.js wiki](https://github.com/joyent/node/wiki/Quick-and-easy-installation) for more info.
26
28
 
27
29
  ## Usage
28
30
 
@@ -52,16 +54,31 @@ Stylus.use :nib
52
54
  # a `:filename` option so Stylus can locate your stylesheet for proper inspection.
53
55
  Stylus.debug = true
54
56
  ```
57
+
55
58
  ### With Rails and the Asset Pipeline.
56
59
 
57
60
  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.
58
61
 
59
62
  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 load path (usually `app/assets`, `lib/assets`, `vendor/assets` and the `assets` folder inside any other gem) will be available to your stylesheets.
60
63
 
61
- If the `config.assets.debug` is turned on, Stylus will emit extra 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.
64
+ If the `config.assets.debug` is turned on, Stylus will emit extra comments on your stylesheets to help debugging and inspection using the `linenos` and `firebug` options. Check the [FireStylus extension for Firebug](https://github.com/stylus/stylus/blob/master/docs/firebug.md) for more info.
62
65
 
63
- ### `@import` and file extensions.
66
+ It should be noted that in a default rails project you should also remove the sass-rails gem. This gem includes the tilt gem required by the asset pipeline so you should also add that gem back on its own.
67
+
68
+ ```
69
+ # gem 'sass-rails'
70
+ gem 'tilt'
71
+ ```
72
+
73
+ For compilation of assets during deployment (e.g. for heroku) you'll also need to enable/add the rubyracer gem.
64
74
 
75
+ ```
76
+ # See https://github.com/rails/execjs#readme for more supported runtimes
77
+ gem 'therubyracer', platforms: :ruby
78
+ ```
79
+
80
+ ### `@import` and file extensions.
81
+
65
82
  Stylus and Sprockets file lookups differ on the subject of handling file extensions, and that may hurt a bit.
66
83
 
67
84
  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.
@@ -73,34 +90,31 @@ If you use Stylus `@import` to expose variables, mixins or just to concatenate c
73
90
 
74
91
  ### `@import` dependency resolution
75
92
 
76
- Because of how sprockets handles dependency resolution for computing
77
- file changes and expiring caches, it is necessary to specify the full import path in your import statements.
93
+ Because of how sprockets handles dependency resolution for computing file changes and expiring caches, it is necessary to specify the full import path in your import statements.
78
94
 
79
95
  That is, given:
80
96
 
81
- app/assets/stylesheets/
82
- app/assets/stylesheets/file.styl
83
- app/assets/stylesheets/some_directory/other_file.styl
84
- app/assets/stylesheets/some_directory/another_file.styl
85
-
86
- Imports should be specified with the full path relative to
87
- `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`.
88
-
89
- `app/assets/stylesheets/file.styl`
97
+ ```
98
+ app/assets/stylesheets/
99
+ app/assets/stylesheets/file.styl
100
+ app/assets/stylesheets/some_directory/other_file.styl
101
+ app/assets/stylesheets/some_directory/another_file.styl
102
+ ```
90
103
 
91
- @import "some_directory/other_file.styl"
92
- ...
104
+ Imports should be specified with the full path relative to `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`.
93
105
 
94
- `app/assets/stylesheets/some_directory/other_file.styl`
106
+ ```ruby
107
+ # app/assets/stylesheets/file.styl
108
+ @import "some_directory/other_file.styl"
95
109
 
96
- @import "some_directory/another_file.styl"
97
- ...
110
+ # app/assets/stylesheets/some_directory/other_file.styl
111
+ @import "some_directory/another_file.styl"
112
+ ```
98
113
 
99
114
  This will ensure that all changes get reflected when any of the imported
100
115
  files change. If you don't do this, sprockets will not accurately be
101
116
  able to keep track of your dependencies.
102
117
 
103
-
104
118
  ### Standalone Sprockets usage
105
119
 
106
120
  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.
@@ -123,7 +137,7 @@ map('/assets') { run assets.index }
123
137
 
124
138
  ## Plugins
125
139
 
126
- [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 the 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`:
140
+ [Stylus](https://github.com/stylus/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 the same as described above for [Stylus](https://github.com/stylus/stylus) (since they're all npm packages after all). You can hook them up on your Ruby code with `Stylus.use`:
127
141
 
128
142
  ```ruby
129
143
  Stylus.use :fingerprint, literal: 'caa8c262e23268d2a7062c6217202343b84f472b'
@@ -137,34 +151,18 @@ stylus(file).use(fingerprint({literal:'caa8c262e23268d2a7062c6217202343b84f472b'
137
151
 
138
152
  ## Questions, Bugs or Support
139
153
 
140
- You can [submit an issue](https://github.com/lucasmazza/ruby-stylus/issues) or ping me on [GitHub](http://github.com/lucasmazza) or [Twitter](http://twitter.com/lucasmazza).
154
+ [Drop us a line in the issues section](https://github.com/forgecrafted/ruby-stylus/issues).
141
155
 
142
- For more info about the [Stylus](https://github.com/LearnBoost/stylus) syntax and its features you can check the [project repository](https://github.com/learnboost/stylus) and the docs on the [GitHub page](http://learnboost.github.com/stylus).
156
+ **Be sure to include sample code that reproduces the problem.**
143
157
 
144
- ## Changelog
145
- [It's available here.](https://github.com/lucasmazza/ruby-stylus/blob/master/CHANGELOG.md)
146
-
147
- ## License
158
+ For more info about Stylus syntax and its features, you can check the [project repository](https://github.com/stylus/stylus), and the docs on the [GitHub page](http://stylus.github.io/stylus/).
148
159
 
149
- (The MIT License)
160
+ ## Changelog
150
161
 
151
- Copyright (c) 2012-2013 Lucas Mazza &lt;luc4smazza@gmail.com&gt;
162
+ [Available here.](https://github.com/forgecrafted/ruby-stylus/blob/master/CHANGELOG.md)
152
163
 
153
- Permission is hereby granted, free of charge, to any person obtaining
154
- a copy of this software and associated documentation files (the
155
- 'Software'), to deal in the Software without restriction, including
156
- without limitation the rights to use, copy, modify, merge, publish,
157
- distribute, sublicense, and/or sell copies of the Software, and to
158
- permit persons to whom the Software is furnished to do so, subject to
159
- the following conditions:
164
+ ## License
160
165
 
161
- The above copyright notice and this permission notice shall be
162
- included in all copies or substantial portions of the Software.
166
+ Copyright (c) 2012-2015 Lucas Mazza; 2015 Forge Software, LLC.
163
167
 
164
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
165
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
166
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
167
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
168
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
169
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
170
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
168
+ This is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -23,11 +23,12 @@ require 'stylus/railtie' if defined?(::Rails)
23
23
  module Stylus
24
24
  extend Runtime
25
25
  class << self
26
- @@compress = false
27
- @@debug = false
28
- @@paths = []
29
- @@imports = []
30
- @@plugins = {}
26
+ @@compress = false
27
+ @@debug = false
28
+ @@paths = []
29
+ @@imports = []
30
+ @@definitions = {}
31
+ @@plugins = {}
31
32
 
32
33
  # Stores a list of plugins to import inside `Stylus`, with an optional hash.
33
34
  def use(*options)
@@ -47,11 +48,23 @@ module Stylus
47
48
  end
48
49
  alias :imports :import
49
50
 
51
+
52
+ # Stores a list of defined variables to create on every compile process.
53
+ def define(variable, value, options = {})
54
+ literal = true if options[:literal]
55
+ @@definitions[variable] = { value: value, literal: literal }
56
+ end
57
+
50
58
  # Retrieves all the registered plugins.
51
59
  def plugins
52
60
  @@plugins
53
61
  end
54
62
 
63
+ # Retrieves all the registered variables.
64
+ def definitions
65
+ @@definitions
66
+ end
67
+
55
68
  # Returns the global load path `Array` for your stylesheets.
56
69
  def paths
57
70
  @@paths
@@ -103,7 +116,7 @@ module Stylus
103
116
  end
104
117
  source = source.read if source.respond_to?(:read)
105
118
  options = merge_options(options)
106
- exec('compile', source, options, plugins, imports)
119
+ exec('compile', source, options, plugins, imports, definitions)
107
120
  end
108
121
 
109
122
  # Converts back an input of plain CSS to the `Stylus` syntax. The source object can be
@@ -1,6 +1,6 @@
1
1
  var stylus = require('stylus');
2
2
 
3
- function compile(str, options, plugins, imports) {
3
+ function compile(str, options, plugins, imports, definitions) {
4
4
  var style = stylus(str, options);
5
5
  var output = '';
6
6
 
@@ -8,10 +8,22 @@ function compile(str, options, plugins, imports) {
8
8
  var fn = require(name);
9
9
  style.use(fn(plugins[name]));
10
10
  }
11
+
11
12
  imports.forEach(function(path) {
12
13
  style.import(path);
13
14
  })
14
15
 
16
+ for(var definition in definitions) {
17
+ obj = definitions[definition];
18
+ value = obj.value
19
+
20
+ if(obj.literal) {
21
+ value = new stylus.nodes.Literal(value);
22
+ }
23
+
24
+ style.define(definition, value);
25
+ }
26
+
15
27
  style.render(function(error, css) {
16
28
  if(error) throw error;
17
29
  output = css;
@@ -3,6 +3,7 @@ require 'stylus/tilt/stylus'
3
3
  module Stylus
4
4
  module Rails
5
5
  class StylusTemplate < ::Tilt::StylusTemplate
6
+ EXCLUDED_EXTENSIONS = %w{ css js gzip json md html }
6
7
 
7
8
  # Public: The default mime type for stylesheets.
8
9
  self.default_mime_type = 'text/css'
@@ -36,7 +37,8 @@ asset-path(key)
36
37
  # Returns string representations of hash in Stylus syntax
37
38
  def assets_hash(scope)
38
39
  @assets_hash ||= scope.environment.each_logical_path.each_with_object({ :url => '', :path => '' }) do |logical_path, assets_hash|
39
- unless File.extname(logical_path) =~ /^(\.(css|js)|)$/
40
+ extensions = EXCLUDED_EXTENSIONS.join('|')
41
+ unless File.extname(logical_path) =~ Regexp.new("^(\.(#{extensions})|)$")
40
42
  path_to_asset = scope.path_to_asset(logical_path)
41
43
  assets_hash[:url] << "('#{logical_path}' url(\"#{path_to_asset}\")) "
42
44
  assets_hash[:path] << "('#{logical_path}' \"#{path_to_asset}\") "
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'rails'
2
5
  require 'rails/generators/test_case'
3
6
 
@@ -21,6 +24,7 @@ RSpec.configure do |config|
21
24
  Stylus.debug = false
22
25
  Stylus.paths = []
23
26
  Stylus.plugins.clear
27
+ Stylus.definitions.clear
24
28
  Stylus.imports.clear
25
29
  end
26
30
  end
@@ -62,6 +62,23 @@ describe Stylus do
62
62
  expect(Stylus.compile(input)).to eq(output)
63
63
  end
64
64
 
65
+ it 'stores the define calls' do
66
+ Stylus.define "mystring", "test"
67
+ expect(Stylus).to have(1).definitions
68
+ end
69
+
70
+ it 'defines a global variable string' do
71
+ Stylus.define "mystring", "test"
72
+ input, output = fixture(:definition)
73
+ expect(Stylus.compile(input)).to match(/content: 'test'/)
74
+ end
75
+
76
+ it 'defines a global variable literal' do
77
+ Stylus.define "mystring", "red", :literal => true
78
+ input, output = fixture(:definition)
79
+ expect(Stylus.compile(input)).to match(/content: red/)
80
+ end
81
+
65
82
  it 'includes and imports "nib" automatically' do
66
83
  Stylus.nib = true
67
84
  input, output = fixture(:nib)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Mazza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.0
41
55
  description: Bridge library to compile .styl stylesheets from ruby code.
42
56
  email:
43
57
  - luc4smazza@gmail.com
@@ -99,25 +113,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
113
  version: '0'
100
114
  requirements: []
101
115
  rubyforge_project:
102
- rubygems_version: 2.2.0
116
+ rubygems_version: 2.5.1
103
117
  signing_key:
104
118
  specification_version: 4
105
119
  summary: Ruby Stylus Compiler
106
120
  test_files:
107
- - spec/generators/assets_generator_spec.rb
108
- - spec/generators/controller_generator_spec.rb
109
- - spec/generators/scaffold_generator_spec.rb
110
- - spec/import_processor_spec.rb
111
- - spec/rails_spec.rb
112
- - spec/runtime_spec.rb
113
- - spec/spec_helper.rb
114
- - spec/sprockets_spec.rb
115
- - spec/stylus_spec.rb
121
+ - spec/support/helpers.rb
122
+ - spec/support/matchers.rb
116
123
  - spec/support/generators/test_case.rb
117
- - spec/support/generators/tmp/app/controllers/posts_controller.rb
118
124
  - spec/support/generators/tmp/app/helpers/posts_helper.rb
125
+ - spec/support/generators/tmp/app/controllers/posts_controller.rb
119
126
  - spec/support/generators/tmp/config/routes.rb
120
- - spec/support/helpers.rb
121
- - spec/support/matchers.rb
122
127
  - spec/tilt/rails_spec.rb
123
128
  - spec/tilt/stylus_spec.rb
129
+ - spec/runtime_spec.rb
130
+ - spec/rails_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/stylus_spec.rb
133
+ - spec/sprockets_spec.rb
134
+ - spec/generators/assets_generator_spec.rb
135
+ - spec/generators/scaffold_generator_spec.rb
136
+ - spec/generators/controller_generator_spec.rb
137
+ - spec/import_processor_spec.rb