Skip to content

Commit

Permalink
support for generating source maps
Browse files Browse the repository at this point in the history
closes #51
  • Loading branch information
darrenkopp committed Mar 31, 2014
1 parent 1a57401 commit 107a0cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
19 changes: 18 additions & 1 deletion SassyStudio.2012/Integration/LibSass/NSassDocumentCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,30 @@ public void Compile(FileInfo source, FileInfo output)
if (!string.IsNullOrWhiteSpace(Options.CompilationIncludePaths) && Directory.Exists(Options.CompilationIncludePaths))
includePaths = includePaths.Concat(Options.CompilationIncludePaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

var css = Compiler.CompileFile(source.FullName, sourceComments: Options.IncludeSourceComments, additionalIncludePaths: includePaths);
var result = Compiler.CompileFile(source.FullName, sourceMapPath: output.Name + ".map", sourceComments: DetermineSourceCommentsMode(Options), additionalIncludePaths: includePaths);
var css = result.CSS;
var sourceMap = result.SourceMap;
InteropHelper.CheckOut(output.FullName);

if (Options.IncludeGeneratedCodeWarning)
css = new StringBuilder("/* AUTOGENERATED CSS: To make changes edit ").Append(source.Name).Append(" */").AppendLine().Append(css).ToString();

File.WriteAllText(output.FullName, css, UTF8_ENCODING);

if (Options.GenerateSourceMaps && !string.IsNullOrEmpty(sourceMap))
{
InteropHelper.CheckOut(output.FullName + ".map");
File.WriteAllText(output.FullName + ".map", sourceMap, UTF8_ENCODING);
}
}

private static SourceCommentsMode DetermineSourceCommentsMode(ScssOptions options)
{
return options.GenerateSourceMaps
? SourceCommentsMode.SourceMaps
: options.IncludeSourceComments
? SourceCommentsMode.Default
: SourceCommentsMode.None;
}

private DirectoryInfo DetermineSaveDirectory(FileInfo source)
Expand Down
7 changes: 5 additions & 2 deletions SassyStudio.2012/Integration/SassGem/SassDocumentCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ public FileInfo GetOutput(FileInfo source)

private string GetSassArguments(FileInfo input, FileInfo output)
{
return new StringBuilder()
.Append("--no-cache ")
var builder = new StringBuilder().Append("--no-cache ");
if (Options.GenerateSourceMaps)
builder.Append("--sourcemap ");

return builder
.Append(@"""").Append(input.FullName).Append(@"""").Append(" ")
.Append(@"""").Append(output.FullName).Append(@"""")
.ToString();
Expand Down
6 changes: 6 additions & 0 deletions SassyStudio.2012/Options/ScssOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public override void LoadSettingsFromStorage()
IncludeCssInProject = true;
IncludeCssInProjectOutput = true;
IncludeSourceComments = false;
GenerateSourceMaps = false;
ReplaceCssWithException = false;
IncludeGeneratedCodeWarning = false;

Expand Down Expand Up @@ -83,5 +84,10 @@ public override void LoadSettingsFromStorage()
[Description("When enabled, a warning will be emitted to CSS files that the file was generated by compiler.")]
[Category("Diagnostics")]
public bool IncludeGeneratedCodeWarning { get; set; }

[LocDisplayName("Generate Source Map")]
[Description("When enabled, a source map file will be generated.")]
[Category("SCSS")]
public bool GenerateSourceMaps { get; set; }
}
}

0 comments on commit 107a0cc

Please sign in to comment.