sprockets-sass 1.3.1 → 2.0.0.beta2

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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.reek +12 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +77 -0
  5. data/.travis.yml +14 -0
  6. data/Appraisals +32 -15
  7. data/Gemfile +5 -0
  8. data/README.md +41 -4
  9. data/Rakefile +15 -3
  10. data/gemfiles/compass_0.11.gemfile +1 -1
  11. data/gemfiles/sass_3.1.gemfile +1 -1
  12. data/gemfiles/sass_3.3.gemfile +8 -0
  13. data/gemfiles/sass_3.4.gemfile +8 -0
  14. data/gemfiles/sprockets_2.10.gemfile +1 -1
  15. data/gemfiles/sprockets_2.11.gemfile +1 -1
  16. data/gemfiles/sprockets_2.2.gemfile +1 -1
  17. data/gemfiles/sprockets_2.3.gemfile +1 -1
  18. data/gemfiles/sprockets_2.4.gemfile +1 -1
  19. data/gemfiles/sprockets_2.5.gemfile +1 -1
  20. data/gemfiles/sprockets_2.6.gemfile +1 -1
  21. data/gemfiles/sprockets_2.7.gemfile +1 -1
  22. data/gemfiles/sprockets_2.8.gemfile +1 -1
  23. data/gemfiles/sprockets_2.9.gemfile +1 -1
  24. data/gemfiles/sprockets_3.7.gemfile +9 -0
  25. data/gemfiles/sprockets_4.0.gemfile +10 -0
  26. data/gemfiles/sprockets_4.0_beta2.gemfile +9 -0
  27. data/lib/sprockets/sass/functions.rb +24 -159
  28. data/lib/sprockets/sass/registration.rb +126 -0
  29. data/lib/sprockets/sass/utils.rb +115 -0
  30. data/lib/sprockets/sass/v2/cache_store.rb +26 -0
  31. data/lib/sprockets/sass/v2/compressor.rb +31 -0
  32. data/lib/sprockets/sass/v2/functions.rb +142 -0
  33. data/lib/sprockets/sass/v2/importer.rb +209 -0
  34. data/lib/sprockets/sass/v2/sass_template.rb +221 -0
  35. data/lib/sprockets/sass/v2/scss_template.rb +14 -0
  36. data/lib/sprockets/sass/v3/cache_store.rb +28 -0
  37. data/lib/sprockets/sass/v3/compressor.rb +97 -0
  38. data/lib/sprockets/sass/v3/functions.rb +12 -0
  39. data/lib/sprockets/sass/v3/importer.rb +224 -0
  40. data/lib/sprockets/sass/v3/sass_template.rb +37 -0
  41. data/lib/sprockets/sass/v3/scss_template.rb +15 -0
  42. data/lib/sprockets/sass/v4/cache_store.rb +11 -0
  43. data/lib/sprockets/sass/v4/compressor.rb +11 -0
  44. data/lib/sprockets/sass/v4/functions.rb +12 -0
  45. data/lib/sprockets/sass/v4/importer.rb +109 -0
  46. data/lib/sprockets/sass/v4/sass_template.rb +27 -0
  47. data/lib/sprockets/sass/v4/scss_template.rb +16 -0
  48. data/lib/sprockets/sass/version.rb +2 -1
  49. data/lib/sprockets/sass.rb +37 -12
  50. data/lib/sprockets-sass.rb +1 -0
  51. data/spec/custom_importer_spec.rb +4 -6
  52. data/spec/importer_spec.rb +44 -0
  53. data/spec/spec_helper.rb +39 -3
  54. data/spec/sprockets-sass_spec.rb +102 -62
  55. data/spec/support/be_fresh_matcher.rb +12 -8
  56. data/spec/support/dummy_importer.rb +1 -1
  57. data/spec/support/fail_postprocessor.rb +23 -0
  58. data/spec/support/fake_engine.rb +50 -0
  59. data/spec/support/sass_template.rb +11 -0
  60. data/spec/support/test_registration.rb +11 -0
  61. data/sprockets-sass.gemspec +28 -9
  62. metadata +100 -97
  63. data/gemfiles/compass_0.12.gemfile +0 -7
  64. data/gemfiles/sass_3.2.gemfile +0 -7
  65. data/gemfiles/sprockets_2.0.gemfile +0 -7
  66. data/gemfiles/sprockets_2.1.gemfile +0 -9
  67. data/lib/sprockets/sass/cache_store.rb +0 -27
  68. data/lib/sprockets/sass/compressor.rb +0 -22
  69. data/lib/sprockets/sass/importer.rb +0 -142
  70. data/lib/sprockets/sass/sass_template.rb +0 -115
  71. data/lib/sprockets/sass/scss_template.rb +0 -12
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e93b8e4aef5fc9d0fcc2e1a59a42b2942f73de0b
4
+ data.tar.gz: 52d6ac715c3bf79e861b3a66977d3d6883e92495
5
+ SHA512:
6
+ metadata.gz: eebe585d42892338ca846c7d0ad6ed922459c6944a06447bb100034bdf07fd4cdd74c87a4c4bdee7b834dcdfe9f421f68d4b318d26baf50d48ebb6ef408ce71a
7
+ data.tar.gz: 21be3f03e533819ac78355160727abc4cb2c00f0c709791d6a0ca0b538cac7c0e268546fb1c166bdeea9d830cb7590ddccd45c9d0cae332c19f0ddfc62874a9b
data/.reek ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ Attribute:
3
+ enabled: false
4
+ TooManyInstanceVariables:
5
+ enabled: false
6
+ TooManyMethods:
7
+ enabled: false
8
+ UtilityFunction:
9
+ enabled: false
10
+ exclude_paths:
11
+ - examples
12
+ - spec
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rubocop.yml ADDED
@@ -0,0 +1,77 @@
1
+ AllCops:
2
+ Exclude:
3
+ - sprockets-sass.gemspec
4
+ - lib/sprockets/sass.rb
5
+ - bin/**/*
6
+ - Guardfile
7
+ - vendor/**/**
8
+ - spec/**/*
9
+ - Gemfile
10
+ - Rakefile
11
+
12
+ TargetRubyVersion: 2.3
13
+
14
+ ClassLength:
15
+ Max: 500
16
+
17
+ Documentation:
18
+ Enabled: true
19
+
20
+ Encoding:
21
+ Enabled: false
22
+
23
+ LineLength:
24
+ Max: 200
25
+
26
+ AccessModifierIndentation:
27
+ EnforcedStyle: outdent
28
+
29
+ IfUnlessModifier:
30
+ Enabled: false
31
+
32
+ CaseIndentation:
33
+ IndentWhenRelativeTo: case
34
+ IndentOneStep: true
35
+
36
+ MethodLength:
37
+ CountComments: false
38
+ Max: 20
39
+
40
+ SignalException:
41
+ Enabled: false
42
+
43
+ ColonMethodCall:
44
+ Enabled: false
45
+
46
+ AsciiComments:
47
+ Enabled: false
48
+
49
+ RegexpLiteral:
50
+ Enabled: false
51
+
52
+ AssignmentInCondition:
53
+ Enabled: false
54
+
55
+ ParameterLists:
56
+ CountKeywordArgs: false
57
+
58
+ SingleLineBlockParams:
59
+ Methods:
60
+ - reduce:
61
+ - memo
62
+ - item
63
+
64
+ Metrics/AbcSize:
65
+ Enabled: false
66
+
67
+ Style/CollectionMethods:
68
+ Enabled: true
69
+
70
+ Style/SymbolArray:
71
+ Enabled: true
72
+
73
+ Style/ExtraSpacing:
74
+ Enabled: true
75
+
76
+ Style/FileName:
77
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ before_install:
5
+ - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
6
+ - gem install bundler
7
+ rvm:
8
+ - 2.2.2
9
+ - 2.2.3
10
+ - 2.3.1
11
+ env:
12
+ - RAILS_ENV=test RACK_ENV=test
13
+ notifications:
14
+ email: false
data/Appraisals CHANGED
@@ -1,18 +1,3 @@
1
- appraise 'sass_3.1' do
2
- gem 'sass', '~> 3.1.0'
3
- gem 'compass', '~> 0.12.0'
4
- end
5
-
6
- appraise 'compass_0.11' do
7
- gem 'sass', '~> 3.2.0'
8
- gem 'compass', '~> 0.11.0'
9
- end
10
-
11
- appraise 'sprockets_2.1' do
12
- gem 'sprockets', '~> 2.1.0'
13
- gem 'sass', '~> 3.2.0'
14
- gem 'compass', '~> 0.12.0'
15
- end
16
1
 
