compass-rails 1.0.3 → 1.1.0
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.
- data/.gitignore +1 -0
- data/.travis.yml +1 -2
- data/Appraisals +6 -5
- data/Gemfile +4 -3
- data/README.md +45 -58
- data/changelog.markdown +11 -0
- data/compass-rails.gemspec +3 -3
- data/gemfiles/rails3.gemfile +3 -2
- data/gemfiles/rails31.gemfile +3 -2
- data/gemfiles/rails32.gemfile +3 -2
- data/gemfiles/{rails2.gemfile → rails40.gemfile} +5 -3
- data/lib/compass-rails/configuration/3_1.rb +4 -0
- data/lib/compass-rails/patches/3_1.rb +6 -1
- data/lib/compass-rails/patches/4_0.rb +30 -0
- data/lib/compass-rails/patches/sass_importer.rb +31 -0
- data/lib/compass-rails/patches/sprite_importer.rb +15 -23
- data/lib/compass-rails/patches/static_compiler.rb +1 -1
- data/lib/compass-rails/patches.rb +4 -4
- data/lib/compass-rails/railties/3_1.rb +10 -6
- data/lib/compass-rails/railties/4_0.rb +102 -0
- data/lib/compass-rails/railties.rb +4 -4
- data/lib/compass-rails/version.rb +1 -1
- data/lib/compass-rails.rb +24 -9
- data/test/helpers/file_helper.rb +1 -1
- data/test/helpers/rails_helper.rb +15 -16
- data/test/helpers/rails_project.rb +10 -64
- data/test/integrations/rails3_test.rb +4 -4
- data/test/integrations/rails_32_without_pipeline_test.rb +37 -0
- data/test/integrations/{rails_23_test.rb → rails_40_test.rb} +21 -3
- metadata +30 -24
- data/gemfiles/rails2.gemfile.lock +0 -81
- data/gemfiles/rails3.gemfile.lock +0 -128
- data/gemfiles/rails31.gemfile.lock +0 -145
- data/gemfiles/rails32.gemfile.lock +0 -142
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
appraise "rails2" do
|
|
2
|
-
gem "rails", "2.3.14"
|
|
3
|
-
end
|
|
4
|
-
|
|
5
1
|
appraise "rails3" do
|
|
6
2
|
gem "rails", "3.0.11"
|
|
7
3
|
end
|
|
@@ -14,4 +10,9 @@ end
|
|
|
14
10
|
appraise "rails32" do
|
|
15
11
|
gem "rails", "~> 3.2"
|
|
16
12
|
gem "sass-rails"
|
|
17
|
-
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
appraise "rails40" do
|
|
16
|
+
gem "rails", "~> 4.0.0"
|
|
17
|
+
gem "sass-rails"
|
|
18
|
+
end
|
data/Gemfile
CHANGED
|
@@ -4,13 +4,14 @@ source 'https://rubygems.org'
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
group :assets do
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
7
|
+
gem "compass", '~> 0.13.alpha.0'
|
|
8
|
+
gem "compass-rails", :path=>"."
|
|
9
|
+
gem 'compass-blueprint'
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
group :test do
|
|
12
13
|
gem 'mocha'
|
|
13
|
-
gem "appraisal", :git => '
|
|
14
|
+
gem "appraisal", :git => 'https://github.com/scottdavis/appraisal.git'
|
|
14
15
|
gem 'rainbow'
|
|
15
16
|
end
|
|
16
17
|
|
data/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# CompassRails
|
|
2
2
|
|
|
3
|
+
[](https://travis-ci.org/Compass/compass-rails)
|
|
4
|
+
|
|
3
5
|
Compass rails is an adapter for the [Compass Stylesheet Authoring
|
|
4
|
-
Framework](http://compass-style.org) for [Ruby on Rails](http://
|
|
6
|
+
Framework](http://compass-style.org) for [Ruby on Rails](http://rubyonrails.org/).
|
|
5
7
|
|
|
6
8
|
Since Compass v0.12, this adapter is the only way to install compass
|
|
7
9
|
into your rails application.
|
|
8
10
|
|
|
9
|
-
This adapter supports rails versions
|
|
11
|
+
This adapter supports rails versions 3.0 and greater. Rails 3.0 users
|
|
10
12
|
please read the caveats below.
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
@@ -27,6 +29,8 @@ And then execute:
|
|
|
27
29
|
|
|
28
30
|
$ bundle
|
|
29
31
|
|
|
32
|
+
## Optional
|
|
33
|
+
|
|
30
34
|
To set up your project with starter stylesheets and a configuration
|
|
31
35
|
file:
|
|
32
36
|
|
|
@@ -38,21 +42,28 @@ If using a compass-based framework (like [susy](http://susy.oddbird.net/) or [bl
|
|
|
38
42
|
|
|
39
43
|
Note that the `compass init` step is optional if you have a project running Rails 3.0 or greater.
|
|
40
44
|
|
|
41
|
-
##
|
|
45
|
+
## Usage
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
Change your `application.css` to `application.css.scss` or `application.css.sass` and use `@import` to your hearts content. Ex:
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
```scss
|
|
50
|
+
@import "project/mixins";
|
|
51
|
+
@import "project/base";
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
*or*
|
|
56
|
+
|
|
57
|
+
Use `application.css` to require files that use compass features. Ex:
|
|
58
|
+
```css
|
|
59
|
+
/*
|
|
60
|
+
*= require styleguide_full_of_compass_stuff
|
|
61
|
+
*/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
*Don't* use `*= require something` within your SCSS or SASS files. You're gonna have a bad time.
|
|
54
65
|
|
|
55
|
-
|
|
66
|
+
### Configuration
|
|
56
67
|
|
|
57
68
|
If you have a compass configuration file (recommended) then you can
|
|
58
69
|
use the [Compass configuration
|
|
@@ -62,12 +73,17 @@ files, then you should understand that the compass configuration
|
|
|
62
73
|
options explained there will be methods and properties on the `config.compass`
|
|
63
74
|
configuration object exposed to rails within any configuration block.
|
|
64
75
|
|
|
65
|
-
|
|
76
|
+
### Notes On Sprockets Directives
|
|
77
|
+
|
|
78
|
+
Sprockets, used by the rails asset pipeline, provides directives for
|
|
79
|
+
doing things like requiring. These **must not** be used with Sass files.
|
|
80
|
+
Instead use the sass `@import` directive. In rails projects, the
|
|
81
|
+
`@import` directive is configured to work with sprockets via `sass-rails`. For more information on importing in rails 3.1 or greater see the [Sass-Rails README](https://github.com/rails/sass-rails/blob/master/README.md)
|
|
66
82
|
|
|
67
83
|
### Developing with Rails-based Compilation
|
|
68
84
|
|
|
69
85
|
By default, your sass files in `app/assets/stylesheets` will be
|
|
70
|
-
automatically compiled by the
|
|
86
|
+
automatically compiled by the [`Sass::Plugin`](http://sass-lang.com/docs/yardoc/Sass/Plugin.html) or the [Rails asset
|
|
71
87
|
pipeline](http://guides.rubyonrails.org/asset_pipeline.html) depending on the version of rails that you use.
|
|
72
88
|
|
|
73
89
|
When using this approach you will need to reload your webpage in order
|
|
@@ -93,11 +109,7 @@ end
|
|
|
93
109
|
To return to using the Rails-based compilation mode, simply delete
|
|
94
110
|
the compiled stylesheets and remove any configuration changes.
|
|
95
111
|
|
|
96
|
-
### Compiling for Production
|
|
97
|
-
|
|
98
|
-
If using the Rails asset pipeline run:
|
|
99
|
-
|
|
100
|
-
$ rake assets:precompile
|
|
112
|
+
### Compiling for Production without Asset Pipeline
|
|
101
113
|
|
|
102
114
|
If not using the asset pipeline run:
|
|
103
115
|
|
|
@@ -109,10 +121,7 @@ stylesheets.
|
|
|
109
121
|
|
|
110
122
|
### Installing Compass extensions
|
|
111
123
|
|
|
112
|
-
Step 1:
|
|
113
|
-
`:assets` group and run the `bundle` command to install it.
|
|
114
|
-
If the extension is a zip file, unzip it into the
|
|
115
|
-
`vendor/plugins/compass_extensions` directory of your project.
|
|
124
|
+
Step 1: Add it to your Gemfile in the `:assets` group and run the `bundle` command to install it.
|
|
116
125
|
|
|
117
126
|
Step 2: Install the extension's assets: `bundle exec compass install
|
|
118
127
|
<extension/template>`
|
|
@@ -140,18 +149,9 @@ config.compass.require "susy"
|
|
|
140
149
|
|
|
141
150
|
to your application.rb configuration file.
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
### Notes On Sprockets Directives
|
|
145
|
-
|
|
146
|
-
Sprockets, used by the rails asset pipeline, provides directives for
|
|
147
|
-
doing things like requiring. These **must not** be used with Sass files.
|
|
148
|
-
Instead use the sass `@import` directive. In rails projects, the
|
|
149
|
-
`@import` directive is configured to work with sprockets via `sass-rails`. For more information on importing in rails 3.1 or greater see the [Sass-Rails README](https://github.com/rails/sass-rails/blob/master/README.markdown)
|
|
150
|
-
|
|
151
152
|
## Rails 3.1 Caveats
|
|
152
153
|
|
|
153
|
-
|
|
154
|
-
at the earliest for this version of rails.
|
|
154
|
+
compass-rails requires Rails 3.1.1 and greater. Also, Rails 3.1 is out of support so consider upgrading.
|
|
155
155
|
|
|
156
156
|
## Rails 3.0 Caveats
|
|
157
157
|
|
|
@@ -168,34 +168,21 @@ to this:
|
|
|
168
168
|
Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Compass requires that your rails 2.3 project is using Bundler to manage
|
|
174
|
-
your rubygems. If you haven't yet set up your rails 2.3 project to use Bundler,
|
|
175
|
-
please do so prior to upgrading. [Bundler installation guide for rails
|
|
176
|
-
2.3](http://gembundler.com/rails23.html).
|
|
171
|
+
Also, Rails 3.0 is out of support so consider upgrading.
|
|
177
172
|
|
|
178
|
-
|
|
179
|
-
your stylesheets (instead of using the compass watcher) you need
|
|
180
|
-
edit `config/boot.rb` and change this:
|
|
173
|
+
## Upgrading Rails 3.0 and older projects to compass-rails
|
|
181
174
|
|
|
182
|
-
|
|
183
|
-
Rails::Initializer.class_eval do
|
|
184
|
-
def load_gems
|
|
185
|
-
@bundler_loaded ||= Bundler.require :default, Rails.env
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
```
|
|
175
|
+
First and foremost, follow the installation instructions above.
|
|
189
176
|
|
|
190
|
-
|
|
177
|
+
CompassRails uses the rails convention for stylesheet locations even in
|
|
178
|
+
older versions of rails that do not use the assets pipeline.
|
|
179
|
+
If you have your stylesheets already in `app/stylesheets`, you have two choices:
|
|
191
180
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
end
|
|
198
|
-
```
|
|
181
|
+
1. Move your stylesheets to `app/assets/stylesheets`.
|
|
182
|
+
2. Configure your project to look in the **legacy location** of
|
|
183
|
+
`app/stylesheets` by setting `config.compass.sass_dir =
|
|
184
|
+
"app/stylesheets"` in your rails configuration or by setting
|
|
185
|
+
`sass_dir = "app/stylesheets"` in your compass configuration file.
|
|
199
186
|
|
|
200
187
|
## Contributing
|
|
201
188
|
|
data/changelog.markdown
ADDED
data/compass-rails.gemspec
CHANGED
|
@@ -3,9 +3,9 @@ require File.expand_path('../lib/compass-rails/version', __FILE__)
|
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["Scott Davis", "Chris Eppstein"]
|
|
6
|
-
gem.email = ["jetviper21@gmail.com", "chris@eppsteins.net"]
|
|
7
|
-
gem.description = %q{Integrate Compass into Rails
|
|
8
|
-
gem.summary = %q{Integrate Compass into Rails
|
|
6
|
+
gem.email = ["jetviper21@gmail.com", "chris@eppsteins.net", "craig.mcnamara@gmail.com"]
|
|
7
|
+
gem.description = %q{Integrate Compass into Rails 3.0 and up.}
|
|
8
|
+
gem.summary = %q{Integrate Compass into Rails 3.0 and up.}
|
|
9
9
|
gem.homepage = "https://github.com/Compass/compass-rails"
|
|
10
10
|
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/gemfiles/rails3.gemfile
CHANGED
|
@@ -9,12 +9,13 @@ gem "guard-test"
|
|
|
9
9
|
gem "rails", "3.0.11"
|
|
10
10
|
|
|
11
11
|
group :assets do
|
|
12
|
-
gem "compass"
|
|
12
|
+
gem "compass", "~> 0.13.alpha.0"
|
|
13
13
|
gem "compass-rails", :path=>".."
|
|
14
|
+
gem "compass-blueprint"
|
|
14
15
|
end
|
|
15
16
|
group :test do
|
|
16
17
|
gem "mocha"
|
|
17
|
-
gem "appraisal", :git=>"
|
|
18
|
+
gem "appraisal", :git=>"https://github.com/scottdavis/appraisal.git"
|
|
18
19
|
gem "rainbow"
|
|
19
20
|
end
|
|
20
21
|
|
data/gemfiles/rails31.gemfile
CHANGED
|
@@ -10,12 +10,13 @@ gem "rails", "3.1.3"
|
|
|
10
10
|
gem "sass-rails"
|
|
11
11
|
|
|
12
12
|
group :assets do
|
|
13
|
-
gem "compass"
|
|
13
|
+
gem "compass", "~> 0.13.alpha.0"
|
|
14
14
|
gem "compass-rails", :path=>".."
|
|
15
|
+
gem "compass-blueprint"
|
|
15
16
|
end
|
|
16
17
|
group :test do
|
|
17
18
|
gem "mocha"
|
|
18
|
-
gem "appraisal", :git=>"
|
|
19
|
+
gem "appraisal", :git=>"https://github.com/scottdavis/appraisal.git"
|
|
19
20
|
gem "rainbow"
|
|
20
21
|
end
|
|
21
22
|
|
data/gemfiles/rails32.gemfile
CHANGED
|
@@ -10,12 +10,13 @@ gem "rails", "~> 3.2"
|
|
|
10
10
|
gem "sass-rails"
|
|
11
11
|
|
|
12
12
|
group :assets do
|
|
13
|
-
gem "compass"
|
|
13
|
+
gem "compass", "~> 0.13.alpha.0"
|
|
14
14
|
gem "compass-rails", :path=>".."
|
|
15
|
+
gem "compass-blueprint"
|
|
15
16
|
end
|
|
16
17
|
group :test do
|
|
17
18
|
gem "mocha"
|
|
18
|
-
gem "appraisal", :git=>"
|
|
19
|
+
gem "appraisal", :git=>"https://github.com/scottdavis/appraisal.git"
|
|
19
20
|
gem "rainbow"
|
|
20
21
|
end
|
|
21
22
|
|
|
@@ -6,15 +6,17 @@ gem "rb-fsevent", :require=>false
|
|
|
6
6
|
gem "ruby_gntp", :require=>false
|
|
7
7
|
gem "guard"
|
|
8
8
|
gem "guard-test"
|
|
9
|
-
gem "rails", "
|
|
9
|
+
gem "rails", "~> 4.0.0"
|
|
10
|
+
gem "sass-rails"
|
|
10
11
|
|
|
11
12
|
group :assets do
|
|
12
|
-
gem "compass"
|
|
13
|
+
gem "compass", "~> 0.13.alpha.0"
|
|
13
14
|
gem "compass-rails", :path=>".."
|
|
15
|
+
gem "compass-blueprint"
|
|
14
16
|
end
|
|
15
17
|
group :test do
|
|
16
18
|
gem "mocha"
|
|
17
|
-
gem "appraisal", :git=>"
|
|
19
|
+
gem "appraisal", :git=>"https://github.com/scottdavis/appraisal.git"
|
|
18
20
|
gem "rainbow"
|
|
19
21
|
end
|
|
20
22
|
|
|
@@ -2,6 +2,11 @@ require 'compass-rails/patches/static_compiler'
|
|
|
2
2
|
|
|
3
3
|
module Sass::Script::Functions
|
|
4
4
|
def generated_image_url(path, only_path = nil)
|
|
5
|
+
path = if Compass.configuration.generated_images_dir
|
|
6
|
+
full_path = File.join(Compass.configuration.generated_images_dir, path.value)
|
|
7
|
+
Sass::Script::String.new full_path.sub(File.join('app', 'assets', 'images'), "")[1..-1]
|
|
8
|
+
end
|
|
9
|
+
|
|
5
10
|
asset_url(path, Sass::Script::String.new("image"))
|
|
6
11
|
end
|
|
7
12
|
end
|
|
@@ -9,7 +14,7 @@ end
|
|
|
9
14
|
|
|
10
15
|
module Compass::RailsImageFunctionPatch
|
|
11
16
|
private
|
|
12
|
-
|
|
17
|
+
|
|
13
18
|
def image_path_for_size(image_file)
|
|
14
19
|
begin
|
|
15
20
|
file = ::Rails.application.assets.find_asset(image_file)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'compass-rails/patches/sass_importer'
|
|
2
|
+
require 'compass-rails/patches/sprite_importer'
|
|
3
|
+
module Sass::Script::Functions
|
|
4
|
+
def generated_image_url(path, only_path = nil)
|
|
5
|
+
asset_url(path)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module Compass::RailsImageFunctionPatch
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def image_path_for_size(image_file)
|
|
14
|
+
begin
|
|
15
|
+
file = ::Rails.application.assets.find_asset(image_file)
|
|
16
|
+
return file
|
|
17
|
+
rescue ::Sprockets::FileOutsidePaths
|
|
18
|
+
return super(image_file)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Sass::Script::Functions
|
|
24
|
+
include Compass::RailsImageFunctionPatch
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
|
28
|
+
class Sass::Script::Functions::EvaluationContext
|
|
29
|
+
include Sass::Script::Functions
|
|
30
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Sprockets
|
|
2
|
+
class SassTemplate < Tilt::Template
|
|
3
|
+
def evaluate(context, locals, &block)
|
|
4
|
+
# Use custom importer that knows about Sprockets Caching
|
|
5
|
+
cache_store = SassCacheStore.new(context.environment)
|
|
6
|
+
paths = context.environment.paths.map { |path| CompassRails::SpriteImporter.new(context, path) }
|
|
7
|
+
paths += context.environment.paths.map { |path| SassImporter.new(context, path) }
|
|
8
|
+
paths += ::Rails.application.config.sass.load_paths
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
options = CompassRails.sass_config.merge( {
|
|
12
|
+
:filename => eval_file,
|
|
13
|
+
:line => line,
|
|
14
|
+
:syntax => syntax,
|
|
15
|
+
:cache_store => cache_store,
|
|
16
|
+
:importer => SassImporter.new(context, context.pathname),
|
|
17
|
+
:load_paths => paths,
|
|
18
|
+
:sprockets => {
|
|
19
|
+
:context => context,
|
|
20
|
+
:environment => context.environment
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
::Sass::Engine.new(data, options).render
|
|
25
|
+
rescue ::Sass::SyntaxError => e
|
|
26
|
+
# Annotates exception message with parse line number
|
|
27
|
+
context.__LINE__ = e.sass_backtrace.first[:line]
|
|
28
|
+
raise e
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
require 'sprockets'
|
|
2
2
|
require 'compass/sprite_importer'
|
|
3
3
|
|
|
4
|
-
module
|
|
5
|
-
class SpriteImporter <
|
|
4
|
+
module CompassRails
|
|
5
|
+
class SpriteImporter < Compass::SpriteImporter
|
|
6
|
+
attr_reader :context, :root
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
def initialize(context, root)
|
|
9
|
+
@context = context
|
|
10
|
+
@root = root
|
|
11
|
+
end
|
|
8
12
|
|
|
9
13
|
def find(uri, options)
|
|
10
|
-
|
|
11
|
-
if old = old_find(uri, options)
|
|
12
|
-
@_options = options
|
|
14
|
+
if old = super(uri, options)
|
|
13
15
|
self.class.files(uri).each do |file|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
puts file.inspect
|
|
17
|
+
relative_path = Pathname.new(file).relative_path_from(Pathname.new(root))
|
|
18
|
+
begin
|
|
19
|
+
pathname = context.resolve(relative_path)
|
|
20
|
+
context.depend_on_asset(pathname)
|
|
21
|
+
rescue Sprockets::FileNotFound
|
|
22
|
+
|
|
16
23
|
end
|
|
17
24
|
end
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
old
|
|
21
28
|
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def resolve(uri)
|
|
26
|
-
resolver.resolve(Pathname.new(uri))
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def context
|
|
30
|
-
resolver.context
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def resolver
|
|
34
|
-
@_options[:custom][:resolver]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
29
|
end
|
|
38
30
|
end
|
|
@@ -88,12 +88,16 @@ module CompassRails
|
|
|
88
88
|
class Railtie < Rails::Railtie
|
|
89
89
|
|
|
90
90
|
initializer "compass.initialize_rails", :group => :all do |app|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
if CompassRails.asset_pipeline_enabled?
|
|
92
|
+
require 'compass-rails/patches/3_1'
|
|
93
|
+
# Configure compass for use within rails, and provide the project configuration
|
|
94
|
+
# that came via the rails boot process.
|
|
95
|
+
CompassRails.check_for_double_boot!
|
|
96
|
+
Compass.discover_extensions!
|
|
97
|
+
CompassRails.configure_rails!(app)
|
|
98
|
+
else
|
|
99
|
+
CompassRails.initialize!(app.config.compass)
|
|
100
|
+
end
|
|
97
101
|
end
|
|
98
102
|
end
|
|
99
103
|
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#3.1.3
|
|
2
|
+
require 'compass'
|
|
3
|
+
require 'rails/railtie'
|
|
4
|
+
|
|
5
|
+
class Rails::Railtie::Configuration
|
|
6
|
+
# Adds compass configuration accessor to the application configuration.
|
|
7
|
+
#
|
|
8
|
+
# If a configuration file for compass exists, it will be read in and
|
|
9
|
+
# the project's configuration values will already be set on the config
|
|
10
|
+
# object.
|
|
11
|
+
#
|
|
12
|
+
# For example:
|
|
13
|
+
#
|
|
14
|
+
# module MyApp
|
|
15
|
+
# class Application < Rails::Application
|
|
16
|
+
# config.compass.line_comments = !Rails.env.production?
|
|
17
|
+
# config.compass.fonts_dir = "app/assets/fonts"
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# It is suggested that you create a compass configuration file if you
|
|
22
|
+
# want a quicker boot time when using the compass command line tool.
|
|
23
|
+
#
|
|
24
|
+
# For more information on available configuration options see:
|
|
25
|
+
# http://compass-style.org/help/tutorials/configuration-reference/
|
|
26
|
+
def compass
|
|
27
|
+
@compass ||= begin
|
|
28
|
+
data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
|
|
29
|
+
config_data
|
|
30
|
+
else
|
|
31
|
+
Compass::Configuration::Data.new("rails_config")
|
|
32
|
+
end
|
|
33
|
+
data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
|
|
34
|
+
Compass.add_configuration(:rails)
|
|
35
|
+
Compass.add_configuration(data)
|
|
36
|
+
Compass.configuration.on_sprite_saved do |filename|
|
|
37
|
+
# This is a huge hack based on reading through the sprockets internals.
|
|
38
|
+
# Sprockets needs an API for adding assets during precompilation.
|
|
39
|
+
# At a minimum sprockets should provide this API:
|
|
40
|
+
#
|
|
41
|
+
# #filename is a path in the asset source directory
|
|
42
|
+
# Rails.application.assets.new_asset!(filename)
|
|
43
|
+
#
|
|
44
|
+
# # logical_path is how devs refer to it, data is the contents of it.
|
|
45
|
+
# Rails.application.assets.new_asset!(logical_path, data)
|
|
46
|
+
#
|
|
47
|
+
# I would also like to select one of the above calls based on whether
|
|
48
|
+
# the user is precompiling or not:
|
|
49
|
+
#
|
|
50
|
+
# Rails.application.assets.precompiling? #=> true or false
|
|
51
|
+
#
|
|
52
|
+
# But even the above is not an ideal API. The issue is that compass sprites need to
|
|
53
|
+
# avoid generation if the sprite file is already generated (which can be quite time
|
|
54
|
+
# consuming). To do this, compass has it's own uniqueness hash based on the user's
|
|
55
|
+
# inputs instead of being based on the file contents. So if we could provide our own
|
|
56
|
+
# hash or some metadata that is opaque to sprockets that could be read from the
|
|
57
|
+
# asset's attributes, we could avoid cluttering the assets directory with generated
|
|
58
|
+
# sprites and always just use the logical_path + data version of the api.
|
|
59
|
+
if Rails.application.config.assets.digest && # if digesting is enabled
|
|
60
|
+
caller.grep(%r{/sprockets/rails/task.rb}).any? && #OMG HAX - check if we're being precompiled
|
|
61
|
+
Compass.configuration.generated_images_path[Compass.configuration.images_path.to_s] # if the generated images path is not in the assets images directory, we don't have to do these backflips
|
|
62
|
+
|
|
63
|
+
# Clear entries in Hike::Index for this sprite's directory.
|
|
64
|
+
# This makes sure the asset can be found by find_assets
|
|
65
|
+
Rails.application.assets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename))
|
|
66
|
+
|
|
67
|
+
pathname = Pathname.new(filename)
|
|
68
|
+
logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path))
|
|
69
|
+
asset = Rails.application.assets.find_asset(logical_path)
|
|
70
|
+
target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path)
|
|
71
|
+
|
|
72
|
+
# Adds the asset to the manifest file.
|
|
73
|
+
|
|
74
|
+
manifest = ActionView::Base.assets_manifest
|
|
75
|
+
manifest.assets[logical_path.to_s] = asset.digest_path
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Adds the fingerprinted asset to the public directory
|
|
79
|
+
FileUtils.mkdir_p File.dirname(target)
|
|
80
|
+
asset.write_to target
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
data
|
|
85
|
+
end
|
|
86
|
+
@compass
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
module CompassRails
|
|
91
|
+
class Railtie < Rails::Railtie
|
|
92
|
+
|
|
93
|
+
initializer "compass.initialize_rails", :group => :all do |app|
|
|
94
|
+
require 'compass-rails/patches/4_0'
|
|
95
|
+
# Configure compass for use within rails, and provide the project configuration
|
|
96
|
+
# that came via the rails boot process.
|
|
97
|
+
CompassRails.check_for_double_boot!
|
|
98
|
+
Compass.discover_extensions!
|
|
99
|
+
CompassRails.configure_rails!(app)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
if defined?(::Rails)
|
|
2
|
-
if CompassRails.
|
|
3
|
-
require "compass-rails/railties/2_3"
|
|
4
|
-
elsif CompassRails.rails31? || CompassRails.rails32?
|
|
2
|
+
if CompassRails.rails31? || CompassRails.rails32?
|
|
5
3
|
require "compass-rails/railties/3_1"
|
|
6
4
|
elsif CompassRails.rails3?
|
|
7
5
|
require "compass-rails/railties/3_0"
|
|
6
|
+
elsif CompassRails.rails4?
|
|
7
|
+
require "compass-rails/railties/4_0"
|
|
8
8
|
else
|
|
9
9
|
$stderr.puts "Unsupported rails environment for compass"
|
|
10
10
|
end
|
|
11
|
-
end
|
|
11
|
+
end
|