wireframe-sass-rails 3.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +13 -0
  3. data/README.markdown +68 -0
  4. data/Rakefile +12 -0
  5. data/lib/rails/generators/sass/assets/assets_generator.rb +13 -0
  6. data/lib/rails/generators/sass/assets/templates/stylesheet.css.sass +3 -0
  7. data/lib/rails/generators/sass/scaffold/scaffold_generator.rb +9 -0
  8. data/lib/rails/generators/sass_scaffold.rb +16 -0
  9. data/lib/rails/generators/scss/assets/assets_generator.rb +13 -0
  10. data/lib/rails/generators/scss/assets/templates/stylesheet.css.scss +3 -0
  11. data/lib/rails/generators/scss/scaffold/scaffold_generator.rb +10 -0
  12. data/lib/sass-rails.rb +1 -0
  13. data/lib/sass/rails.rb +12 -0
  14. data/lib/sass/rails/compressor.rb +15 -0
  15. data/lib/sass/rails/helpers.rb +38 -0
  16. data/lib/sass/rails/importer.rb +122 -0
  17. data/lib/sass/rails/logger.rb +21 -0
  18. data/lib/sass/rails/railtie.rb +74 -0
  19. data/lib/sass/rails/template_handlers.rb +86 -0
  20. data/lib/sass/rails/version.rb +5 -0
  21. data/sass-rails.gemspec +25 -0
  22. data/test/fixtures/engine_project/.gitignore +6 -0
  23. data/test/fixtures/engine_project/Gemfile +7 -0
  24. data/test/fixtures/engine_project/README.rdoc +3 -0
  25. data/test/fixtures/engine_project/Rakefile +39 -0
  26. data/test/fixtures/engine_project/app/assets/images/engine_project/.gitkeep +0 -0
  27. data/test/fixtures/engine_project/app/assets/javascripts/engine_project/application.js +9 -0
  28. data/test/fixtures/engine_project/app/assets/stylesheets/engine_project/application.css +7 -0
  29. data/test/fixtures/engine_project/app/controllers/engine_project/application_controller.rb +4 -0
  30. data/test/fixtures/engine_project/app/helpers/engine_project/application_helper.rb +4 -0
  31. data/test/fixtures/engine_project/app/views/layouts/engine_project/application.html.erb +14 -0
  32. data/test/fixtures/engine_project/config/routes.rb +2 -0
  33. data/test/fixtures/engine_project/lib/engine_project.rb +4 -0
  34. data/test/fixtures/engine_project/lib/engine_project/engine.rb +5 -0
  35. data/test/fixtures/engine_project/lib/engine_project/version.rb +3 -0
  36. data/test/fixtures/engine_project/lib/tasks/engine_project_tasks.rake +4 -0
  37. data/test/fixtures/engine_project/script/rails +6 -0
  38. data/test/fixtures/engine_project/test/dummy/Rakefile +7 -0
  39. data/test/fixtures/engine_project/test/dummy/app/assets/javascripts/application.js +9 -0
  40. data/test/fixtures/engine_project/test/dummy/app/assets/stylesheets/application.css +7 -0
  41. data/test/fixtures/engine_project/test/dummy/app/controllers/application_controller.rb +3 -0
  42. data/test/fixtures/engine_project/test/dummy/app/helpers/application_helper.rb +2 -0
  43. data/test/fixtures/engine_project/test/dummy/app/mailers/.gitkeep +0 -0
  44. data/test/fixtures/engine_project/test/dummy/app/models/.gitkeep +0 -0
  45. data/test/fixtures/engine_project/test/dummy/app/views/layouts/application.html.erb +14 -0
  46. data/test/fixtures/engine_project/test/dummy/config.ru +4 -0
  47. data/test/fixtures/engine_project/test/dummy/config/application.rb +42 -0
  48. data/test/fixtures/engine_project/test/dummy/config/boot.rb +10 -0
  49. data/test/fixtures/engine_project/test/dummy/config/database.yml +25 -0
  50. data/test/fixtures/engine_project/test/dummy/config/environment.rb +5 -0
  51. data/test/fixtures/engine_project/test/dummy/config/environments/development.rb +27 -0
  52. data/test/fixtures/engine_project/test/dummy/config/environments/production.rb +51 -0
  53. data/test/fixtures/engine_project/test/dummy/config/environments/test.rb +39 -0
  54. data/test/fixtures/engine_project/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/test/fixtures/engine_project/test/dummy/config/initializers/inflections.rb +10 -0
  56. data/test/fixtures/engine_project/test/dummy/config/initializers/mime_types.rb +5 -0
  57. data/test/fixtures/engine_project/test/dummy/config/initializers/secret_token.rb +7 -0
  58. data/test/fixtures/engine_project/test/dummy/config/initializers/session_store.rb +8 -0
  59. data/test/fixtures/engine_project/test/dummy/config/initializers/wrap_parameters.rb +12 -0
  60. data/test/fixtures/engine_project/test/dummy/config/locales/en.yml +5 -0
  61. data/test/fixtures/engine_project/test/dummy/config/routes.rb +4 -0
  62. data/test/fixtures/engine_project/test/dummy/lib/assets/.gitkeep +0 -0
  63. data/test/fixtures/engine_project/test/dummy/log/.gitkeep +0 -0
  64. data/test/fixtures/engine_project/test/dummy/public/404.html +26 -0
  65. data/test/fixtures/engine_project/test/dummy/public/422.html +26 -0
  66. data/test/fixtures/engine_project/test/dummy/public/500.html +26 -0
  67. data/test/fixtures/engine_project/test/dummy/public/favicon.ico +0 -0
  68. data/test/fixtures/engine_project/test/dummy/script/rails +6 -0
  69. data/test/fixtures/sass_project/.gitignore +5 -0
  70. data/test/fixtures/sass_project/Gemfile +7 -0
  71. data/test/fixtures/sass_project/README +261 -0
  72. data/test/fixtures/sass_project/Rakefile +7 -0
  73. data/test/fixtures/sass_project/app/assets/images/rails.png +0 -0
  74. data/test/fixtures/sass_project/app/assets/javascripts/application.js +9 -0
  75. data/test/fixtures/sass_project/app/assets/stylesheets/application.css +7 -0
  76. data/test/fixtures/sass_project/app/controllers/application_controller.rb +3 -0
  77. data/test/fixtures/sass_project/app/helpers/application_helper.rb +2 -0
  78. data/test/fixtures/sass_project/app/mailers/.gitkeep +0 -0
  79. data/test/fixtures/sass_project/app/models/.gitkeep +0 -0
  80. data/test/fixtures/sass_project/app/views/layouts/application.html.erb +14 -0
  81. data/test/fixtures/sass_project/config.ru +4 -0
  82. data/test/fixtures/sass_project/config/application.rb +52 -0
  83. data/test/fixtures/sass_project/config/boot.rb +6 -0
  84. data/test/fixtures/sass_project/config/database.yml +25 -0
  85. data/test/fixtures/sass_project/config/environment.rb +5 -0
  86. data/test/fixtures/sass_project/config/environments/development.rb +27 -0
  87. data/test/fixtures/sass_project/config/environments/production.rb +54 -0
  88. data/test/fixtures/sass_project/config/environments/test.rb +39 -0
  89. data/test/fixtures/sass_project/config/initializers/backtrace_silencers.rb +7 -0
  90. data/test/fixtures/sass_project/config/initializers/inflections.rb +10 -0
  91. data/test/fixtures/sass_project/config/initializers/mime_types.rb +5 -0
  92. data/test/fixtures/sass_project/config/initializers/secret_token.rb +7 -0
  93. data/test/fixtures/sass_project/config/initializers/session_store.rb +8 -0
  94. data/test/fixtures/sass_project/config/initializers/wrap_parameters.rb +12 -0
  95. data/test/fixtures/sass_project/config/locales/en.yml +5 -0
  96. data/test/fixtures/sass_project/config/routes.rb +58 -0
  97. data/test/fixtures/sass_project/db/seeds.rb +7 -0
  98. data/test/fixtures/sass_project/doc/README_FOR_APP +2 -0
  99. data/test/fixtures/sass_project/lib/tasks/.gitkeep +0 -0
  100. data/test/fixtures/sass_project/log/.gitkeep +0 -0
  101. data/test/fixtures/sass_project/public/404.html +26 -0
  102. data/test/fixtures/sass_project/public/422.html +26 -0
  103. data/test/fixtures/sass_project/public/500.html +26 -0
  104. data/test/fixtures/sass_project/public/favicon.ico +0 -0
  105. data/test/fixtures/sass_project/public/index.html +241 -0
  106. data/test/fixtures/sass_project/public/robots.txt +5 -0
  107. data/test/fixtures/sass_project/script/rails +6 -0
  108. data/test/fixtures/sass_project/vendor/assets/stylesheets/.gitkeep +0 -0
  109. data/test/fixtures/sass_project/vendor/plugins/.gitkeep +0 -0
  110. data/test/fixtures/scss_project/.gitignore +5 -0
  111. data/test/fixtures/scss_project/Gemfile +7 -0
  112. data/test/fixtures/scss_project/README +261 -0
  113. data/test/fixtures/scss_project/Rakefile +7 -0
  114. data/test/fixtures/scss_project/app/assets/images/rails.png +0 -0
  115. data/test/fixtures/scss_project/app/assets/javascripts/application.js +9 -0
  116. data/test/fixtures/scss_project/app/assets/stylesheets/_top_level_partial.css.scss +3 -0
  117. data/test/fixtures/scss_project/app/assets/stylesheets/application.css.scss +19 -0
  118. data/test/fixtures/scss_project/app/assets/stylesheets/css_application.css +7 -0
  119. data/test/fixtures/scss_project/app/assets/stylesheets/globbed/globbed.css.scss +3 -0
  120. data/test/fixtures/scss_project/app/assets/stylesheets/globbed/nested/nested_glob.css.scss +3 -0
  121. data/test/fixtures/scss_project/app/assets/stylesheets/partials/_sass_import.css.sass +5 -0
  122. data/test/fixtures/scss_project/app/assets/stylesheets/partials/_scss_import.css.scss +9 -0
  123. data/test/fixtures/scss_project/app/assets/stylesheets/partials/_without_css_ext.scss +3 -0
  124. data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/_relative_sass.css.sass +2 -0
  125. data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/_relative_scss.css.scss +3 -0
  126. data/test/fixtures/scss_project/app/assets/stylesheets/partials/subfolder/relative_not_a_partial.css.scss +3 -0
  127. data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/another_plain.css +3 -0
  128. data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/plain.css +3 -0
  129. data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/second_level.css.scss +1 -0
  130. data/test/fixtures/scss_project/app/controllers/application_controller.rb +3 -0
  131. data/test/fixtures/scss_project/app/helpers/application_helper.rb +2 -0
  132. data/test/fixtures/scss_project/app/mailers/.gitkeep +0 -0
  133. data/test/fixtures/scss_project/app/models/.gitkeep +0 -0
  134. data/test/fixtures/scss_project/app/views/layouts/application.html.erb +14 -0
  135. data/test/fixtures/scss_project/config.ru +4 -0
  136. data/test/fixtures/scss_project/config/application.rb +49 -0
  137. data/test/fixtures/scss_project/config/boot.rb +6 -0
  138. data/test/fixtures/scss_project/config/database.yml +25 -0
  139. data/test/fixtures/scss_project/config/environment.rb +5 -0
  140. data/test/fixtures/scss_project/config/environments/development.rb +27 -0
  141. data/test/fixtures/scss_project/config/environments/production.rb +54 -0
  142. data/test/fixtures/scss_project/config/environments/test.rb +39 -0
  143. data/test/fixtures/scss_project/config/initializers/backtrace_silencers.rb +7 -0
  144. data/test/fixtures/scss_project/config/initializers/inflections.rb +10 -0
  145. data/test/fixtures/scss_project/config/initializers/mime_types.rb +5 -0
  146. data/test/fixtures/scss_project/config/initializers/secret_token.rb +7 -0
  147. data/test/fixtures/scss_project/config/initializers/session_store.rb +8 -0
  148. data/test/fixtures/scss_project/config/initializers/wrap_parameters.rb +12 -0
  149. data/test/fixtures/scss_project/config/locales/en.yml +5 -0
  150. data/test/fixtures/scss_project/config/routes.rb +58 -0
  151. data/test/fixtures/scss_project/db/seeds.rb +7 -0
  152. data/test/fixtures/scss_project/doc/README_FOR_APP +2 -0
  153. data/test/fixtures/scss_project/lib/tasks/.gitkeep +0 -0
  154. data/test/fixtures/scss_project/log/.gitkeep +0 -0
  155. data/test/fixtures/scss_project/public/404.html +26 -0
  156. data/test/fixtures/scss_project/public/422.html +26 -0
  157. data/test/fixtures/scss_project/public/500.html +26 -0
  158. data/test/fixtures/scss_project/public/favicon.ico +0 -0
  159. data/test/fixtures/scss_project/public/index.html +241 -0
  160. data/test/fixtures/scss_project/public/robots.txt +5 -0
  161. data/test/fixtures/scss_project/script/rails +6 -0
  162. data/test/fixtures/scss_project/vendor/assets/stylesheets/.gitkeep +0 -0
  163. data/test/fixtures/scss_project/vendor/plugins/.gitkeep +0 -0
  164. data/test/sass_rails_logger_test.rb +26 -0
  165. data/test/sass_rails_test.rb +88 -0
  166. data/test/support/sass_rails_test_case.rb +151 -0
  167. data/test/test_helper.rb +28 -0
  168. metadata +427 -0
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .sass-cache
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
+
@@ -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.
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
@@ -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,3 @@
1
+ // Place all the styles related to the <%= name %> controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass here: http://sass-lang.com/
@@ -0,0 +1,9 @@
1
+ require "rails/generators/sass_scaffold"
2
+
3
+ module Sass
4
+ module Generators
5
+ class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
6
+ def syntax() :sass end
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the <%= name %> controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,10 @@
1
+ require "rails/generators/sass_scaffold"
2
+
3
+ module Scss
4
+ module Generators
5
+ class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
6
+ def syntax() :scss end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1 @@
1
+ require 'sass/rails'
@@ -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,15 @@
1
+ require 'sass'
2
+
3
+ module Sass
4
+ module Rails
5
+ class CssCompressor
6
+ def compress(css)
7
+ Sass::Engine.new(css,
8
+ :syntax => :scss,
9
+ :cache => false,
10
+ :read_cache => false,
11
+ :style => :compressed).render
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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