From 107a0cc2cd119b3863f725eda204c91f33f6e8f2 Mon Sep 17 00:00:00 2001 From: Darren Kopp Date: Sun, 30 Mar 2014 18:47:13 -0600 Subject: [PATCH] support for generating source maps closes #51 --- .../LibSass/NSassDocumentCompiler.cs | 19 ++++++++++++++++++- .../SassGem/SassDocumentCompiler.cs | 7 +++++-- SassyStudio.2012/Options/ScssOptions.cs | 6 ++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/SassyStudio.2012/Integration/LibSass/NSassDocumentCompiler.cs b/SassyStudio.2012/Integration/LibSass/NSassDocumentCompiler.cs index ce67099..6535c15 100644 --- a/SassyStudio.2012/Integration/LibSass/NSassDocumentCompiler.cs +++ b/SassyStudio.2012/Integration/LibSass/NSassDocumentCompiler.cs @@ -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) diff --git a/SassyStudio.2012/Integration/SassGem/SassDocumentCompiler.cs b/SassyStudio.2012/Integration/SassGem/SassDocumentCompiler.cs index af60c99..823ca7e 100644 --- a/SassyStudio.2012/Integration/SassGem/SassDocumentCompiler.cs +++ b/SassyStudio.2012/Integration/SassGem/SassDocumentCompiler.cs @@ -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(); diff --git a/SassyStudio.2012/Options/ScssOptions.cs b/SassyStudio.2012/Options/ScssOptions.cs index 8fd1633..7431dab 100644 --- a/SassyStudio.2012/Options/ScssOptions.cs +++ b/SassyStudio.2012/Options/ScssOptions.cs @@ -18,6 +18,7 @@ public override void LoadSettingsFromStorage() IncludeCssInProject = true; IncludeCssInProjectOutput = true; IncludeSourceComments = false; + GenerateSourceMaps = false; ReplaceCssWithException = false; IncludeGeneratedCodeWarning = false; @@ -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; } } }