Skip to content

Commit ae65bef

Browse files
committed
Merge pull request #27 from bolandrm/source_maps
Inline Source maps
2 parents ad01576 + 01843f1 commit ae65bef

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ This should essentially be a drop in alternative to [sass-rails](https://github.
2424

2525
__Note: This is a new project, please report any issues you come across!__
2626

27+
## Inline Source Maps
28+
29+
With SassC-Rails, it's also extremely easy to turn on inline source maps. Simply
30+
add the following configuration to your development.rb file:
31+
32+
```ruby
33+
# config/environments/development.rb
34+
config.sass.inline_source_maps = true
35+
```
36+
37+
Note, as indicated, these source maps are *inline*. They will not generate additional
38+
files or anything like that. Instead, they will be appended to the compiled
39+
application.css file.
2740

2841
## LibSass Compatibility With Ruby Sass
2942

lib/sassc/rails/template.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ def call(input)
1313
syntax: self.class.syntax,
1414
load_paths: input[:environment].paths,
1515
importer: SassC::Rails::Importer,
16-
style: sass_style,
1716
sprockets: {
1817
context: context,
1918
environment: input[:environment],
2019
dependencies: context.metadata[:dependency_paths]
2120
}
22-
}
21+
}.merge(config_options)
2322

2423
engine = ::SassC::Engine.new(input[:data], options)
2524

@@ -44,12 +43,11 @@ def evaluate(context, locals, &block)
4443
syntax: syntax,
4544
load_paths: context.environment.paths,
4645
importer: SassC::Rails::Importer,
47-
style: sass_style,
4846
sprockets: {
4947
context: context,
5048
environment: context.environment
5149
}
52-
}
50+
}.merge(config_options)
5351

5452
::SassC::Engine.new(data, options).render
5553
end
@@ -61,9 +59,23 @@ def evaluate(context, locals, &block)
6159
include Sprockets2
6260
end
6361

62+
def config_options
63+
opts = { style: sass_style }
64+
65+
66+
if Rails.application.config.sass.inline_source_maps
67+
opts.merge!({
68+
source_map_file: ".",
69+
source_map_embed: true,
70+
source_map_contents: true,
71+
})
72+
end
73+
74+
opts
75+
end
76+
6477
def sass_style
65-
style = Rails.application.config.sass.style || :expanded
66-
"sass_style_#{style}".to_sym
78+
(Rails.application.config.sass.style || :expanded).to_sym
6779
end
6880
end
6981

sassc-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
2626
# unfortunately we require sass for now, so that we can
2727
# reuse portions of the sprockets template
2828
spec.add_dependency 'sass'
29-
spec.add_dependency "sassc", "~> 1.4"
29+
spec.add_dependency "sassc", "~> 1.5"
3030

3131
spec.add_dependency "tilt"
3232

test/sassc_rails_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ def test_sassc_compression_is_used
221221
SassC::Engine.expects(:new).with("", {style: :compressed}).returns(engine)
222222
render_asset("application.scss")
223223
end
224+
225+
def test_allows_for_inclusion_of_inline_source_maps
226+
@app.config.sass.inline_source_maps = true
227+
initialize_dev!
228+
229+
asset = render_asset("application.scss")
230+
assert_match /.hello/, asset
231+
assert_match /sourceMappingURL/, asset
232+
end
233+
224234
#test 'sprockets require works correctly' do
225235
# skip
226236

0 commit comments

Comments
 (0)