stylus_rails 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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stylus-rails.gemspec
4
+ gemspec
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.
@@ -0,0 +1,41 @@
1
+ # Stylus for Rails apps
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
+
5
+
6
+ ## Installation
7
+
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.
13
+
14
+ ## Folders
15
+
16
+ By default, `stylus_rails` will compile all files existing at `public/stylesheets/stylus` to the `public/stylesheets` folder. For instance, `public/stylesheets/stylus/application.styl` would generate `public/stylesheets/application.css`.
17
+
18
+ ## License
19
+
20
+ (The MIT License)
21
+
22
+ Copyright (c) 2011 Lucas Mazza &lt;luc4smazza@gmail.com&gt;
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining
25
+ a copy of this software and associated documentation files (the
26
+ 'Software'), to deal in the Software without restriction, including
27
+ without limitation the rights to use, copy, modify, merge, publish,
28
+ distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is furnished to do so, subject to
30
+ the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be
33
+ included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
36
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
39
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ desc "Run specs"
6
+ RSpec::Core::RakeTask.new do |task|
7
+ task.rspec_opts = ["-c"]
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ require 'stylus_rails/stylus'
2
+ require 'stylus_rails/runner'
3
+ require 'stylus_rails/railtie' if defined?(::Rails) && Rails.env.development?
@@ -0,0 +1,19 @@
1
+ module Stylus
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ rake_tasks do
5
+ load "stylus_rails/tasks/tasks.rake"
6
+ end
7
+
8
+ initializer "stylus.reloader" do
9
+ Stylus.root = File.join(Rails.public_path,"stylesheets")
10
+ config.to_prepare do
11
+ if `which stylus` && $?.success?
12
+ Stylus.compile
13
+ else
14
+ Rails.logger.warn(Stylus.message)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Stylus
2
+ class Runner
3
+ attr_reader :paths
4
+
5
+ def initialize(*paths)
6
+ @paths = paths.flatten.select { |path| should_parse?(path) }
7
+ end
8
+
9
+ def call
10
+ paths.each do |file|
11
+ system("stylus #{file} -o #{css_folder(file)}")
12
+ end
13
+ end
14
+
15
+ private
16
+ def css_folder(path)
17
+ File.dirname(File.dirname(path))
18
+ end
19
+
20
+ def should_parse?(path)
21
+ File.extname(path) == ".#{Stylus.extension}" && File.file?(path) && File.basename(path) !~ /^_/
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_support/core_ext/module/attribute_accessors'
2
+
3
+ module Stylus
4
+
5
+ # Directory to look for .stylus files
6
+ mattr_accessor :directory
7
+ @@directory = "stylus"
8
+
9
+ # Root path for the stylus directory lookup.
10
+ mattr_accessor :root
11
+ @@root = File.dirname(__FILE__)
12
+
13
+ mattr_accessor :extension
14
+ @@extension = "styl"
15
+
16
+ def self.compile
17
+ paths = Dir[File.join(folder, "**", "*.#{extension}")]
18
+ Stylus::Runner.new(paths).call
19
+ end
20
+ def self.message
21
+ <<-warn
22
+
23
+ Warning: 'stylus' executable was not found on your system.
24
+ Check stylus docs about installation at https://github.com/LearnBoost/stylus
25
+ and be sure to have node.js and npm properly installed.
26
+
27
+ warn
28
+ end
29
+
30
+ protected
31
+ def self.folder
32
+ File.join(root, directory)
33
+ end
34
+
35
+ end
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,3 @@
1
+ module Stylus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ body {
2
+ font: 12px Helvetica, Arial, sans-serif;
3
+ }
4
+ a.button {
5
+ -webkit-border-radius: 5px;
6
+ -moz-border-radius: 5px;
7
+ border-radius: 5px;
8
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ border-radius()
2
+ -webkit-border-radius arguments
3
+ -moz-border-radius arguments
4
+ border-radius arguments
@@ -0,0 +1,7 @@
1
+ @import '_border_radius'
2
+
3
+ body
4
+ font 12px Helvetica, Arial, sans-serif
5
+
6
+ a.button
7
+ border-radius 5px
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stylus::Runner do
4
+
5
+ describe "#initialize" do
6
+ it "assigns only .styl files" do
7
+ parser = Stylus::Runner.new(fixtures("stylus/simple.styl", "style.css"))
8
+ parser.paths.should == fixture("stylus/simple.styl")
9
+ end
10
+
11
+ it "rejects non existent files" do
12
+ parser = Stylus::Runner.new(fixtures("stylus/simple.styl", "not/found.styl"))
13
+ parser.paths.should == fixture("stylus/simple.styl")
14
+ end
15
+
16
+ it "excludes partial files" do
17
+ parser = Stylus::Runner.new(fixtures("stylus/simple.styl", "stylus/_border_radius.styl"))
18
+ parser.paths.should == fixture("stylus/simple.styl")
19
+ end
20
+ end
21
+
22
+ describe "#call" do
23
+ subject { Stylus::Runner.new(fixture("stylus/simple.styl")) }
24
+
25
+ it "calls the stylus cli" do
26
+ stylus_file = fixture("stylus/simple.styl").first
27
+ target_folder = File.dirname(fixture("simple.css").first)
28
+ subject.should_receive(:system).with("stylus #{stylus_file} -o #{target_folder}")
29
+ subject.call
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ require 'stylus_rails'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ def fixtures(*paths)
6
+ paths.map { |path| File.expand_path(path, "spec/fixtures") }
7
+ end
8
+ alias :fixture :fixtures
9
+ end
10
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "stylus_rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "stylus_rails"
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 = "http://rubygems.org/gems/stylus_rails"
12
+ s.summary = %q{Stylus stylesheets for Rails apps}
13
+ s.description = %q{Rails engine to compile .styl files between requests}
14
+
15
+ s.add_dependency "activesupport", "~> 3.0"
16
+ s.add_development_dependency "rspec", "~> 2.4"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stylus_rails
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-02-01 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 11
45
+ segments:
46
+ - 2
47
+ - 4
48
+ version: "2.4"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Rails engine to compile .styl files between requests
52
+ email:
53
+ - luc4smazza@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/stylus_rails.rb
67
+ - lib/stylus_rails/railtie.rb
68
+ - lib/stylus_rails/runner.rb
69
+ - lib/stylus_rails/stylus.rb
70
+ - lib/stylus_rails/tasks/tasks.rake
71
+ - lib/stylus_rails/version.rb
72
+ - spec/fixtures/simple.css
73
+ - spec/fixtures/style.css
74
+ - spec/fixtures/stylus/_border_radius.styl
75
+ - spec/fixtures/stylus/simple.styl
76
+ - spec/runner_spec.rb
77
+ - spec/spec_helper.rb
78
+ - stylus_rails.gemspec
79
+ has_rdoc: true
80
+ homepage: http://rubygems.org/gems/stylus_rails
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.4.2
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Stylus stylesheets for Rails apps
113
+ test_files:
114
+ - spec/fixtures/simple.css
115
+ - spec/fixtures/style.css
116
+ - spec/fixtures/stylus/_border_radius.styl
117
+ - spec/fixtures/stylus/simple.styl
118
+ - spec/runner_spec.rb
119
+ - spec/spec_helper.rb