Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source_map getter #48

Merged
merged 2 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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