stylus 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ docs
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.1.0 (2011-06-21)
4
+ [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.0.3...v0.1.0)
5
+
6
+ * Support for Stylus plugins via `Stylus.use`.
7
+ * Docco documentation live at [http://lucasmazza.github.com/ruby-stylus](http://lucasmazza.github.com/ruby-stylus).
8
+
9
+
3
10
  ### 0.0.3 (2011-06-06)
4
11
  [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.0.2...v0.0.3)
5
12
 
data/README.md CHANGED
@@ -21,6 +21,9 @@ Stylus.compile(File.read('application.styl'))
21
21
 
22
22
  # Converting old and boring CSS to awesome Stylus.
23
23
  Stylus.convert(File.new('file.css'))
24
+
25
+ # Importing plugins directly from Node.JS, like nib.
26
+ Stylus.use :nib
24
27
  ```
25
28
  ### With the Rails 3.1 Asset Pipeline.
26
29
 
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
+ require 'fileutils'
1
2
  require 'bundler'
2
3
  require 'rspec/core/rake_task'
4
+ require 'rocco/tasks'
3
5
  Bundler::GemHelper.install_tasks
4
6
 
5
7
  desc "Run specs"
@@ -7,5 +9,17 @@ RSpec::Core::RakeTask.new do |task|
7
9
  task.rspec_opts = ["-c -b"]
8
10
  end
9
11
 
12
+ task :default => :spec
10
13
 
11
- task :default => :spec
14
+ Rocco::make 'docs/'
15
+
16
+ desc 'Builds Rocco docs'
17
+ task :docs => :rocco do
18
+ Dir['docs/lib/**/*.html'].each do |file|
19
+ path = file.gsub(/lib/,'')
20
+ FileUtils.mkdir_p(File.dirname(path))
21
+ FileUtils.mv(file, path)
22
+ end
23
+ cp 'docs/stylus.html', 'docs/index.html', :preserve => true
24
+ end
25
+ directory 'docs/'
data/lib/stylus.rb CHANGED
@@ -1,40 +1,81 @@
1
+ ## Stylus
2
+
3
+ # `stylus` is a bridge between your Ruby code and the [Stylus](https://github.com/LearnBoost/stylus)
4
+ # library that runs on Node.js. It's aims to be a replacement for the
5
+ # [stylus_rails](https://github.com/lucasmazza/stylus_rails) gem and to support the Rails 3.1 asset pipeline
6
+ # (via [Tilt](https://github.com/rtomayko/tilt)) and other scenarios,
7
+ # backed by the [ExecJS](https://github.com/sstephenson/execjs) gem.module Stylus
8
+ ### Usage
9
+ # To compile a `.styl` file or an arbitrary String to .CSS using stylus, just use the `compile` method.
10
+ #
11
+ # `Stylus.compile(File.new('application.styl'))`
12
+ #
13
+ # A hash of options for the stylus API is accepted.
14
+ #
15
+ # `Stylus.compile(File.read('application.styl'), :compress => true)`
16
+ #
17
+
1
18
  require 'execjs'
2
19
  require 'stylus/version'
3
20
  require 'stylus/railtie' if defined?(::Rails)
4
-
5
21
  module Stylus
6
-
7
22
  class << self
8
23
  @@compress = false
9
24
  @@paths = []
25
+ @@plugins = {}
26
+
27
+ # Stores a list of plugins to import inside `Stylus`, with an optional hash.
28
+
29
+ def use(*options)
30
+ arguments = options.last.is_a?(Hash) ? options.pop : {}
31
+ options.each do |plugin|
32
+ @@plugins[plugin] = arguments
33
+ end
34
+ end
35
+ alias :plugin :use
36
+
37
+ # Retrieves the plugins registered by `use`.
38
+ def plugins
39
+ @@plugins
40
+ end
10
41
 
42
+ # Returns the global load path `Array` for your stylesheets.
11
43
  def paths
12
44
  @@paths
13
45
  end
14
46
 
47
+ # Replaces the global load path `Array` of paths.
15
48
  def paths=(val)
16
49
  @@paths = Array(val)
17
50
  end
18
51
 
52
+ # Returns the global compress flag.
19
53
  def compress
20
54
  @@compress
21
55
  end
22
56
 
57
+ # Sets the global flag for the `compress` option.
23
58
  def compress=(val)
24
59
  @@compress = val
25
60
  end
26
61
 
62
+ # Compiles a given input - a `File`, `StringIO`, `String` or anything that responds to `read`.
63
+ # Also accepts a hash of options that will be merged with the global configuration.
27
64
  def compile(source, options = {})
28
65
  source = source.read if source.respond_to?(:read)
29
66
  options = merge_options(options)
30
- context.call('compiler', source, options)
67
+ context.call('compiler', source, options, plugins)
31
68
  end
32
69
 
70
+ # Converts back an input of plain CSS to the `Stylus` syntax. The source object can be
71
+ # a `File`, `StringIO`, `String` or anything that responds to `read`.
33
72
  def convert(source)
34
73
  source = source.read if source.respond_to?(:read)
35
74
  context.call('convert', source)
36
75
  end
37
76
 
77
+ # Returns a `Hash` of the given `options` merged with the default configuration.
78
+ # It also concats the global load path with a given `Array`.
38
79
  def merge_options(options)
39
80
  _paths = options.delete(:paths)
40
81
  options = defaults.merge(options)
@@ -42,26 +83,30 @@ module Stylus
42
83
  options
43
84
  end
44
85
 
86
+ # Returns the default `Hash` of options.
45
87
  def defaults
46
88
  { :compress => self.compress, :paths => self.paths }
47
89
  end
48
90
 
91
+ # Return the gem version alongside with the current `Stylus` version of your system.
49
92
  def version
50
93
  "Stylus - gem #{VERSION} library #{context.call('version')}"
51
94
  end
52
95
 
53
96
  protected
97
+ # Returns the `ExecJS` execution context.
54
98
  def context
55
99
  @@_context ||= backend.compile(script)
56
100
  end
57
101
 
102
+ # Reads the default compiler script that `ExecJS` will execute.
58
103
  def script
59
104
  File.read(File.expand_path('../stylus/compiler.js',__FILE__))
60
105
  end
61
106
 
107
+ # We're targeting the Runtime directly so we don't mess with other
108
+ # gems using `ExecJS`.
62
109
  def backend
63
- # Targeting the Runtime directly so we don't mess with other
64
- # gems using ExecJS.
65
110
  @@_backend ||= ExecJS::Runtimes::Node
66
111
  end
67
112
  end
@@ -1,8 +1,14 @@
1
1
  var stylus = require('stylus');
2
2
 
3
- function compiler(str, options) {
3
+ function compiler(str, options, plugins) {
4
4
  var style = stylus(str, options);
5
5
  var output = '';
6
+
7
+ for(var name in plugins) {
8
+ var fn = require(name);
9
+ style.use(fn(plugins[name]));
10
+ }
11
+
6
12
  style.render(function(error, css) {
7
13
  if(error) throw error;
8
14
  output = css;
@@ -1,3 +1,7 @@
1
+ ### Stylus Railtie
2
+ # `Railtie` responsible for injecting `stylus` inside the
3
+ # Rails application and the `Sprockets` Asset Pipeline.
4
+
1
5
  require 'stylus/tilt'
2
6
 
3
7
  module Stylus
@@ -7,11 +11,14 @@ module Stylus
7
11
  config.app_generators.stylesheet_engine :styl
8
12
  next unless app.config.assets.enabled
9
13
 
14
+ # Loading `Sprockets` before Rails so we can register our own Engine.
10
15
  require 'sprockets'
11
16
  require 'sprockets/engines'
12
17
  Sprockets.register_engine '.styl', Tilt::StylusTemplate
13
18
  end
14
19
 
20
+ # Includes the `Rails` asset load path into `stylus` so any
21
+ # `.styl` file inside it can be imported.
15
22
  config.after_initialize do |app|
16
23
  Stylus.paths.concat app.assets.paths
17
24
  end
data/lib/stylus/tilt.rb CHANGED
@@ -1,11 +1,9 @@
1
+ ### Stylus template implementation for `Tilt`.
2
+ # It can be used by the `Rails` Asset Pipeline or `Sinatra` Applications.
1
3
  require 'tilt'
2
4
  require 'tilt/template'
3
5
 
4
6
  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
7
  class StylusTemplate < Template
10
8
  self.default_mime_type = 'text/css'
11
9
 
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,5 @@
1
+ background {
2
+ line-height: 1;
3
+ color: #000;
4
+ background: #fff;
5
+ }
@@ -0,0 +1,4 @@
1
+ @import 'nib'
2
+
3
+ background
4
+ reset-body()
data/spec/stylus_spec.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stylus do
4
+
5
+ before do
6
+ Stylus.plugins.clear
7
+ end
8
+
4
9
  it "compiles the given source" do
5
10
  input, output = fixture :simple
6
11
  Stylus.compile(input).should == output
@@ -43,4 +48,15 @@ describe Stylus do
43
48
  stylus, css = fixture :stylesheet
44
49
  Stylus.convert(css).should == stylus
45
50
  end
51
+
52
+ it "stores the given plugins" do
53
+ Stylus.use :one, :two, :argument => true
54
+ Stylus.should have(2).plugins
55
+ end
56
+
57
+ it "includes the given plugins" do
58
+ Stylus.use :nib
59
+ input, output = fixture :nib
60
+ Stylus.compile(input).should == output
61
+ end
46
62
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Mazza
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-06 00:00:00 -03:00
19
- default_executable:
18
+ date: 2011-06-22 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: execjs
@@ -105,6 +104,8 @@ files:
105
104
  - spec/fixtures/import.css
106
105
  - spec/fixtures/import.styl
107
106
  - spec/fixtures/mixins/vendor.styl
107
+ - spec/fixtures/nib.css
108
+ - spec/fixtures/nib.styl
108
109
  - spec/fixtures/simple.css
109
110
  - spec/fixtures/simple.styl
110
111
  - spec/fixtures/stylesheet.css
@@ -113,7 +114,6 @@ files:
113
114
  - spec/stylus_spec.rb
114
115
  - spec/tilt_spec.rb
115
116
  - stylus.gemspec
116
- has_rdoc: true
117
117
  homepage: https://github.com/lucasmazza/ruby-stylus
118
118
  licenses: []
119
119
 
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  requirements: []
144
144
 
145
145
  rubyforge_project:
146
- rubygems_version: 1.6.1
146
+ rubygems_version: 1.8.5
147
147
  signing_key:
148
148
  specification_version: 3
149
149
  summary: Ruby Stylus Compiler
@@ -153,6 +153,8 @@ test_files:
153
153
  - spec/fixtures/import.css
154
154
  - spec/fixtures/import.styl
155
155
  - spec/fixtures/mixins/vendor.styl
156
+ - spec/fixtures/nib.css
157
+ - spec/fixtures/nib.styl
156
158
  - spec/fixtures/simple.css
157
159
  - spec/fixtures/simple.styl
158
160
  - spec/fixtures/stylesheet.css