sprockets-sass 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,17 @@ require 'sass'
3
3
  module Sprockets
4
4
  module Sass
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
+
6
17
  # Using Sprockets::Helpers#asset_path, return the full path
7
18
  # for the given +source+ as a Sass String. This supports keyword
8
19
  # arguments that mirror the +options+.
@@ -73,16 +84,40 @@ module Sprockets
73
84
  end
74
85
  ::Sass::Script::String.new "url(#{image_path(source, options)})"
75
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
76
100
 
77
- # Using Sprockets::Context#asset_data_uri return a Base64-encoded `data:`
78
- # URI with the contents of the asset at the specified path.
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+.
79
104
  #
80
105
  # === Examples
81
- #
82
- # background: asset-data-uri("image.jpg"); // background: url(data:image/jpeg;base64,...);
83
106
  #
84
- def asset_data_uri(source)
85
- ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})"
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)})"
86
121
  end
87
122
 
88
123
  protected
@@ -109,7 +144,7 @@ module Sass::Script::Functions
109
144
 
110
145
  # Hack to ensure previous API declarations (by Compass or whatever)
111
146
  # don't take precedence.
112
- [:asset_path, :asset_url, :image_path, :image_url, :asset_data_uri].each do |method|
147
+ [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method|
113
148
  defined?(@signatures) && @signatures.delete(method)
114
149
  end
115
150
 
@@ -121,5 +156,8 @@ module Sass::Script::Functions
121
156
  declare :image_url, [:source], :var_kwargs => true
122
157
  declare :image_url, [:source, :only_path]
123
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]
124
162
  declare :asset_data_uri, [:source]
125
163
  end
@@ -15,7 +15,7 @@ module Sprockets
15
15
 
16
16
  # Add the Sass functions if they haven't already been added.
17
17
  def initialize_engine
18
- super
18
+ super unless self.class.superclass.engine_initialized?
19
19
 
20
20
  if Sass.add_sass_functions
21
21
  require 'sprockets/sass/functions'
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Sass
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
@@ -249,6 +249,19 @@ describe Sprockets::Sass do
249
249
  @env['image_path_options.css'].to_s.should =~ %r(body \{\n background: url\("/themes/image-[0-9a-f]+.jpg"\); \}\n)
250
250
  @env['image_url_options.css'].to_s.should =~ %r(body \{\n background: url\("/themes/image-[0-9a-f]+.jpg"\); \}\n)
251
251
  end
