Skip to content

Commit

Permalink
Merge pull request #48 from TylerHorth/source_map_getter
Browse files Browse the repository at this point in the history
Add source_map getter
  • Loading branch information
bolandrm committed Oct 4, 2016
2 parents 90ce13e + 76ee7d2 commit e5e27f2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/sassc/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def render
css = Native.context_get_output_string(context)

@dependencies = Native.context_get_included_files(context)
@source_map = Native.context_get_source_map_string(context)

Native.delete_data_context(data_context)

Expand All @@ -62,6 +63,11 @@ def dependencies
Dependency.from_filenames(@dependencies)
end

def source_map
raise NotRenderedError unless @source_map
@source_map
end

def filename
@options[:filename]
end
Expand Down
45 changes: 45 additions & 0 deletions test/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ def test_not_rendered_error
assert_raises(NotRenderedError) { engine.dependencies }
end

def test_source_map
temp_dir('admin')

temp_file('admin/text-color.scss', <<SCSS)
p {
color: red;
}
SCSS
temp_file('style.scss', <<SCSS)
@import 'admin/text-color';
p {
padding: 20px;
}
SCSS
engine = Engine.new(File.read('style.scss'), {
source_map_file: "style.scss.map",
source_map_contents: true
})
engine.render

assert_equal <<MAP.strip, engine.source_map
{
\t"version": 3,
\t"file": "stdin.css",
\t"sources": [
\t\t"stdin",
\t\t"admin/text-color.scss"
\t],
\t"sourcesContent": [
\t\t"@import 'admin/text-color';\\n\\np {\\n padding: 20px;\\n}\\n",
\t\t"p {\\n color: red;\\n}\\n"
\t],
\t"mappings": "ACAA,AAAA,CAAC,CAAC;EACA,KAAK,EAAE,GAAI,GACZ;;ADAD,AAAA,CAAC,CAAC;EACA,OAAO,EAAE,IAAK,GACf",
\t"names": []
}
MAP
end

def test_no_source_map
engine = Engine.new("$size: 30px;")
engine.render
assert_raises(NotRenderedError) { engine.source_map }
end

def test_load_paths
temp_dir("included_1")
temp_dir("included_2")
Expand Down

0 comments on commit e5e27f2

Please sign in to comment.