stylus 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,11 +1,16 @@
1
1
  ## Changelog
2
2
 
3
- ### 0.1.2 (2001-07-08)
3
+ ### 0.2.0 (211-07-14)
4
+ [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.1.2...v0.2.0)
5
+
6
+ * Replaced `stylus:install` with proper generators for Rails 3.1 - now all hooks for the `stylesheet_engine` will generate `.styl` files.
7
+
8
+ ### 0.1.2 (2011-07-08)
4
9
  [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.1.1...v0.1.2)
5
10
 
6
11
  * Fixes missing `require` for Rails apps.
7
12
 
8
- ### 0.1.1 (2001-07-07)
13
+ ### 0.1.1 (2011-07-07)
9
14
  [Compare view](https://github.com/lucasmazza/ruby-stylus/compare/v0.1.0...v0.1.1)
10
15
 
11
16
  * Requiring `stylus/tilt` outside the `Railtie`, by [DAddYE](https://github.com/DAddYE).
data/README.md CHANGED
@@ -38,10 +38,6 @@ Just add the `stylus` gem to your Gemfile and the gem will hook itself into Spro
38
38
 
39
39
  If you just want to merge the generated css in another file, you can use only the `require` directive from Sprockets.
40
40
 
41
- ### Rails Generators
42
-
43
- `stylus` ships with a `stylus:install` generator that copy 2 `.styl` files to your `lib/` folder, so when you run rails generators like `rails g assets products` or `rails g scaffold post` it will create `.styl` files instead of plain `.css` ones.
44
-
45
41
  ## Changelog
46
42
  [here.](https://github.com/lucasmazza/ruby-stylus/blob/master/CHANGELOG.md)
47
43
 
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Stylus
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_stylus
9
+ template "stylesheet.css.styl", File.join('app/assets/stylesheets', class_path, "#{file_name}.css.styl")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  // Place all the styles related to the matching controller here.
2
2
  // They will automatically be included in application.css.
3
- // You can use Sass here: http://learnboost.github.com/stylus
3
+ // You can use Stylus syntax here: http://learnboost.github.com/stylus
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/css/scaffold/scaffold_generator'
2
+
3
+ module Stylus
4
+ module Generators
5
+ # Just inherit from the original Generator from Rails
6
+ # because `scaffold.css` it's just to help people to start up
7
+ # their Rails applications.
8
+ class ScaffoldGenerator < Css::Generators::ScaffoldGenerator
9
+ end
10
+ end
11
+ end
@@ -1,23 +1,19 @@
1
- ### Stylus Railtie
2
- # `Railtie` responsible for injecting `stylus` inside the
3
- # Rails application and the `Sprockets` Asset Pipeline.
1
+ require 'stylus/tilt'
2
+ require 'sprockets'
4
3
  module Stylus
4
+ ### Stylus Railtie
5
+ #
6
+ # `Railtie` responsible for injecting `stylus` inside the
7
+ # Rails application and the `Sprockets` Asset Pipeline.
5
8
  class Railtie < ::Rails::Railtie
6
9
 
7
- initializer :setup_stylus do |app|
8
- config.app_generators.stylesheet_engine :styl
9
- next unless app.config.assets.enabled
10
+ config.app_generators.stylesheet_engine :stylus
10
11
 
11
- # Loading `Sprockets` before Rails so we can register our own Engine.
12
- require 'sprockets'
13
- require 'sprockets/engines'
14
- require 'stylus/tilt'
15
-
16
- Sprockets.register_engine '.styl', Tilt::StylusTemplate
17
- end
12
+ Sprockets::Engines #autoloading
13
+ Sprockets.register_engine '.styl', Tilt::StylusTemplate
18
14
 
19
15
  # Includes the `Rails` asset load path into `stylus` so any
20
- # `.styl` file inside it can be imported.
16
+ # `.styl` file inside it can be imported by the `stylus` API.
21
17
  config.after_initialize do |app|
22
18
  Stylus.paths.concat app.assets.paths
23
19
  end
data/lib/stylus/tilt.rb CHANGED
@@ -1,13 +1,18 @@
1
- ### Stylus template implementation for `Tilt`.
2
- # It can be used by the `Rails` Asset Pipeline or `Sinatra` Applications.
3
1
  require 'tilt'
4
- require 'tilt/template'
5
2
 
6
3
  module Tilt
4
+ ### Stylus template implementation for `Tilt`.
5
+ #
6
+ # It can be used by the `Rails` Asset Pipeline or `Sinatra` applications.
7
7
  class StylusTemplate < Template
8
8
  self.default_mime_type = 'text/css'
9
9
 
10
+ def self.engine_initialized?
11
+ defined? ::Stylus
12
+ end
13
+
10
14
  def prepare
15
+ require_template_library 'stylus'
11
16
  end
12
17
 
13
18
  def evaluate(scope, locals, &block)
@@ -1,3 +1,3 @@
1
1
  module Stylus
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/stylus.rb CHANGED
@@ -1,11 +1,18 @@
1
- ## Stylus
1
+ require 'execjs'
2
+ require 'stylus/version'
3
+ require 'stylus/tilt' if defined?(::Tilt)
4
+ require 'stylus/railtie' if defined?(::Rails)
2
5
 
6
+ ## Stylus
7
+ #
3
8
  # `stylus` is a bridge between your Ruby code and the [Stylus](https://github.com/LearnBoost/stylus)
4
9
  # library that runs on Node.js. It's aims to be a replacement for the
5
10
  # [stylus_rails](https://github.com/lucasmazza/stylus_rails) gem and to support the Rails 3.1 asset pipeline
6
11
  # (via [Tilt](https://github.com/rtomayko/tilt)) and other scenarios,
7
- # backed by the [ExecJS](https://github.com/sstephenson/execjs) gem.module Stylus
12
+ # backed by the [ExecJS](https://github.com/sstephenson/execjs) gem.
13
+ #
8
14
  ### Usage
15
+ #
9
16
  # To compile a `.styl` file or an arbitrary String to .CSS using stylus, just use the `compile` method.
10
17
  #
11
18
  # `Stylus.compile(File.new('application.styl'))`
@@ -14,11 +21,6 @@
14
21
  #
15
22
  # `Stylus.compile(File.read('application.styl'), :compress => true)`
16
23
  #
17
-
18
- require 'execjs'
19
- require 'stylus/version'
20
- require 'stylus/tilt' if defined?(::Tilt)
21
- require 'stylus/railtie' if defined?(::Rails)
22
24
  module Stylus
23
25
  class << self
24
26
  @@compress = false
@@ -26,7 +28,6 @@ module Stylus
26
28
  @@plugins = {}
27
29
 
28
30
  # Stores a list of plugins to import inside `Stylus`, with an optional hash.
29
-
30
31
  def use(*options)
31
32
  arguments = options.last.is_a?(Hash) ? options.pop : {}
32
33
  options.each do |plugin|
@@ -35,7 +36,7 @@ module Stylus
35
36
  end
36
37
  alias :plugin :use
37
38
 
38
- # Retrieves the plugins registered by `use`.
39
+ # Retrieves all the registered plugins registered.
39
40
  def plugins
40
41
  @@plugins
41
42
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'rails/generators/stylus/assets/assets_generator'
3
+
4
+ describe Stylus::Generators::AssetsGenerator do
5
+ include Generators::TestCase
6
+ arguments %w(posts)
7
+
8
+ it 'generates a .styl file' do
9
+ file('app/assets/stylesheets/posts.css.styl').should exist
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'rails/generators/rails/controller/controller_generator'
3
+ require 'rails/generators/stylus/assets/assets_generator'
4
+
5
+ describe Rails::Generators::ControllerGenerator do
6
+ include Generators::TestCase
7
+ arguments %w(posts --stylesheet-engine=stylus)
8
+
9
+ it 'generates a .styl file' do
10
+ file('app/assets/stylesheets/posts.css.styl').should exist
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'rails/generators/rails/scaffold/scaffold_generator'
3
+ require 'rails/generators/stylus/assets/assets_generator'
4
+ require 'rails/generators/stylus/scaffold/scaffold_generator'
5
+
6
+ describe Rails::Generators::ScaffoldGenerator do
7
+ include Generators::TestCase
8
+ arguments %w(posts --stylesheet-engine=stylus --orm=false)
9
+
10
+ it 'generates the default scaffold stylesheet' do
11
+ file('app/assets/stylesheets/scaffold.css').should exist
12
+ end
13
+
14
+ it 'generates a named .styl file' do
15
+ file('app/assets/stylesheets/posts.css.styl').should exist
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
- require 'stylus'
1
+ require 'support/helpers'
2
+ require 'support/matchers'
3
+ require 'support/generators/test_case'
2
4
 
3
5
  RSpec.configure do |config|
6
+ config.include Helpers
4
7
 
5
8
  config.after :each do
6
9
  Stylus.compress = false
@@ -8,14 +11,3 @@ RSpec.configure do |config|
8
11
  Stylus.plugins.clear
9
12
  end
10
13
  end
11
-
12
- def fixture_root
13
- File.expand_path('../fixtures', __FILE__)
14
- end
15
-
16
- def fixture(name)
17
- stylus = File.read(File.join(fixture_root, "#{name}.styl"))
18
- css = File.read(File.join(fixture_root, "#{name}.css"))
19
- [stylus, css]
20
- end
21
-
data/spec/stylus_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'stylus'
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Stylus do
@@ -0,0 +1,68 @@
1
+ # Extracted from generator_spec https://github.com/stevehodgkiss/generator_spec
2
+ # But `RSpec::Rails::RailsExampleGroup` loads a truckload of things from rails and rspec-rails
3
+ # That we don't need.
4
+
5
+ ENV["RAILS_ENV"] = 'test'
6
+ require 'rails'
7
+ require 'rails/test_help'
8
+ require 'rails/generators/test_case'
9
+ require 'active_support/core_ext/class/attribute_accessors'
10
+
11
+ module Generators
12
+ module TestCase
13
+ extend ActiveSupport::Concern
14
+ include FileUtils
15
+
16
+ included do
17
+ cattr_accessor :test_case, :test_case_instance
18
+
19
+ self.test_case = Class.new(Rails::Generators::TestCase) do
20
+ def fake_test_case; end
21
+ def add_assertion; end
22
+ end
23
+ self.test_case_instance = self.test_case.new(:fake_test_case)
24
+ self.test_case.tests described_class
25
+
26
+ before do
27
+ prepare_destination
28
+ create_routes
29
+ run_generator
30
+ end
31
+
32
+ destination File.expand_path("../tmp", __FILE__)
33
+ end
34
+
35
+ module ClassMethods
36
+ def tests(klass)
37
+ self.test_case.generator_class = klass
38
+ end
39
+
40
+ def arguments(array)
41
+ self.test_case.default_arguments = array
42
+ end
43
+
44
+ def destination(path)
45
+ self.test_case.destination_root = path
46
+ end
47
+ end
48
+
49
+ module InstanceMethods
50
+
51
+ def file(relative)
52
+ File.expand_path(relative, destination_root)
53
+ end
54
+
55
+ def method_missing(method_sym, *arguments, &block)
56
+ self.test_case_instance.send(method_sym, *arguments, &block)
57
+ end
58
+
59
+ def respond_to?(method_sym, include_private = false)
60
+ if self.test_case_instance.respond_to?(method_sym)
61
+ true
62
+ else
63
+ super
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ module Helpers
2
+ def create_routes
3
+ destination = File.join(destination_root, "config")
4
+
5
+ FileUtils.mkdir_p(destination)
6
+ FileUtils.touch File.join(destination, 'routes.rb')
7
+ end
8
+
9
+ def fixture_root
10
+ File.expand_path('../../fixtures', __FILE__)
11
+ end
12
+
13
+ def fixture(name)
14
+ stylus = File.read(File.join(fixture_root, "#{name}.styl"))
15
+ css = File.read(File.join(fixture_root, "#{name}.css"))
16
+ [stylus, css]
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :exist do
2
+ match do |file_path|
3
+ File.exists?(file_path)
4
+ end
5
+ end
data/stylus.gemspec CHANGED
@@ -13,8 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Bridge library to compile .styl stylesheets from ruby code.}
14
14
 
15
15
  s.add_dependency 'execjs'
16
- s.add_development_dependency 'rspec', '~>2.0'
17
- s.add_development_dependency 'tilt'
16
+ s.add_development_dependency 'rspec', '~> 2.0'
17
+ s.add_development_dependency 'railties', '~> 3.1.0.rc1'
18
+ s.add_development_dependency 'actionpack', '~> 3.1.0.rc1'
19
+ s.add_development_dependency 'sprockets', '2.0.0.beta.10'
18
20
  s.add_development_dependency 'yajl-ruby'
19
21
  s.add_development_dependency 'rocco'
20
22
 
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: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Mazza
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-08 00:00:00 -03:00
18
+ date: 2011-07-14 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,23 +48,63 @@ dependencies:
48
48
  type: :development
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- name: tilt
51
+ name: railties
52
52
  prerelease: false
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - ">="
56
+ - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 3
58
+ hash: 15424103
59
59
  segments:
60
+ - 3
61
+ - 1
60
62
  - 0
61
- version: "0"
63
+ - rc
64
+ - 1
65
+ version: 3.1.0.rc1
62
66
  type: :development
63
67
  version_requirements: *id003
64
68
  - !ruby/object:Gem::Dependency
65
- name: yajl-ruby
69
+ name: actionpack
66
70
  prerelease: false
67
71
  requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 15424103
77
+ segments:
78
+ - 3
79
+ - 1
80
+ - 0
81
+ - rc
82
+ - 1
83
+ version: 3.1.0.rc1
84
+ type: :development
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: sprockets
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - "="
93
+ - !ruby/object:Gem::Version
94
+ hash: 62196471
95
+ segments:
96
+ - 2
97
+ - 0
98
+ - 0
99
+ - beta
100
+ - 10
101
+ version: 2.0.0.beta.10
102
+ type: :development
103
+ version_requirements: *id005
104
+ - !ruby/object:Gem::Dependency
105
+ name: yajl-ruby
106
+ prerelease: false
107
+ requirement: &id006 !ruby/object:Gem::Requirement
68
108
  none: false
69
109
  requirements:
70
110
  - - ">="
@@ -74,11 +114,11 @@ dependencies:
74
114
  - 0
75
115
  version: "0"
76
116
  type: :development
77
- version_requirements: *id004
117
+ version_requirements: *id006
78
118
  - !ruby/object:Gem::Dependency
79
119
  name: rocco
80
120
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
121
+ requirement: &id007 !ruby/object:Gem::Requirement
82
122
  none: false
83
123
  requirements:
84
124
  - - ">="
@@ -88,7 +128,7 @@ dependencies:
88
128
  - 0
89
129
  version: "0"
90
130
  type: :development
91
- version_requirements: *id005
131
+ version_requirements: *id007
92
132
  description: Bridge library to compile .styl stylesheets from ruby code.
93
133
  email:
94
134
  - luc4smazza@gmail.com
@@ -105,10 +145,9 @@ files:
105
145
  - LICENSE
106
146
  - README.md
107
147
  - Rakefile
108
- - lib/generators/stylus/USAGE
109
- - lib/generators/stylus/install_generator.rb
110
- - lib/generators/stylus/templates/scaffold.css.styl
111
- - lib/generators/stylus/templates/stylesheet.css.styl
148
+ - lib/rails/generators/stylus/assets/assets_generator.rb
149
+ - lib/rails/generators/stylus/assets/templates/stylesheet.css.styl
150
+ - lib/rails/generators/stylus/scaffold/scaffold_generator.rb
112
151
  - lib/stylus.rb
113
152
  - lib/stylus/compiler.js
114
153
  - lib/stylus/railtie.rb
@@ -125,8 +164,14 @@ files:
125
164
  - spec/fixtures/simple.styl
126
165
  - spec/fixtures/stylesheet.css
127
166
  - spec/fixtures/stylesheet.styl
167
+ - spec/generators/assets_generator_spec.rb
168
+ - spec/generators/controller_generator_spec.rb
169
+ - spec/generators/scaffold_generator_spec.rb
128
170
  - spec/spec_helper.rb
129
171
  - spec/stylus_spec.rb
172
+ - spec/support/generators/test_case.rb
173
+ - spec/support/helpers.rb
174
+ - spec/support/matchers.rb
130
175
  - spec/tilt_spec.rb
131
176
  - stylus.gemspec
132
177
  has_rdoc: true
@@ -175,6 +220,12 @@ test_files:
175
220
  - spec/fixtures/simple.styl
176
221
  - spec/fixtures/stylesheet.css
177
222
  - spec/fixtures/stylesheet.styl
223
+ - spec/generators/assets_generator_spec.rb
224
+ - spec/generators/controller_generator_spec.rb
225
+ - spec/generators/scaffold_generator_spec.rb
178
226
  - spec/spec_helper.rb
179
227
  - spec/stylus_spec.rb
228
+ - spec/support/generators/test_case.rb
229
+ - spec/support/helpers.rb
230
+ - spec/support/matchers.rb
180
231
  - spec/tilt_spec.rb
@@ -1,3 +0,0 @@
1
- Copy the Stylus templates to your Rails app to replace the .css files generated by Rails, just do:
2
-
3
- rails generate stylus:install
@@ -1,16 +0,0 @@
1
- module Stylus
2
- module Generators
3
- class InstallGenerator < ::Rails::Generators::Base
4
- desc 'copy Stylus assets templates'
5
- source_root File.expand_path('../templates', __FILE__)
6
-
7
- def copy_asset_template
8
- copy_file 'stylesheet.css.styl', 'lib/templates/rails/assets/stylesheet.css.styl'
9
- end
10
-
11
- def copy_scaffold_template
12
- copy_file 'scaffold.css.styl', 'lib/templates/rails/resource/scaffold.css.styl'
13
- end
14
- end
15
- end
16
- end
@@ -1,58 +0,0 @@
1
- body
2
- background-color #fff
3
- color #333
4
-
5
- body, p, ol, ul, td
6
- font-family verdana, arial, helvetica, sans-serif
7
- font-size 13px
8
- line-height 18px
9
-
10
- pre
11
- background-color #eee
12
- padding 10px
13
- font-size 11px
14
-
15
- a
16
- color #000
17
-
18
- &:visited
19
- color #666
20
-
21
- &:hover
22
- color #fff
23
- background-color #000
24
-
25
- div.field, div.actions
26
- margin-bottom 10px
27
-
28
- #notice
29
- color green
30
-
31
- .field_with_errors
32
- padding 2px
33
- background-color red
34
- display table
35
-
36
- #error_explanation
37
- width 450px
38
- border 2px solid red
39
- padding 7px
40
- padding-bottom 0
41
- margin-bottom 20px
42
- background-color #f0f0f0
43
-
44
- h2
45
- text-align left
46
- font-weight bold
47
- padding 5px 5px 5px 15px
48
- font-size 12px
49
- margin -7px
50
- margin-bottom 0px
51
- background-color #c00
52
- color #fff
53
- ul
54
- li
55
- font-size 12px
56
- list-style square
57
-
58
-