252
+
253
+ it 'adds the #font_path helper' do
254
+ @assets.file 'font_path.css.scss', %(@font-face { src: url(font-path("font.ttf")); })
255
+ @assets.file 'font_url.css.scss', %(@font-face { src: font-url("font.ttf"); })
256
+ @assets.file 'font_path_options.css.scss', %(@font-face { src: url(font-path("font.ttf", $digest: true, $prefix: "/themes")); })
257
+ @assets.file 'font_url_options.css.scss', %(@font-face { src: font-url("font.ttf", $digest: true, $prefix: "/themes"); })
258
+ @assets.file 'font.ttf'
259
+
260
+ @env['font_path.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
261
+ @env['font_url.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
262
+ @env['font_path_options.css'].to_s.should =~ %r(@font-face \{\n src: url\("/themes/font-[0-9a-f]+.ttf"\); \}\n)
263
+ @env['font_url_options.css'].to_s.should =~ %r(@font-face \{\n src: url\("/themes/font-[0-9a-f]+.ttf"\); \}\n)
264
+ end
252
265
 
253
266
  it 'adds the #asset_data_uri helper' do
254
267
  @assets.file 'asset_data_uri.css.scss', %(body { background: asset-data-uri("image.jpg"); })
@@ -267,6 +280,15 @@ describe Sprockets::Sass do
267
280
  @env['image_url.css'].to_s.should == %(body {\n background: url("/assets/image.jpg"); }\n)
268
281
  @env['cache_buster.css'].to_s.should == %(body {\n background: url("/assets/image.jpg"); }\n)
269
282
  end
283
+
284
+ it "mirrors Compass's #font_url helper" do
285
+ @assets.file 'font_path.css.scss', %(@font-face { src: url(font-url("font.ttf", true)); })
286
+ @assets.file 'font_url.css.scss', %(@font-face { src: font-url("font.ttf", false); })
287
+ @assets.file 'font.ttf'
288
+
289
+ @env['font_path.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
290
+ @env['font_url.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
291
+ end
270
292
 
271
293
  it "mirrors Sass::Rails's #asset_path helpers" do
272
294
  @assets.file 'asset_path.css.scss', %(body { background: url(asset-path("image.jpg", image)); })
@@ -277,13 +299,26 @@ describe Sprockets::Sass do
277
299
  @env['asset_url.css'].to_s.should == %(body {\n background: url("/images/icon.jpg"); }\n)
278
300
  end
279
301
 
280
- it "compresses css" do
281
- css = <<-CSS
282
- div {
283
- color: red;
284
- }
285
- CSS
286
-
302
+ it 'compresses css' do
303
+ css = "div {\n color: red;\n}\n"
287
304
  Sprockets::Sass::Compressor.new.compress(css).should == "div{color:red}\n"
288
305
  end
306
+
307
+ describe Sprockets::Sass::SassTemplate do
308
+ describe 'initialize_engine' do
309
+ it 'initializes super if super is uninitinalized' do
310
+ Tilt::SassTemplate.stub(:engine_initialized?).and_return false
311
+ template = Sprockets::Sass::SassTemplate.new {}
312
+ template.should_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
313
+ template.initialize_engine
314
+ end
315
+
316
+ it "does not initializes super if super is initinalized to silence warnings" do
317
+ Tilt::SassTemplate.stub(:engine_initialized?).and_return true
318
+ template = Sprockets::Sass::SassTemplate.new {}
319
+ template.should_not_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
320
+ template.initialize_engine
321
+ end
322
+ end
323
+ end
289
324
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'appraisal', '~> 0.4'
24
24
  s.add_development_dependency 'rspec', '~> 2.6'
25
25
  s.add_development_dependency 'test-construct', '~> 1.2'
26
- s.add_development_dependency 'sprockets-helpers', '~> 0.3'
26
+ s.add_development_dependency 'sprockets-helpers', '~> 0.6'
27
27
  s.add_development_dependency 'sass', '~> 3.1'
28
28
  s.add_development_dependency 'compass', '~> 0.11'
29
29
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &-1072935398 !ruby/object:Gem::Requirement
16
+ requirement: &70201732598340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *-1072935398
24
+ version_requirements: *70201732598340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tilt
27
- requirement: &-1072935738 !ruby/object:Gem::Requirement
27
+ requirement: &70201732597840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *-1072935738
35
+ version_requirements: *70201732597840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: appraisal
38
- requirement: &-1072936198 !ruby/object:Gem::Requirement
38
+ requirement: &70201732597360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.4'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *-1072936198
46
+ version_requirements: *70201732597360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &-1072936978 !ruby/object:Gem::Requirement
49
+ requirement: &70201732596900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.6'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *-1072936978
57
+ version_requirements: *70201732596900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: test-construct
60
- requirement: &-1072937558 !ruby/object:Gem::Requirement
60
+ requirement: &70201732596440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,21 +65,21 @@ dependencies:
65
65
  version: '1.2'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *-1072937558
68
+ version_requirements: *70201732596440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sprockets-helpers
71
- requirement: &-1072938048 !ruby/object:Gem::Requirement
71
+ requirement: &70201732595980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: '0.3'
76
+ version: '0.6'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *-1072938048
79
+ version_requirements: *70201732595980
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sass
82
- requirement: &-1072938558 !ruby/object:Gem::Requirement
82
+ requirement: &70201731818520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.1'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *-1072938558
90
+ version_requirements: *70201731818520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: compass
93
- requirement: &-1072939588 !ruby/object:Gem::Requirement
93
+ requirement: &70201731818060 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0.11'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *-1072939588
101
+ version_requirements: *70201731818060
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rake
104
- requirement: &-1072796628 !ruby/object:Gem::Requirement
104
+ requirement: &70201731817680 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *-1072796628
112
+ version_requirements: *70201731817680
113
113
  description: When using Sprockets 2.0 with Sass you will eventually run into a pretty
114
114
  big issue. `//= require` directives will not allow Sass mixins, variables, etc.
115
115
  to be shared between files. So you'll try to use `@import`, and that'll also blow
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: 393589807
165
+ hash: 1670006435570534219
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: 393589807
174
+ hash: 1670006435570534219
175
175
  requirements: []
176
176
  rubyforge_project: sprockets-sass
177
177
  rubygems_version: 1.8.11