rack-asset-compiler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -19,7 +19,7 @@ in and the compiled output is expected to be returned.
19
19
 
20
20
  require 'rack/asset_compiler'
21
21
 
22
- use Rack::AssetCompiler(
22
+ use Rack::AssetCompiler,
23
23
  :source_dir => 'lowercase',
24
24
  :url => '/uppercase',
25
25
  :content_type => 'text/plain',
@@ -27,17 +27,17 @@ in and the compiled output is expected to be returned.
27
27
  :compiler => lambda { |source_file|
28
28
  File.read(source_file).upcase
29
29
  }
30
- )
31
30
 
32
31
  ## Subclassing
33
32
  An alternative to passing in a lambda to the :compiler option is to subclass Rack::AssetCompiler and
34
33
  override the `compile` method.
35
34
 
36
- This gem comes with two subclasses: one for compiling CoffeeScript and one for Sass.
35
+ This gem comes with three subclasses: one for compiling CoffeeScript one for Sass, and one for Compass.
37
36
 
38
37
  ## Compiling CoffeeScript
39
38
 
40
39
  config.ru
40
+
41
41
  require 'rack/coffee_compiler'
42
42
 
43
43
  use Rack::CoffeeCompiler,
@@ -46,6 +46,7 @@ config.ru
46
46
  :alert_on_error => true # Generates a window.alert on compile error. Defaults to (RACK_ENV != 'production')
47
47
 
48
48
  Gemfile
49
+
49
50
  gem 'therubyracer'
50
51
  gem 'coffee-script'
51
52
 
@@ -66,15 +67,57 @@ On Rails
66
67
  # Insert the new middleware
67
68
  Rails.application.config.middleware.use Rack::SassCompiler,
68
69
  :source_dir => 'app/sass',
69
- :url => '/css',
70
- :syntax => :scss # :sass or :scss, defaults to :scss
70
+ :url => '/css'
71
+
72
+ The above uses the default options for the sass compiler, including the
73
+ use of the scss syntax. To compile sass, or to change any of the other
74
+ sass compiler options, provide the optional `sass_options` hash in the
75
+ options hash. For example...
76
+
77
+ # Insert the new middleware
78
+ Rails.application.config.middleware.use Rack::SassCompiler,
79
+ :source_dir => 'app/sass',
80
+ :url => '/css'
81
+ :sass_options => {
82
+ :syntax => :sass,
83
+ :style => :compressed
84
+ }
85
+
86
+ The above would use the the sass syntax compiler and output compressed
87
+ CSS. See [Sass Documentation](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options)
88
+ for a list of options.
89
+
90
+ To make the Compass frameworks available to the SassCompiler, simply
91
+ require Compass and any compass plugins. For example...
92
+
93
+ require 'compass'
94
+ require 'ninesixty' # 960.gs Compass plugin
95
+
96
+ use Rack::SassCompiler,
97
+ :source_dir => 'sass'
98
+ :url => '/css'
99
+
100
+
101
+ ## Running without an HTTP cache
102
+ If your stack doesn't include an HTTP cache (like Varnish), the compilation step will run each time a new visitor requests a compiled resource.
103
+
104
+ An easy solution is to use [Rack::Cache][rack-cache]
105
+
106
+ require 'rack/asset_compiler'
107
+ require 'rack/cache'
108
+ use Rack::Cache # Make sure this comes first
109
+ use Rack::AssetCompiler, ...
110
+
111
+ If you're running on Heroku, you get Varnish for free. So you don't have to worry about this.
112
+
113
+ If you're running locally, the user agent cache in your browser is sufficient. So you also don't need to worry about this.
71
114
 
72
115
  ## Contribute
73
116
 
74
117
  Contributions must be accompanied by passing tests. To run the test suite for
75
118
  the gem you need the following gems installed:
76
119
 
77
- [sudo] gem install rack rack-test haml coffee-script rspec
120
+ [sudo] gem install rack rack-test haml coffee-script rspec compass
78
121
 
79
122
  After installing the required gems and before beginning development,
80
123
  ensure your environment is properly configured and all tests pass by
@@ -82,7 +125,10 @@ running `rake`.
82
125
 
83
126
  ## Thanks
84
127
  asset-compiler was inspired by [rack-coffee] by [Matthew Lyon][mattly]
128
+
85
129
  ruby 1.9.2 compatibility added by [Derek Prior][derekprior]
86
130
 
87
131
  [rack-coffee]: https://github.com/mattly/rack-coffee
88
- [mattly]: https://github.com/mattly/rack-coffee
132
+ [mattly]: https://github.com/mattly
133
+ [derekprior]: https://github.com/derekprior
134
+ [rack-cache]: http://rtomayko.github.com/rack-cache/
@@ -35,8 +35,10 @@ module Jasmine
35
35
  run Jasmine.app(config)
36
36
  end