17
2
  appraise 'sprockets_2.2' do
18
3
  gem 'sprockets', '~> 2.2.0'
@@ -73,3 +58,35 @@ appraise 'sprockets_2.11' do
73
58
  gem 'sass', '~> 3.2.0'
74
59
  gem 'compass', '~> 0.12.0'
75
60
  end
61
+
62
+ appraise 'sprockets_3.7' do
63
+ gem 'sprockets', '~> 3.7.0'
64
+ gem 'sass', '~> 3.4.0'
65
+ gem 'compass', '~> 1.0.0'
66
+ end
67
+
68
+ appraise 'sass_3.1' do
69
+ gem 'sass', '~> 3.1.0'
70
+ gem 'compass', '~> 0.12.0'
71
+ end
72
+
73
+ appraise 'sass_3.3' do
74
+ gem 'sass', '~> 3.3.0'
75
+ gem 'compass', '~> 1.0.0'
76
+ end
77
+
78
+ appraise 'sass_3.4' do
79
+ gem 'sass', '~> 3.4.0'
80
+ gem 'compass', '~> 1.0.0'
81
+ end
82
+
83
+ appraise 'compass_0.11' do
84
+ gem 'sass', '~> 3.2.0'
85
+ gem 'compass', '~> 0.11.0'
86
+ end
87
+
88
+ # appraise 'sprockets_4.0_beta2' do
89
+ # gem 'sprockets', '4.0.0.beta2'
90
+ # gem 'sass', '~> 3.4.0'
91
+ # gem 'compass', '~> 1.0.0'
92
+ # end
data/Gemfile CHANGED
@@ -1,2 +1,7 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
4
+
5
+ if RUBY_VERSION < "2.2.0"
6
+ gem 'rack', '>= 1.0', '< 2.0'
7
+ end
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
1
  sprockets-sass
