stylus_rails 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.1.0 (2011-03-28)
4
+ [Compare view](http://github.com/lucasmazza/stylus_rails/compare/v0.0.3...v0.1.0)
5
+
6
+ * Sinatra plugin added. Check the docs for usage and configuration;
7
+ * The rake task can be used standalone using `load 'stylus_rails/tasks/compile.rake'`;
8
+ * Compress flag changed from `-C` to `-c` ([see it here](https://github.com/LearnBoost/stylus/commit/910246859718e1817c9a76683f9a892e4cad4965)). Be sure to have stylus 0.9.0 or higher installed.
9
+
3
10
  ### 0.0.3 (2011-03-13)
4
11
  [Compare view](http://github.com/lucasmazza/stylus_rails/compare/v0.0.2...v0.0.3)
5
12
 
data/README.md CHANGED
@@ -1,15 +1,10 @@
1
1
  # Stylus for Rails apps
2
2
 
3
- A Rails helper to compile your [Stylus](https://github.com/LearnBoost/stylus) files located at `public/stylesheets/stylus/*.styl` between HTTP Requests during Rails development.
4
-
3
+ A Rails helper to compile your [Stylus](https://github.com/LearnBoost/stylus) files in your Rails apps.
5
4
 
6
5
  ## Installation
7
6
 
8
- Just add `gem 'stylus_rails'` To your `Gemfile`.
9
-
10
- ## Partials
11
-
12
- `stylus_rails` will skip all files starting with `_`, so you can use this naming convention on your partial files.
7
+ Just add `gem 'stylus_rails'` To your `Gemfile`. Rails will load the Stylus Railtie on your app on the development environment.
13
8
 
14
9
  ## Folders
15
10
 
@@ -19,6 +14,58 @@ By default, `stylus_rails` will compile all files existing at `public/stylesheet
19
14
  Stylus.directory = 'stylus'
20
15
  Stylus.compile_directory = File.join(Rails.root, 'public', 'stylesheets')
21
16
 
17
+ ## Partials
18
+
19
+ `stylus_rails` will skip all files starting with `_`, so you can use this naming convention on your partial files and import them on other files.
20
+
21
+ So, let's say that you have the following `_vendor.styl`:
22
+
23
+ border-radius()
24
+ -webkit-border-radius arguments
25
+ -moz-border-radius arguments
26
+ border-radius arguments
27
+
28
+ And a `application.styl`
29
+
30
+ @import '_mixins'
31
+ .button
32
+ border-radius 5px
33
+
34
+ Stylus will compile your `application.styl` into a `application.css` and your `_vendor.styl` will be ignored.
35
+
36
+ ## Sinatra
37
+
38
+ We all love [Sinatra](http://www.sinatrarb.com/), so we have a extension to add `stylus` to your Sinatra applications.
39
+ When using classic applications, just requiring `stylus_rails` will load the extension inside the Sinatra stack. When goin' modular, you will need to register it yourself.
40
+
41
+ require 'sinatra'
42
+ require 'stylus_rails'
43
+
44
+ class MyApp < Sinatra::Base
45
+ register Stylus::Sinatra
46
+
47
+ get '/' do
48
+ 'oh hai'
49
+ end
50
+ end
51
+
52
+ You can also customize the `root` and `compile_directory` options using the Sinatra settings:
53
+
54
+ # storing your .styl files in ./styl ...
55
+ set :stylus_root, File.dirname(__FILE__)
56
+ # and compiling to ./public/stylesheets
57
+ set :stylus_directory, File.join(setting.public, 'stylesheets')
58
+
59
+
60
+ ## Rake task
61
+
62
+ `stylus_rails` bundles a rake task `stylus:compile` to recompile your `.styl` files. Just add the following to your Rakefile:
63
+
64
+ require 'rubygems'
65
+ load 'stylus_rails/tasks/compile.rake'
66
+
67
+ The task is included automatically the Railtile on Rails apps.
68
+
22
69
  ## Changelog
23
70
  [here.](https://github.com/lucasmazza/stylus_rails/blob/master/CHANGELOG.md)
24
71
 
data/lib/stylus_rails.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'stylus_rails/core_ext/attribute_accessors'
1
2
  require 'stylus_rails/stylus'
2
3
  require 'stylus_rails/runner'
3
- require 'stylus_rails/railtie' if defined?(::Rails) && Rails.env.development?
4
+ require 'stylus_rails/railtie' if defined?(::Rails) && Rails.env.development?
5
+ require 'stylus_rails/sinatra' if defined?(::Sinatra) && ::Sinatra.send(:development?)
@@ -0,0 +1,18 @@
1
+ # Similar implementation to the ActiveSupport core extension.
2
+ # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
3
+ class Module
4
+
5
+ def mattr_accessor(sym)
6
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
7
+ @@#{sym} = nil unless defined? @@#{sym}
8
+
9
+ def self.#{sym}
10
+ @@#{sym}
11
+ end
12
+
13
+ def self.#{sym}=(obj)
14
+ @@#{sym} = obj
15
+ end
16
+ EOS
17
+ end
18
+ end
@@ -2,7 +2,7 @@ module Stylus
2
2
  class Railtie < ::Rails::Railtie
3
3
 
4
4
  rake_tasks do
5
- load "stylus_rails/tasks/tasks.rake"
5
+ load "stylus_rails/tasks/compile.rake"
6
6
  end
7
7
 
8
8
  initializer "stylus.reloader" do
@@ -11,7 +11,7 @@ module Stylus
11
11
  if `which stylus` && $?.success?
12
12
  Stylus.compile
13
13
  else
14
- Rails.logger.warn(Stylus.message)
14
+ Rails.logger.warn(Stylus.warning)
15
15
  end
16
16
  end
17
17
  end
@@ -11,25 +11,24 @@ module Stylus
11
11
 
12
12
  directories.each_pair do |directory, files|
13
13
  FileUtils.mkdir_p(directory) unless File.directory?(directory)
14
- system("stylus #{files.join(" ")} -o #{directory}#{' -C' if Stylus.compress?}")
14
+ system("stylus #{files.join(" ")} -o #{directory}#{' -c' if Stylus.compress?}")
15
15
  end
16
16
  end
17
17
 
18
18
  private
19
- def css_folder(path)
19
+ def output_folder(path)
20
+ dirname = File.dirname(path)
20
21
  if Stylus.compile_directory.nil?
21
- dirname = File.dirname(File.dirname(path))
22
+ File.dirname(dirname)
22
23
  else
23
- dirname = File.dirname(path)
24
- dirname.gsub!(File.join(Stylus.root, Stylus.directory), Stylus.compile_directory)
24
+ dirname.gsub(Stylus.folder, Stylus.compile_directory)
25
25
  end
26
- dirname
27
26
  end
28
27
 
29
28
  def group_paths
30
- directories = Hash.new { |h, k| h[k] = [] }
29
+ directories = Hash.new { |hash, key| hash[key] = [] }
31
30
  paths.each do |path|
32
- directories[css_folder(path)] << path
31
+ directories[output_folder(path)] << path
33
32
  end
34
33
  directories
35
34
  end
@@ -0,0 +1,17 @@
1
+ module Stylus
2
+ module Sinatra
3
+
4
+ def self.registered(app)
5
+ app.set :stylus_root, Proc.new { public? && File.join(public, 'stylesheets') }
6
+ app.set :stylus_directory, nil
7
+
8
+ app.before do
9
+ Stylus.root = settings.stylus_root if settings.stylus_root?
10
+ Stylus.compile_directory = settings.stylus_directory if settings.stylus_directory?
11
+ Stylus.compile
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ ::Sinatra.register(Stylus::Sinatra)
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
-
3
1
  module Stylus
4
2
 
5
3
  # Directory to look for .stylus files
@@ -8,8 +6,8 @@ module Stylus
8
6
 
9
7
  # Root path for the stylus directory lookup.
10
8
  mattr_accessor :root
11
- @@root = File.dirname(__FILE__)
12
-
9
+ @@root = Dir.pwd
10
+
13
11
  # Root path for the output
14
12
  mattr_accessor :compile_directory
15
13
  @@compile_directory = nil
@@ -27,17 +25,17 @@ module Stylus
27
25
  paths = Dir[File.join(folder, "**", "*.#{extension}")]
28
26
  Stylus::Runner.new(paths).call
29
27
  end
30
- def message
31
- <<-warn
32
28
 
33
- Warning: 'stylus' executable was not found on your system.
29
+ def warning
30
+ <<-WARN
31
+
32
+ Warning: The 'stylus' executable was not found on your system.
34
33
  Check stylus docs about installation at https://github.com/LearnBoost/stylus
35
34
  and be sure to have node.js and npm properly installed.
36
35
 
37
- warn
36
+ WARN
38
37
  end
39
38
 
40
- protected
41
39
  def folder
42
40
  File.join(root, directory)
43
41
  end
@@ -0,0 +1,9 @@
1
+ namespace :stylus do
2
+ prereq = defined?(::Rails) ? :environment : []
3
+ path = File.join(Stylus.root, Stylus.directory).gsub(Dir.pwd, ".")
4
+
5
+ desc "Compiles all the .#{Stylus.extension} inside '#{path}' into css files."
6
+ task :compile => prereq do
7
+ Stylus.compile
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/runner_spec.rb CHANGED
@@ -17,13 +17,13 @@ describe Stylus::Runner do
17
17
  parser = Stylus::Runner.new(fixtures("stylus/simple.styl", "stylus/_border_radius.styl"))
18
18
  parser.paths.should == fixture("stylus/simple.styl")
19
19
  end
20
-
20
+
21
21
  it "process nested files correctly" do
22
22
  parser = Stylus::Runner.new(fixtures("stylus/nested/bar.styl"))
23
23
  parser.paths.should == fixture("stylus/nested/bar.styl")
24
24
  end
25
25
  end
26
-
26
+
27
27
  describe "#call" do
28
28
  subject { Stylus::Runner.new(fixture("stylus/simple.styl")) }
29
29
  let(:stylus_file) { fixture("stylus/simple.styl").first }
@@ -47,11 +47,11 @@ describe Stylus::Runner do
47
47
 
48
48
  it "uses the compress flag when configured to" do
49
49
  Stylus.compress = true
50
- subject.should_receive(:system).with("stylus #{stylus_file} -o #{target_folder} -C")
50
+ subject.should_receive(:system).with("stylus #{stylus_file} -o #{target_folder} -c")
51
51
  subject.call
52
52
  end
53
53
  end
54
-
54
+
55
55
  describe "#call with different compile_dir" do
56
56
  subject { Stylus::Runner.new(fixture("stylus/simple.styl")) }
57
57
  let(:stylus_file) { fixture("stylus/simple.styl").first }
@@ -78,7 +78,7 @@ describe Stylus::Runner do
78
78
 
79
79
  it "uses the compress flag when configured to" do
80
80
  Stylus.compress = true
81
- subject.should_receive(:system).with("stylus #{stylus_file} -o #{target_folder} -C")
81
+ subject.should_receive(:system).with("stylus #{stylus_file} -o #{target_folder} -c")
82
82
  subject.call
83
83
  end
84
84
  end
data/stylus_rails.gemspec CHANGED
@@ -12,8 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Stylus stylesheets for Rails apps}
13
13
  s.description = %q{Rails plugin to compile .styl files between requests}
14
14
 
15
- s.add_dependency "activesupport", "~> 3.0"
16
- s.add_development_dependency "rspec", "~> 2.4"
15
+ s.add_development_dependency "rspec", "~> 2.0"
17
16
 
18
17
  s.files = `git ls-files`.split("\n")
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylus_rails
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease:
5
- version: 0.0.3
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Lucas Mazza
@@ -10,31 +15,24 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-03-13 00:00:00 -03:00
18
+ date: 2011-03-28 00:00:00 -03:00
14
19
  default_executable:
15
20
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: activesupport
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ~>
23
- - !ruby/object:Gem::Version
24
- version: "3.0"
25
- type: :runtime
26
- version_requirements: *id001
27
21
  - !ruby/object:Gem::Dependency
28
22
  name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
31
25
  none: false
32
26
  requirements:
33
27
  - - ~>
34
28
  - !ruby/object:Gem::Version
35
- version: "2.4"
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 0
33
+ version: "2.0"
36
34
  type: :development
37
- version_requirements: *id002
35
+ version_requirements: *id001
38
36
  description: Rails plugin to compile .styl files between requests
39
37
  email:
40
38
  - luc4smazza@gmail.com
@@ -52,10 +50,12 @@ files:
52
50
  - README.md
53
51
  - Rakefile
54
52
  - lib/stylus_rails.rb
53
+ - lib/stylus_rails/core_ext/attribute_accessors.rb
55
54
  - lib/stylus_rails/railtie.rb
56
55
  - lib/stylus_rails/runner.rb
56
+ - lib/stylus_rails/sinatra.rb
57
57
  - lib/stylus_rails/stylus.rb
58
- - lib/stylus_rails/tasks/tasks.rake
58
+ - lib/stylus_rails/tasks/compile.rake
59
59
  - lib/stylus_rails/version.rb
60
60
  - spec/fixtures/foo.css
61
61
  - spec/fixtures/output/foo.css
@@ -84,17 +84,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
87
90
  version: "0"
88
91
  required_rubygems_version: !ruby/object:Gem::Requirement
89
92
  none: false
90
93
  requirements:
91
94
  - - ">="
92
95
  - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
93
99
  version: "0"
94
100
  requirements: []
95
101
 
96
102
  rubyforge_project:
97
- rubygems_version: 1.5.2
103
+ rubygems_version: 1.4.2
98
104
  signing_key:
99
105
  specification_version: 3
100
106
  summary: Stylus stylesheets for Rails apps
@@ -1,6 +0,0 @@
1
- namespace :stylus do
2
- desc "Compiles all the .#{Stylus.extension} inside 'public/stylesheets/#{Stylus.directory}' into css files."
3
- task :compile => :environment do
4
- Stylus.compile
5
- end
6
- end