37
37
 
38
- handler = Rack::Handler.default
39
- handler.run app, :Port => port, :AccessLog => []
38
+ server = Rack::Server.new(:Port => port, :AccessLog => [])
39
+ # workaround for Rack bug, when Rack > 1.2.1 is released Rack::Server.start(:app => Jasmine.app(self)) will work
40
+ server.instance_variable_set(:@app, app)
41
+ server.start
40
42
  end
41
43
  end
42
44
  end
@@ -3,7 +3,7 @@ require 'sass'
3
3
 
4
4
  module Rack
5
5
  class SassCompiler < AssetCompiler
6
- attr_accessor :syntax
6
+ attr_accessor :sass_options
7
7
 
8
8
  def initialize(app, options={})
9
9
  options
@@ -11,21 +11,33 @@ module Rack
11
11
  options = {
12
12
  :url => '/stylesheets',
13
13
  :content_type => 'text/css',
14
- :syntax => :scss
15
14
  }.merge(options)
16
15
 
17
- @syntax = options[:syntax]
18
- options[:source_extension] ||= syntax.to_s
16
+ options[:sass_options] ||= {}
17
+ options[:sass_options] = {
18
+ :syntax => :scss,
19
+ :cache => false
20
+ }.merge(options[:sass_options])
21
+
22
+ @sass_options = options[:sass_options]
23
+ options[:source_extension] ||= @sass_options[:syntax].to_s
19
24
  super
20
25
  end
21
26
 
27
+ def get_load_paths(src_dir)
28
+ paths = [src_dir]
29
+ if defined?(Compass::Frameworks)
30
+ Compass::Frameworks::ALL.each do |framework|
31
+ paths << framework.stylesheets_directory if ::File.exists?(framework.stylesheets_directory)
32
+ end
33
+ end
34
+ paths
35
+ end
36
+
22
37
  def compile(source_file)
23
- sass_options = {
24
- :syntax => syntax,
25
- :cache => false,
26
- :load_paths => [source_dir]
27
- }
28
- Sass::Engine.new(::File.read(source_file), sass_options).render
38
+ @sass_options[:load_paths] ||= []
39
+ @sass_options[:load_paths] = @sass_options[:load_paths] | get_load_paths(source_dir)
40
+ Sass::Engine.new(::File.read(source_file), @sass_options).render
29
41
  end
30
42
  end
31
- end
43
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rack-asset-compiler'
3
- s.version = "0.1.0"
3
+ s.version = "0.2.0"
4
4
  s.author = 'Jonathan Baudanza'
5
5
  s.email = 'jon@jonb.org'
6
6
  s.summary = 'Rack Middleware to facilitate the generic compiling static assets.'
@@ -0,0 +1,6 @@
1
+ @import "compass/css3";
2
+
3
+ #border-radius-test {
4
+ @include border-radius(25px);
5
+ }
6
+
@@ -1,6 +1,6 @@
1
1
  require 'rack/sass_compiler'
2
2
  require 'rack/lobster'
3
- require "rack/test"
3
+ require 'rack/test'
4
4
 
5
5
  include Rack::Test::Methods
6
6
 
@@ -31,11 +31,19 @@ describe "SassCompiler" do
31
31
  end
32
32
 
33
33
  it "should compile sass" do
34
- @options[:syntax] = :sass
34
+ @options[:sass_options] = {:syntax => :sass}
35
35
  get '/stylesheets/style.css'
36
36
  last_response.body.should ==
37
37
  Sass::Engine.new(File.read("#{@source_dir}/style.sass"), :syntax => :sass).render
38
38
  last_response.status.should == 200
39
39
  last_response.content_type.should == 'text/css'
40
40
  end
41
- end
41
+
42
+ it "should compile compass when library is loaded" do
43
+ require 'compass'
44
+ get '/stylesheets/compass.css'
45
+ last_response.status.should == 200
46
+ last_response.content_type.should == 'text/css'
47
+ end
48
+
49
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-asset-compiler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Baudanza
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-14 00:00:00 -07:00
18
+ date: 2011-04-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -58,6 +58,7 @@ files:
58
58
  - spec/fixtures/coffeescripts/syntax_error.coffee
59
59
  - spec/fixtures/eggscripts/application.eggscript
60
60
  - spec/fixtures/eggscripts/subdir/application.eggscript
61
+ - spec/fixtures/sass/compass.scss
61
62
  - spec/fixtures/sass/style.sass
62
63
  - spec/fixtures/sass/style.scss
63
64
  - spec/sass_compiler_spec.rb
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements: []
93
94
 
94
95
  rubyforge_project:
95
- rubygems_version: 1.6.2
96
+ rubygems_version: 1.5.0
96
97
  signing_key:
97
98
  specification_version: 3
98
99
  summary: Rack Middleware to facilitate the generic compiling static assets.