stylus 0.0.1
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 +4 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +11 -0
- data/lib/stylus.rb +64 -0
- data/lib/stylus/compiler.js +15 -0
- data/lib/stylus/railtie.rb +14 -0
- data/lib/stylus/tilt.rb +21 -0
- data/lib/stylus/version.rb +3 -0
- data/spec/fixtures/compressed.css +1 -0
- data/spec/fixtures/compressed.styl +2 -0
- data/spec/fixtures/import.css +5 -0
- data/spec/fixtures/import.styl +4 -0
- data/spec/fixtures/mixins/vendor.styl +4 -0
- data/spec/fixtures/simple.css +3 -0
- data/spec/fixtures/simple.styl +2 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/stylus_spec.rb +41 -0
- data/spec/tilt_spec.rb +26 -0
- data/stylus.gemspec +24 -0
- metadata +152 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2011 Lucas Mazza <luc4smazza@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Ruby Stylus
|
2
|
+
|
3
|
+
`stylus` is a bridge between your Ruby code and the [Stylus](https://github.com/LearnBoost/stylus) library that runs on Node.js. It's aims to be a replacement for the [stylus_rails](https://github.com/lucasmazza/stylus_rails) gem and to support the Rails 3.1 asset pipeline (via [Tilt](https://github.com/rtomayko/tilt)) and other scenarios, backed by the [ExecJS](https://github.com/sstephenson/execjs) gem.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
First, be sure to have stylus installed in your system. If needed, check the project [README](https://github.com/learnboost/stylus) for more information.
|
8
|
+
|
9
|
+
require 'stylus'
|
10
|
+
|
11
|
+
# Accepts a raw string or an IO object (File, StringIO or anything that responds to 'read').
|
12
|
+
Stylus.compile(File.new('application.styl')) # returns the compiled stylesheet.
|
13
|
+
|
14
|
+
# Using the compress option, removing most newlines from the code.
|
15
|
+
Stylus.compile(File.read('application.styl'), :compress => true)
|
16
|
+
|
17
|
+
# Or use the global compress flag
|
18
|
+
Stylus.compress = true
|
19
|
+
Stylus.compile(File.read('application.styl'))
|
20
|
+
|
21
|
+
### With the Rails 3.1 Asset Pipeline.
|
22
|
+
|
23
|
+
Just add the `stylus` gem to your Gemfile and the gem will hook itself into Sprockets and enable the `.styl` templates for your stylesheets.
|
24
|
+
|
25
|
+
## Changelog
|
26
|
+
[here.](https://github.com/lucasmazza/ruby-stylus/blob/master/CHANGELOG.md)
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
(The MIT License)
|
31
|
+
|
32
|
+
Copyright (c) 2011 Lucas Mazza <luc4smazza@gmail.com>
|
33
|
+
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
35
|
+
a copy of this software and associated documentation files (the
|
36
|
+
'Software'), to deal in the Software without restriction, including
|
37
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
38
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
39
|
+
permit persons to whom the Software is furnished to do so, subject to
|
40
|
+
the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be
|
43
|
+
included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
46
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
47
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
48
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
49
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
50
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
51
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/stylus.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'execjs'
|
2
|
+
require 'stylus/version'
|
3
|
+
require 'stylus/railtie' if defined?(::Rails)
|
4
|
+
|
5
|
+
module Stylus
|
6
|
+
|
7
|
+
class << self
|
8
|
+
@@compress = false
|
9
|
+
@@paths = []
|
10
|
+
|
11
|
+
def paths
|
12
|
+
@@paths
|
13
|
+
end
|
14
|
+
|
15
|
+
def paths=(val)
|
16
|
+
@@paths = Array(val)
|
17
|
+
end
|
18
|
+
|
19
|
+
def compress
|
20
|
+
@@compress
|
21
|
+
end
|
22
|
+
|
23
|
+
def compress=(val)
|
24
|
+
@@compress = val
|
25
|
+
end
|
26
|
+
|
27
|
+
def compile(source, options = {})
|
28
|
+
source = source.read if source.respond_to?(:read)
|
29
|
+
options = merge_options(options)
|
30
|
+
context.call('compiler', source, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def merge_options(options)
|
34
|
+
_paths = options.delete(:paths)
|
35
|
+
options = defaults.merge(options)
|
36
|
+
options[:paths] = paths.concat(Array(_paths))
|
37
|
+
options
|
38
|
+
end
|
39
|
+
|
40
|
+
def defaults
|
41
|
+
{ :compress => self.compress, :paths => self.paths }
|
42
|
+
end
|
43
|
+
|
44
|
+
def version
|
45
|
+
"Stylus - gem #{VERSION} library #{context.call('version')}"
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
def context
|
50
|
+
@@_context ||= backend.compile(script)
|
51
|
+
end
|
52
|
+
|
53
|
+
def script
|
54
|
+
path = File.expand_path(File.dirname(__FILE__))
|
55
|
+
File.read(File.join(path, 'stylus', 'compiler.js'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def backend
|
59
|
+
# Targeting the Runtime directly so we don't mess with other
|
60
|
+
# gems using ExecJS.
|
61
|
+
@@_backend ||= ExecJS::Runtimes::Node
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
var stylus = require('stylus');
|
2
|
+
|
3
|
+
function compiler(str, options) {
|
4
|
+
var style = stylus(str, options);
|
5
|
+
var output = '';
|
6
|
+
style.render(function(error, css) {
|
7
|
+
if(error) throw error;
|
8
|
+
output = css;
|
9
|
+
})
|
10
|
+
return output;
|
11
|
+
}
|
12
|
+
|
13
|
+
function version() {
|
14
|
+
return stylus.version;
|
15
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'stylus/tilt'
|
2
|
+
|
3
|
+
module Stylus
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
config.after_initialize do |app|
|
7
|
+
if app.assets
|
8
|
+
Stylus.paths.concat app.assets.paths
|
9
|
+
app.assets.register_engine '.styl', Tilt::StylusTemplate
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/lib/stylus/tilt.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'tilt/template'
|
3
|
+
|
4
|
+
module Tilt
|
5
|
+
# Stylus template implementation. See:
|
6
|
+
# http://learnboost.github.com/stylus/
|
7
|
+
#
|
8
|
+
# Stylus templates do not support object scopes, locals, or yield.
|
9
|
+
class StylusTemplate < Template
|
10
|
+
self.default_mime_type = 'text/css'
|
11
|
+
|
12
|
+
def prepare
|
13
|
+
end
|
14
|
+
|
15
|
+
def evaluate(scope, locals, &block)
|
16
|
+
Stylus.compile(data, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Tilt.register Tilt::StylusTemplate, 'styl'
|
@@ -0,0 +1 @@
|
|
1
|
+
body{padding:5px}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'stylus'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
|
5
|
+
config.after :each do
|
6
|
+
Stylus.compress = false
|
7
|
+
Stylus.paths = []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture_root
|
12
|
+
File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures')
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture(name)
|
16
|
+
stylus = File.read(File.join(fixture_root, "#{name}.styl"))
|
17
|
+
css = File.read(File.join(fixture_root, "#{name}.css"))
|
18
|
+
[stylus, css]
|
19
|
+
end
|
20
|
+
|
data/spec/stylus_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stylus do
|
4
|
+
it "compiles the given source" do
|
5
|
+
input, output = fixture :simple
|
6
|
+
Stylus.compile(input).should == output
|
7
|
+
end
|
8
|
+
|
9
|
+
it "accepts a IO object as source" do
|
10
|
+
input, output = fixture :simple
|
11
|
+
input = StringIO.new(input)
|
12
|
+
Stylus.compile(input).should == output
|
13
|
+
end
|
14
|
+
|
15
|
+
it "compress the file when the compress flag is given" do
|
16
|
+
input, output = fixture :compressed
|
17
|
+
Stylus.compile(input, :compress => true).should == output
|
18
|
+
end
|
19
|
+
|
20
|
+
it "uses the class level compress flag" do
|
21
|
+
Stylus.compress = true
|
22
|
+
input, output = fixture :compressed
|
23
|
+
Stylus.compile(input).should == output
|
24
|
+
end
|
25
|
+
|
26
|
+
it "imports the given paths" do
|
27
|
+
path = fixture_root
|
28
|
+
input, output = fixture :import
|
29
|
+
Stylus.compile(input, :paths => path).should == output
|
30
|
+
end
|
31
|
+
|
32
|
+
it "handles the import paths globally" do
|
33
|
+
Stylus.paths << fixture_root
|
34
|
+
input, output = fixture :import
|
35
|
+
Stylus.compile(input).should == output
|
36
|
+
end
|
37
|
+
|
38
|
+
it "outputs both gem and library version" do
|
39
|
+
Stylus.version.should =~ /Stylus - gem .+ library .+/
|
40
|
+
end
|
41
|
+
end
|
data/spec/tilt_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stylus/tilt'
|
3
|
+
|
4
|
+
describe Tilt::StylusTemplate do
|
5
|
+
|
6
|
+
it "is registered for .styl files" do
|
7
|
+
Tilt['application.styl'].should == Tilt::StylusTemplate
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a content-type" do
|
11
|
+
Tilt::StylusTemplate.default_mime_type.should == 'text/css'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "compiles the given source" do
|
15
|
+
input, output = fixture :simple
|
16
|
+
template = Tilt::StylusTemplate.new { |t| input }
|
17
|
+
template.render.should == output
|
18
|
+
end
|
19
|
+
|
20
|
+
it "compiles with the compress option" do
|
21
|
+
input, output = fixture :compressed
|
22
|
+
template = Tilt::StylusTemplate.new(:compress => true) { |t| input }
|
23
|
+
template.render.should == output
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/stylus.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "stylus/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "stylus"
|
7
|
+
s.version = Stylus::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Lucas Mazza"]
|
10
|
+
s.email = ["luc4smazza@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/lucasmazza/ruby-stylus"
|
12
|
+
s.summary = %q{Ruby Stylus Compiler}
|
13
|
+
s.description = %q{Bridge library to compile .styl stylesheets from ruby code.}
|
14
|
+
|
15
|
+
s.add_dependency 'execjs'
|
16
|
+
s.add_development_dependency 'rspec', '~>2.0'
|
17
|
+
s.add_development_dependency 'tilt'
|
18
|
+
s.add_development_dependency 'yajl-ruby'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stylus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lucas Mazza
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-19 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: execjs
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
version: "2.0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: tilt
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: yajl-ruby
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: Bridge library to compile .styl stylesheets from ruby code.
|
78
|
+
email:
|
79
|
+
- luc4smazza@gmail.com
|
80
|
+
executables: []
|
81
|
+
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files: []
|
85
|
+
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- CHANGELOG.md
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/stylus.rb
|
94
|
+
- lib/stylus/compiler.js
|
95
|
+
- lib/stylus/railtie.rb
|
96
|
+
- lib/stylus/tilt.rb
|
97
|
+
- lib/stylus/version.rb
|
98
|
+
- spec/fixtures/compressed.css
|
99
|
+
- spec/fixtures/compressed.styl
|
100
|
+
- spec/fixtures/import.css
|
101
|
+
- spec/fixtures/import.styl
|
102
|
+
- spec/fixtures/mixins/vendor.styl
|
103
|
+
- spec/fixtures/simple.css
|
104
|
+
- spec/fixtures/simple.styl
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/stylus_spec.rb
|
107
|
+
- spec/tilt_spec.rb
|
108
|
+
- stylus.gemspec
|
109
|
+
homepage: https://github.com/lucasmazza/ruby-stylus
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Ruby Stylus Compiler
|
142
|
+
test_files:
|
143
|
+
- spec/fixtures/compressed.css
|
144
|
+
- spec/fixtures/compressed.styl
|
145
|
+
- spec/fixtures/import.css
|
146
|
+
- spec/fixtures/import.styl
|
147
|
+
- spec/fixtures/mixins/vendor.styl
|
148
|
+
- spec/fixtures/simple.css
|
149
|
+
- spec/fixtures/simple.styl
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/stylus_spec.rb
|
152
|
+
- spec/tilt_spec.rb
|