2
2
  ==============
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/sprockets-sass.svg)](https://badge.fury.io/rb/sprockets-sass) [![Build Status](https://travis-ci.org/petebrowne/sprockets-sass.svg?branch=master)](https://travis-ci.org/petebrowne/sprockets-sass)
5
+
4
6
  **Better Sass integration with [Sprockets 2.x](http://github.com/sstephenson/sprockets)**
5
7
 
6
8
  When using Sprockets 2.x with Sass you will eventually run into a pretty big issue. `//= require` directives will not allow Sass mixins, variables, etc. to be shared between files. So you'll try to use `@import`, and that'll also blow up in your face. `sprockets-sass` fixes all of this by creating a Sass::Importer that is Sprockets aware.
7
9
 
8
- _Note: This works in Rails 3.1, thanks to the [sass-rails gem](http://github.com/rails/sass-rails). But if you want to use Sprockets and Sass anywhere else, like Sinatra, use `sprockets-sass`._
10
+ **Note: This works in Rails 3.1, thanks to the [sass-rails gem](http://github.com/rails/sass-rails). But if you want to use Sprockets and Sass anywhere else, like Sinatra, use `sprockets-sass`**
9
11
 
10
12
  ### Features
11
13
 
12
- * Imports Sass _partials_ (filenames prepended with "_").
14
+ * Imports Sass ```_partials_``` (filenames prepended with ```_```).
13
15
  * Import paths work exactly like `require` directives.
14
16
  * Imports either Sass syntax, or just regular CSS files.
15
17
  * Imported files are preprocessed by Sprockets, so `.css.scss.erb` files can be imported.
@@ -48,6 +50,24 @@ map "/" do
48
50
  end
49
51
  ```
50
52
 
53
+ Sprockets Sass provides also a compressor for ```.css``` files
54
+
55
+ You can use it with Sprockets 2.x by doing this:
56
+
57
+ ```ruby
58
+ environment = Sprockets::Environment.new
59
+ environment.css_compressor = Sprockets::Sass::V2::Compressor
60
+ ```
61
+
62
+ Or with Sprockets 3.x by doing this:
63
+
64
+ ```ruby
65
+ environment = Sprockets::Environment.new
66
+ environment.css_compressor = :sprockets_sass
67
+ ```
68
+
69
+ Or with Rails by setting ```css_compressor``` in the ```config/application.rb``` file to one of the values listed above depending on your version of Sprockets
70
+
51
71
  Now `@import` works essentially just like a `require` directive, but with one essential bonus:
52
72
  Sass mixins, variables, etc. work as expected.
53
73
 
@@ -158,13 +178,13 @@ require "sass"
158
178
  map "/assets" do
159
179
  environment = Sprockets::Environment.new
160
180
  environment.append_path "assets/stylesheets"
161
-
181
+
162
182
  Sprockets::Helpers.configure do |config|
163
183
  config.environment = environment
164
184
  config.prefix = "/assets"
165
185
  config.digest = false
166
186
  end
167
-
187
+
168
188
  run environment
169
189
  end
170
190
 
@@ -192,6 +212,23 @@ background: asset-data-uri("image.jpg"); // background: url(data:image/jpeg;base
192
212
  ```
193
213
 
194
214
 
215
+ Development
216
+ -----------
217
+
218
+ Install dependencies using bundler:
219
+
220
+ ``` bash
221
+ bundle install
222
+ ```
223
+
224
+ sprocket-sass is tested against numerous versions of Sass, Compoass, and Sprockets using [appraisal](https://github.com/thoughtbot/appraisal).
225
+ This will install all the gems and run the tests against all versions
226
+ Run tests:
227
+
228
+ ``` bash
229
+ bundle exec rake
230
+ ```
231
+
195
232
  Copyright
196
233
  ---------
197
234
 
data/Rakefile CHANGED
@@ -1,6 +1,18 @@
1
- require 'appraisal'
1
+ require 'bundler/setup'
2
2
  require 'bundler/gem_tasks'
3
+ require 'appraisal'
3
4
  require 'rspec/core/rake_task'
4
5
 
5
- RSpec::Core::RakeTask.new
6
- task :default => :spec
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.rspec_opts = ['--backtrace '] if ENV['DEBUG']
9
+ spec.verbose = true
10
+ end
11
+
12
+ desc 'Default: run the unit tests.'
13
+ task default: [:all]
14
+
15
+ desc 'Test the plugin under all supported versions.'
16
+ task :all do |_t|
17
+ exec('bundle exec appraisal install && bundle exec rake appraisal spec')
18
+ end
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "sass", "~> 3.2.0"
6
6
  gem "compass", "~> 0.11.0"
7
7
 
8
- gemspec :path=>"../"
8
+ gemspec :path => "../"
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "sass", "~> 3.1.0"
6
6
  gem "compass", "~> 0.12.0"
7
7
 
8
- gemspec :path=>"../"
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sass", "~> 3.3.0"
6
+ gem "compass", "~> 1.0.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sass", "~> 3.4.0"
6
+ gem "compass", "~> 1.0.0"
7
+
8
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.9.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.9.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.2.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.3.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.4.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.5.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.6.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.7.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.8.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -6,4 +6,4 @@ gem "sprockets", "~> 2.9.0"
6
6
  gem "sass", "~> 3.2.0"
7
7
  gem "compass", "~> 0.12.0"
8
8
 
9
- gemspec :path=>"../"
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sprockets", "~> 3.7.0"
6
+ gem "sass", "~> 3.4.0"
7
+ gem "compass", "~> 1.0.0"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rack", ">= 1.0", "< 2.0"
6
+ gem "sprockets", "4.0.0.beta2"
7
+ gem "sass", ">= 3.4.0"
8
+ gem "compass", ">= 1.0.0"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sprockets", "4.0.0.beta2"
6
+ gem "sass", "~> 3.4.0"
7
+ gem "compass", "~> 1.0.0"
8
+
9
+ gemspec :path => "../"
@@ -1,163 +1,28 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- module Sass
1
+ # frozen_string_literal: true
2
+ module Sass
3
+ module Script
4
+ # Original Sass script functions are overidden with this methods
5
5
  module Functions
6
- # Using Sprockets::Context#asset_data_uri return a Base64-encoded `data:`
7
- # URI with the contents of the asset at the specified path.
8
- #
9
- # === Examples
10
- #
11
- # background: asset-data-uri("image.jpg"); // background: url(data:image/jpeg;base64,...);
12
- #
13
- def asset_data_uri(source)
14
- ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})"
15
- end
16
-
17
- # Using Sprockets::Helpers#asset_path, return the full path
18
- # for the given +source+ as a Sass String. This supports keyword
19
- # arguments that mirror the +options+.
20
- #
21
- # === Examples
22
- #
23
- # background: url(asset-path("image.jpg")); // background: url("/assets/image.jpg");
24
- # background: url(asset-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
25
- #
26
- def asset_path(source, options = {})
27
- # Work with the Sass::Rails #asset_path API
28
- if options.respond_to? :value
29
- kind = options.value
30
- options = {}
31
- end
32
-
33
- if kind && sprockets_context.respond_to?("#{kind}_path")
34
- ::Sass::Script::String.new sprockets_context.send("#{kind}_path", source.value), :string
35
- else
36
- ::Sass::Script::String.new sprockets_context.asset_path(source.value, map_options(options)).to_s, :string
37
- end
38
- end
39
-
40
- # Using Sprockets::Helpers#asset_path, return the url CSS
41
- # for the given +source+ as a Sass String. This supports keyword
42
- # arguments that mirror the +options+.
43
- #
44
- # === Examples
45
- #
46
- # background: asset-url("image.jpg"); // background: url("/assets/image.jpg");
47
- # background: asset-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
48
- #
49
- def asset_url(source, options = {})
50
- ::Sass::Script::String.new "url(#{asset_path(source, options)})"
51
- end
52
-
53
- # Using Sprockets::Helpers#image_path, return the full path
54
- # for the given +source+ as a Sass String. This supports keyword
55
- # arguments that mirror the +options+.
56
- #
57
- # === Examples
58
- #
59
- # background: url(image-path("image.jpg")); // background: url("/assets/image.jpg");
60
- # background: url(image-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
61
- #
62
- def image_path(source, options = {})
63
- ::Sass::Script::String.new sprockets_context.image_path(source.value, map_options(options)).to_s, :string
64
- end
65
-
66
- # Using Sprockets::Helpers#image_path, return the url CSS
67
- # for the given +source+ as a Sass String. This supports keyword
68
- # arguments that mirror the +options+.
69
- #
70
- # === Examples
71
- #
72
- # background: image-url("image.jpg"); // background: url("/assets/image.jpg");
73
- # background: image-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
74
- #
75
- def image_url(source, options = {}, cache_buster = nil)
76
- # Work with the Compass #image_url API
77
- if options.respond_to? :value
78
- case options.value
79
- when true
80
- return image_path source
81
- else
82
- options = {}
83
- end
84
- end
85
- ::Sass::Script::String.new "url(#{image_path(source, options)})"
86
- end
87
-
88
- # Using Sprockets::Helpers#font_path, return the full path
89
- # for the given +source+ as a Sass String. This supports keyword
90
- # arguments that mirror the +options+.
91
- #
92
- # === Examples
93
- #
94
- # src: url(font-path("font.ttf")); // src: url("/assets/font.ttf");
95
- # src: url(font-path("font.ttf", $digest: true)); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
96
- #
97
- def font_path(source, options = {})
98
- ::Sass::Script::String.new sprockets_context.font_path(source.value, map_options(options)).to_s, :string
99
- end
100
-
101
- # Using Sprockets::Helpers#font_path, return the url CSS
102
- # for the given +source+ as a Sass String. This supports keyword
103
- # arguments that mirror the +options+.
104
- #
105
- # === Examples
106
- #
107
- # src: font-url("font.ttf"); // src: url("/assets/font.ttf");
108
- # src: font-url("image.jpg", $digest: true); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
109
- #
110
- def font_url(source, options = {})
111
- # Work with the Compass #font_url API
112
- if options.respond_to? :value
113
- case options.value
114
- when true
115
- return font_path source
116
- else
117
- options = {}
118
- end
119
- end
120
- ::Sass::Script::String.new "url(#{font_path(source, options)})"
121
- end
122
-
123
- protected
124
-
125
- # Returns a reference to the Sprocket's context through
126
- # the importer.
127
- def sprockets_context # :nodoc:
128
- options[:custom][:sprockets_context]
129
- end
130
-
131
- # Returns an options hash where the keys are symbolized
132
- # and the values are unwrapped Sass literals.
133
- def map_options(options = {}) # :nodoc:
134
- ::Sass::Util.map_hash(options) do |key, value|
135
- [key.to_sym, value.respond_to?(:value) ? value.value : value]
136
- end
137
- end
6
+ include Sprockets::Sass::Utils.get_class_by_version('Functions')
7
+
8
+ # Hack to ensure previous API declarations (by Compass or whatever)
9
+ # don't take precedence.
10
+ %i(asset_path asset_url image_path image_url font_path font_url asset_data_uri).each do |method|
11
+ defined?(@signatures) && @signatures.delete(method)
12
+ end
13
+
14
+ declare :asset_path, [:source], var_kwargs: true
15
+ declare :asset_path, %i(source kind)
16
+ declare :asset_url, [:source], var_kwargs: true
17
+ declare :asset_url, %i(source kind)
18
+ declare :image_path, [:source], var_kwargs: true
19
+ declare :image_url, [:source], var_kwargs: true
20
+ declare :image_url, %i(source only_path)
21
+ declare :image_url, %i(source only_path cache_buster)
22
+ declare :font_path, [:source], var_kwargs: true
23
+ declare :font_url, [:source], var_kwargs: true
24
+ declare :font_url, %i(source only_path)
25
+ declare :asset_data_uri, [:source]
138
26
  end
139
27
  end
140
28
  end
141
-
142
- module Sass::Script::Functions
143
- include Sprockets::Sass::Functions
144
-
145
- # Hack to ensure previous API declarations (by Compass or whatever)
146
- # don't take precedence.
147
- [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method|
148
- defined?(@signatures) && @signatures.delete(method)
149
- end
150
-
151
- declare :asset_path, [:source], :var_kwargs => true
152
- declare :asset_path, [:source, :kind]
153
- declare :asset_url, [:source], :var_kwargs => true
154
- declare :asset_url, [:source, :kind]
155
- declare :image_path, [:source], :var_kwargs => true
156
- declare :image_url, [:source], :var_kwargs => true
157
- declare :image_url, [:source, :only_path]
158
- declare :image_url, [:source, :only_path, :cache_buster]
159
- declare :font_path, [:source], :var_kwargs => true
160
- declare :font_url, [:source], :var_kwargs => true
161
- declare :font_url, [:source, :only_path]
162
- declare :asset_data_uri, [:source]
163
- end