wireframe-sass-rails 3.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +13 -0
- data/README.markdown +68 -0
- data/Rakefile +12 -0
- data/lib/rails/generators/sass/assets/assets_generator.rb +13 -0
- data/lib/rails/generators/sass/assets/templates/stylesheet.css.sass +3 -0
- data/lib/rails/generators/sass/scaffold/scaffold_generator.rb +9 -0
- data/lib/rails/generators/sass_scaffold.rb +16 -0
- data/lib/rails/generators/scss/assets/assets_generator.rb +13 -0
- data/lib/rails/generators/scss/assets/templates/stylesheet.css.scss +3 -0
- data/lib/rails/generators/scss/scaffold/scaffold_generator.rb +10 -0
- data/lib/sass-rails.rb +1 -0
- data/lib/sass/rails.rb +12 -0
- data/lib/sass/rails/compressor.rb +15 -0
- data/lib/sass/rails/helpers.rb +38 -0
- data/lib/sass/rails/importer.rb +122 -0
- data/lib/sass/rails/logger.rb +21 -0
- data/lib/sass/rails/railtie.rb +74 -0
- data/lib/sass/rails/template_handlers.rb +86 -0
- data/lib/sass/rails/version.rb +5 -0
- data/sass-rails.gemspec +25 -0
- data/test/fixtures/engine_project/.gitignore +6 -0
- data/test/fixtures/engine_project/Gemfile +7 -0
- data/test/fixtures/engine_project/README.rdoc +3 -0
- data/test/fixtures/engine_project/Rakefile +39 -0
- data/test/fixtures/engine_project/app/assets/images/engine_project/.gitkeep +0 -0
- data/test/fixtures/engine_project/app/assets/javascripts/engine_project/application.js +9 -0
- data/test/fixtures/engine_project/app/assets/stylesheets/engine_project/application.css +7 -0
- data/test/fixtures/engine_project/app/controllers/engine_project/application_controller.rb +4 -0
- data/test/fixtures/engine_project/app/helpers/engine_project/application_helper.rb +4 -0
- data/test/fixtures/engine_project/app/views/layouts/engine_project/application.html.erb +14 -0
- data/test/fixtures/engine_project/config/routes.rb +2 -0
- data/test/fixtures/engine_project/lib/engine_project.rb +4 -0
- data/test/fixtures/engine_project/lib/engine_project/engine.rb +5 -0
- data/test/fixtures/engine_project/lib/engine_project/version.rb +3 -0
- data/test/fixtures/engine_project/lib/tasks/engine_project_tasks.rake +4 -0
- data/test/fixtures/engine_project/script/rails +6 -0
- data/test/fixtures/engine_project/test/dummy/Rakefile +7 -0
- data/test/fixtures/engine_project/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/fixtures/engine_project/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/fixtures/engine_project/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/engine_project/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/engine_project/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/fixtures/engine_project/test/dummy/app/models/.gitkeep +0 -0
- data/test/fixtures/engine_project/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/fixtures/engine_project/test/dummy/config.ru +4 -0
- data/test/fixtures/engine_project/test/dummy/config/application.rb +42 -0
- data/test/fixtures/engine_project/test/dummy/config/boot.rb +10 -0
- data/test/fixtures/engine_project/test/dummy/config/database.yml +25 -0
- data/test/fixtures/engine_project/test/dummy/config/environment.rb +5 -0
- data/test/fixtures/engine_project/test/dummy/config/environments/development.rb +27 -0
- data/test/fixtures/engine_project/test/dummy/config/environments/production.rb +51 -0
- data/test/fixtures/engine_project/test/dummy/config/environments/test.rb +39 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/fixtures/engine_project/test/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/test/fixtures/engine_project/test/dummy/config/locales/en.yml +5 -0
- data/test/fixtures/engine_project/test/dummy/config/routes.rb +4 -0
- data/test/fixtures/engine_project/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/fixtures/engine_project/test/dummy/log/.gitkeep +0 -0
- data/test/fixtures/engine_project/test/dummy/public/404.html +26 -0
- data/test/fixtures/engine_project/test/dummy/public/422.html +26 -0
- data/test/fixtures/engine_project/test/dummy/public/500.html +26 -0
- data/test/fixtures/engine_project/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/engine_project/test/dummy/script/rails +6 -0
- data/test/fixtures/sass_project/.gitignore +5 -0
- data/test/fixtures/sass_project/Gemfile +7 -0
- data/test/fixtures/sass_project/README +261 -0
- data/test/fixtures/sass_project/Rakefile +7 -0
- data/test/fixtures/sass_project/app/assets/images/rails.png +0 -0
- data/test/fixtures/sass_project/app/assets/javascripts/application.js +9 -0
- data/test/fixtures/sass_project/app/assets/stylesheets/application.css +7 -0
- data/test/fixtures/sass_project/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/sass_project/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/sass_project/app/mailers/.gitkeep +0 -0
- data/test/fixtures/sass_project/app/models/.gitkeep +0 -0
- data/test/fixtures/sass_project/app/views/layouts/application.html.erb +14 -0
- data/test/fixtures/sass_project/config.ru +4 -0
- data/test/fixtures/sass_project/config/application.rb +52 -0
- data/test/fixtures/sass_project/config/boot.rb +6 -0
- data/test/fixtures/sass_project/config/database.yml +25 -0
- data/test/fixtures/sass_project/config/environment.rb +5 -0
- data/test/fixtures/sass_project/config/environments/development.rb +27 -0
- data/test/fixtures/sass_project/config/environments/production.rb +54 -0
- data/test/fixtures/sass_project/config/environments/test.rb +39 -0
- data/test/fixtures/sass_project/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/sass_project/config/initializers/inflections.rb +10 -0
- data/test/fixtures/sass_project/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/sass_project/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/sass_project/config/initializers/session_store.rb +8 -0
- data/test/fixtures/sass_project/config/initializers/wrap_parameters.rb +12 -0
- data/test/fixtures/sass_project/config/locales/en.yml +5 -0
- data/test/fixtures/sass_project/config/routes.rb +58 -0
- data/test/fixtures/sass_project/db/seeds.rb +7 -0
- data/test/fixtures/sass_project/doc/README_FOR_APP +2 -0
- data/test/fixtures/sass_project/lib/tasks/.gitkeep +0 -0
- data/test/fixtures/sass_project/log/.gitkeep +0 -0
- data/test/fixtures/sass_project/public/404.html +26 -0
- data/test/fixtures/sass_project/public/422.html +26 -0
- data/test/fixtures/sass_project/public/500.html +26 -0
- data/test/fixtures/sass_project/public/favicon.ico +0 -0
- data/test/fixtures/sass_project/public/index.html +241 -0
- data/test/fixtures/sass_project/public/robots.txt +5 -0
- data/test/fixtures/sass_project/script/rails +6 -0
- data/test/fixtures/sass_project/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/fixtures/sass_project/vendor/plugins/.gitkeep +0 -0
- data/test/fixtures/scss_project/.gitignore +5 -0
- data/test/fixtures/scss_project/Gemfile +7 -0
- data/test/fixtures/scss_project/README +261 -0
- data/test/fixtures/scss_project/Rakefile +7 -0
- data/test/fixtures/scss_project/app/assets/images/rails.png +0 -0
- data/test/fixtures/scss_project/app/assets/javascripts/application.js +9 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/_top_level_partial.css.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/application.css.scss +19 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/css_application.css +7 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/globbed/globbed.css.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/globbed/nested/nested_glob.css.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/_sass_import.css.sass +5 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/_scss_import.css.scss +9 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/_without_css_ext.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/_relative_sass.css.sass +2 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/_relative_scss.css.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/relative_not_a_partial.css.scss +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/another_plain.css +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/plain.css +3 -0
- data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/second_level.css.scss +1 -0
- data/test/fixtures/scss_project/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/scss_project/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/scss_project/app/mailers/.gitkeep +0 -0
- data/test/fixtures/scss_project/app/models/.gitkeep +0 -0
- data/test/fixtures/scss_project/app/views/layouts/application.html.erb +14 -0
- data/test/fixtures/scss_project/config.ru +4 -0
- data/test/fixtures/scss_project/config/application.rb +49 -0
- data/test/fixtures/scss_project/config/boot.rb +6 -0
- data/test/fixtures/scss_project/config/database.yml +25 -0
- data/test/fixtures/scss_project/config/environment.rb +5 -0
- data/test/fixtures/scss_project/config/environments/development.rb +27 -0
- data/test/fixtures/scss_project/config/environments/production.rb +54 -0
- data/test/fixtures/scss_project/config/environments/test.rb +39 -0
- data/test/fixtures/scss_project/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/scss_project/config/initializers/inflections.rb +10 -0
- data/test/fixtures/scss_project/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/scss_project/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/scss_project/config/initializers/session_store.rb +8 -0
- data/test/fixtures/scss_project/config/initializers/wrap_parameters.rb +12 -0
- data/test/fixtures/scss_project/config/locales/en.yml +5 -0
- data/test/fixtures/scss_project/config/routes.rb +58 -0
- data/test/fixtures/scss_project/db/seeds.rb +7 -0
- data/test/fixtures/scss_project/doc/README_FOR_APP +2 -0
- data/test/fixtures/scss_project/lib/tasks/.gitkeep +0 -0
- data/test/fixtures/scss_project/log/.gitkeep +0 -0
- data/test/fixtures/scss_project/public/404.html +26 -0
- data/test/fixtures/scss_project/public/422.html +26 -0
- data/test/fixtures/scss_project/public/500.html +26 -0
- data/test/fixtures/scss_project/public/favicon.ico +0 -0
- data/test/fixtures/scss_project/public/index.html +241 -0
- data/test/fixtures/scss_project/public/robots.txt +5 -0
- data/test/fixtures/scss_project/script/rails +6 -0
- data/test/fixtures/scss_project/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/fixtures/scss_project/vendor/plugins/.gitkeep +0 -0
- data/test/sass_rails_logger_test.rb +26 -0
- data/test/sass_rails_test.rb +88 -0
- data/test/support/sass_rails_test_case.rb +151 -0
- data/test/test_helper.rb +28 -0
- metadata +427 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in sass-rails.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "sfl", "~> 2.0"
|
7
|
+
gem "sprockets"
|
8
|
+
gem "mocha"
|
9
|
+
|
10
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
11
|
+
# gem 'ruby-debug'
|
12
|
+
# gem 'ruby-debug19'
|
13
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Official Ruby-on-Rails Integration with Sass
|
2
|
+
|
3
|
+
This gem provides official integration for ruby on rails projects with the Sass stylesheet language.
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
Since rails 3.1, new rails projects will be already configured to use Sass. If you are upgrading to rails 3.1 you will need to add the following to your Gemfile:
|
8
|
+
|
9
|
+
gem 'sass-rails'
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
To configure Sass via rails set use `config.sass` in your
|
14
|
+
application and/or environment files to set configuration
|
15
|
+
properties that will be passed to Sass.
|
16
|
+
|
17
|
+
### Example
|
18
|
+
|
19
|
+
MyProject::Application.configure do
|
20
|
+
config.sass.line_comments = false
|
21
|
+
config.sass.syntax = :nested
|
22
|
+
end
|
23
|
+
|
24
|
+
### Options
|
25
|
+
|
26
|
+
The [list of supported options](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options) can be found on the Sass Website with the following caveats:
|
27
|
+
|
28
|
+
1. Output compression is now controlled via the `config.assets.compress` boolean option instead of through the `:style` option.
|
29
|
+
2. `:never_update` - This option is not supported. Instead set `config.assets.enabled = false`
|
30
|
+
3. `:always_update` - This option is not supported. Sprockets uses a controller to access stylesheets in development mode instead of a full scan for changed files.
|
31
|
+
4. `:always_check` - This option is not supported. Sprockets always checks in development.
|
32
|
+
5. `:syntax` - This is determined by the file's extensions.
|
33
|
+
6. `:filename` - This is determined by the file's name.
|
34
|
+
7. `:line` - This is provided by the template handler.
|
35
|
+
|
36
|
+
## Features
|
37
|
+
|
38
|
+
* **Glob Imports**. When in rails, there is a special import syntax that allows you to
|
39
|
+
glob imports relative to the folder of the stylesheet that is doing the importing.
|
40
|
+
E.g. `@import "mixins/*"` will import all the files in the mixins folder and
|
41
|
+
`@import "mixins/**/*"` will import all the files in the mixins tree.
|
42
|
+
Any valid ruby glob may be used. The imports are sorted alphabetically.
|
43
|
+
**NOTE:** It is recommended that you only use this when importing pure library
|
44
|
+
files (containing mixins and variables) because it is difficult to control the
|
45
|
+
cascade ordering for imports that contain styles using this approach.
|
46
|
+
|
47
|
+
* **Asset Helpers**. When using the asset pipeline, paths to assets must be rewritten.
|
48
|
+
When referencing assets use the following asset helpers:
|
49
|
+
|
50
|
+
* `asset_path($relative-asset-path, $asset-class)` - Returns a string to the asset.
|
51
|
+
For example: `asset_path("rails.png", image)` becomes `"/assets/rails.png"`
|
52
|
+
* `asset_url($relative-asset-path, $asset-class)` - Returns url reference to the asset.
|
53
|
+
|
54
|
+
For example: `asset_url("rails.png", image)` becomes `url(/assets/rails.png)`
|
55
|
+
* As a convenience, for each of the following asset classes there are
|
56
|
+
corresponding `_path` and `_url` helpers:
|
57
|
+
image, font, video, audio, javascript, stylesheet.
|
58
|
+
|
59
|
+
For example: `image_url("rails.png")` becomes `url(/assets/rails.png)` and
|
60
|
+
`image_path("rails.png")` becomes `"/assets/rails.png"`.
|
61
|
+
|
62
|
+
|
63
|
+
## Running Tests
|
64
|
+
|
65
|
+
$ bundle install
|
66
|
+
$ bundle exec rake test
|
67
|
+
|
68
|
+
If you need to test against local gems, use Bundler's gem :path option in the Gemfile and also edit `test/support/test_helper.rb` and tell the tests where the gem is checked out.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Generators
|
5
|
+
class AssetsGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def copy_sass
|
9
|
+
template "stylesheet.css.sass", File.join('app/assets/stylesheets', class_path, "#{file_name}.css.sass")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "sass/css"
|
2
|
+
require "rails/generators/named_base"
|
3
|
+
|
4
|
+
module Sass
|
5
|
+
module Generators
|
6
|
+
class ScaffoldBase < ::Rails::Generators::NamedBase
|
7
|
+
def copy_stylesheet
|
8
|
+
dir = ::Rails::Generators::ScaffoldGenerator.source_root
|
9
|
+
file = File.join(dir, "scaffold.css")
|
10
|
+
converted_contents = ::Sass::CSS.new(File.read(file)).render(syntax)
|
11
|
+
create_file "app/assets/stylesheets/scaffolds.css.#{syntax}", converted_contents
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
|
3
|
+
module Scss
|
4
|
+
module Generators
|
5
|
+
class AssetsGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def copy_scss
|
9
|
+
template "stylesheet.css.scss", File.join('app/assets/stylesheets', class_path, "#{file_name}.css.scss")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/sass-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sass/rails'
|
data/lib/sass/rails.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Sass
|
2
|
+
module Rails
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'sass/rails/compressor'
|
7
|
+
require 'sass/rails/logger'
|
8
|
+
require 'sass/rails/railtie'
|
9
|
+
require 'sass/rails/helpers'
|
10
|
+
require 'sass/rails/importer'
|
11
|
+
require 'sass/rails/template_handlers'
|
12
|
+
require 'sass/rails/version'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Sass
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def asset_path(asset, kind)
|
6
|
+
Sass::Script::String.new(public_path(asset.value, kind.value), true)
|
7
|
+
end
|
8
|
+
|
9
|
+
def asset_url(asset, kind)
|
10
|
+
Sass::Script::String.new(%Q{url(#{public_path(asset.value, kind.value)})})
|
11
|
+
end
|
12
|
+
|
13
|
+
[:image, :font, :video, :audio, :javascript, :stylesheet].each do |asset_class|
|
14
|
+
class_eval %Q{
|
15
|
+
def #{asset_class}_path(asset)
|
16
|
+
asset_path(asset, Sass::Script::String.new("#{asset_class}"))
|
17
|
+
end
|
18
|
+
def #{asset_class}_url(asset)
|
19
|
+
asset_url(asset, Sass::Script::String.new("#{asset_class}"))
|
20
|
+
end
|
21
|
+
}, __FILE__, __LINE__ - 6
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def public_path(asset, kind)
|
26
|
+
options[:custom][:resolver].public_path(asset, kind.pluralize)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Sass
|
33
|
+
module Script
|
34
|
+
module Functions
|
35
|
+
include Sass::Rails::Helpers
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
|
3
|
+
module Sass::Rails
|
4
|
+
class Importer
|
5
|
+
GLOB = /\*|\[.+\]/
|
6
|
+
PARTIAL = /^_/
|
7
|
+
HAS_EXTENSION = /\.css(.s[ac]ss)?$/
|
8
|
+
|
9
|
+
SASS_EXTENSIONS = {
|
10
|
+
".css.sass" => :sass,
|
11
|
+
".css.scss" => :scss,
|
12
|
+
".sass" => :sass,
|
13
|
+
".scss" => :scss
|
14
|
+
}
|
15
|
+
attr_reader :context
|
16
|
+
|
17
|
+
def initialize(context)
|
18
|
+
@context = context
|
19
|
+
@resolver = Resolver.new(context)
|
20
|
+
end
|
21
|
+
|
22
|
+
def sass_file?(filename)
|
23
|
+
filename = filename.to_s
|
24
|
+
SASS_EXTENSIONS.keys.any?{|ext| filename[ext]}
|
25
|
+
end
|
26
|
+
|
27
|
+
def syntax(filename)
|
28
|
+
filename = filename.to_s
|
29
|
+
SASS_EXTENSIONS.each {|ext, syntax| return syntax if filename[(ext.size+2)..-1][ext]}
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolve(name, base_pathname = nil)
|
34
|
+
name = Pathname.new(name)
|
35
|
+
if base_pathname && base_pathname.to_s.size > 0
|
36
|
+
root = Pathname.new(context.root_path)
|
37
|
+
name = base_pathname.relative_path_from(root).join(name)
|
38
|
+
end
|
39
|
+
partial_name = name.dirname.join("_#{name.basename}")
|
40
|
+
@resolver.resolve(name) || @resolver.resolve(partial_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_relative(name, base, options)
|
44
|
+
base_pathname = Pathname.new(base)
|
45
|
+
if name =~ GLOB
|
46
|
+
glob_imports(name, base_pathname, options)
|
47
|
+
elsif pathname = resolve(name, base_pathname.dirname)
|
48
|
+
context.depend_on(pathname)
|
49
|
+
if sass_file?(pathname)
|
50
|
+
Sass::Engine.new(pathname.read, options.merge(:filename => pathname.to_s, :importer => self, :syntax => syntax(pathname)))
|
51
|
+
else
|
52
|
+
Sass::Engine.new(@resolver.process(pathname), options.merge(:filename => pathname.to_s, :importer => self, :syntax => :scss))
|
53
|
+
end
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def find(name, options)
|
60
|
+
if name =~ GLOB
|
61
|
+
nil # globs must be relative
|
62
|
+
elsif pathname = resolve(name)
|
63
|
+
context.depend_on(pathname)
|
64
|
+
if sass_file?(pathname)
|
65
|
+
Sass::Engine.new(pathname.read, options.merge(:filename => pathname.to_s, :importer => self, :syntax => syntax(pathname)))
|
66
|
+
else
|
67
|
+
Sass::Engine.new(@resolver.process(pathname), options.merge(:filename => pathname.to_s, :importer => self, :syntax => :scss))
|
68
|
+
end
|
69
|
+
else
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def each_globbed_file(glob, base_pathname, options)
|
75
|
+
Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
|
76
|
+
next if filename == options[:filename]
|
77
|
+
yield filename if File.directory?(filename) || context.asset_requirable?(filename)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def glob_imports(glob, base_pathname, options)
|
82
|
+
contents = ""
|
83
|
+
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
|
84
|
+
if File.directory?(filename)
|
85
|
+
context.depend_on(filename)
|
86
|
+
elsif context.asset_requirable?(filename)
|
87
|
+
context.depend_on(filename)
|
88
|
+
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
return nil if contents.empty?
|
92
|
+
Sass::Engine.new(contents, options.merge(
|
93
|
+
:filename => base_pathname.to_s,
|
94
|
+
:importer => self,
|
95
|
+
:syntax => :scss
|
96
|
+
))
|
97
|
+
end
|
98
|
+
|
99
|
+
def mtime(name, options)
|
100
|
+
if name =~ GLOB && options[:filename]
|
101
|
+
mtime = nil
|
102
|
+
each_globbed_file(name, Pathname.new(options[:filename]).dirname, options) do |p|
|
103
|
+
mtime ||= File.mtime(p)
|
104
|
+
mtime = [mtime, File.mtime(p)].max
|
105
|
+
end
|
106
|
+
mtime
|
107
|
+
elsif pathname = resolve(name)
|
108
|
+
pathname.mtime
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def key(name, options)
|
113
|
+
["Sprockets:" + File.dirname(File.expand_path(name)), File.basename(name)]
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
"Sass::Rails::Importer(#{context.pathname})"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sass/logger'
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Rails
|
5
|
+
class Logger < Sass::Logger::Base
|
6
|
+
def _log(level, message)
|
7
|
+
|
8
|
+
case level
|
9
|
+
when :trace, :debug
|
10
|
+
::Rails.logger.debug message
|
11
|
+
when :warn
|
12
|
+
::Rails.logger.warn message
|
13
|
+
when :error
|
14
|
+
::Rails.logger.error message
|
15
|
+
when :info
|
16
|
+
::Rails.logger.info message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'sprockets/railtie'
|
2
|
+
|
3
|
+
module Sass::Rails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
module SassContext
|
6
|
+
attr_accessor :sass_config
|
7
|
+
end
|
8
|
+
config.sass = ActiveSupport::OrderedOptions.new
|
9
|
+
# Establish static configuration defaults
|
10
|
+
# Emit scss files during stylesheet generation of scaffold
|
11
|
+
config.sass.preferred_syntax = :scss
|
12
|
+
# Use expanded output instead of the sass default of :nested
|
13
|
+
config.sass.style = :expanded
|
14
|
+
# Write sass cache files for performance
|
15
|
+
config.sass.cache = true
|
16
|
+
# Read sass cache files for performance
|
17
|
+
config.sass.read_cache = true
|
18
|
+
# Display line comments above each selector as a debugging aid
|
19
|
+
config.sass.line_comments = true
|
20
|
+
# Initialize the load paths to an empty array
|
21
|
+
config.sass.load_paths = []
|
22
|
+
# Send Sass logs to Rails.logger
|
23
|
+
config.sass.logger = Sass::Rails::Logger.new
|
24
|
+
|
25
|
+
# Set the default stylesheet engine
|
26
|
+
# It can be overridedden by passing:
|
27
|
+
# --stylesheet_engine=sass
|
28
|
+
# to the rails generate command
|
29
|
+
config.app_generators.stylesheet_engine config.sass.preferred_syntax
|
30
|
+
|
31
|
+
config.before_initialize do |app|
|
32
|
+
unless app.config.assets && app.config.assets.enabled
|
33
|
+
raise "The sass-rails plugin requires the asset pipeline to be enabled."
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'sass'
|
37
|
+
Sprockets::Engines #force autoloading
|
38
|
+
Sprockets.register_engine '.sass', Sass::Rails::SassTemplate
|
39
|
+
Sprockets.register_engine '.scss', Sass::Rails::ScssTemplate
|
40
|
+
end
|
41
|
+
|
42
|
+
initializer :setup_sass do |app|
|
43
|
+
# Only emit one kind of syntax because though we have registered two kinds of generators
|
44
|
+
syntax = app.config.sass.preferred_syntax.to_sym
|
45
|
+
alt_syntax = syntax == :sass ? "scss" : "sass"
|
46
|
+
app.config.generators.hide_namespace alt_syntax
|
47
|
+
|
48
|
+
# Override stylesheet engine to the preferred syntax
|
49
|
+
config.app_generators.stylesheet_engine syntax
|
50
|
+
|
51
|
+
# Set the sass cache location
|
52
|
+
config.sass.cache_location = File.join(Rails.root, "tmp/cache/sass")
|
53
|
+
|
54
|
+
# Establish configuration defaults that are evironmental in nature
|
55
|
+
if config.sass.full_exception.nil?
|
56
|
+
# Display a stack trace in the css output when in development-like environments.
|
57
|
+
config.sass.full_exception = app.config.consider_all_requests_local
|
58
|
+
end
|
59
|
+
app.assets.context_class.extend(SassContext)
|
60
|
+
app.assets.context_class.sass_config = app.config.sass
|
61
|
+
end
|
62
|
+
|
63
|
+
initializer :setup_compression do |app|
|
64
|
+
if app.config.assets.compress
|
65
|
+
# Use sass's css_compressor
|
66
|
+
app.config.assets.css_compressor = CssCompressor.new
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
config.after_initialize do |app|
|
71
|
+
Sass::logger = app.config.sass.logger
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|