-
Notifications
You must be signed in to change notification settings - Fork 11
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
Multiple file managers #13
Comments
Hello, John! In fact, and earlier the static classes was used for these purposes. You just didn't see it due to the tricky wrapper. This approach has been criticized, and therefore I had to convert the compiler to a static class and refuse locks. You can use a wrapper with locks: using System;
using LibSassHost;
namespace LibSassHost.Wrapper
{
/// <summary>
/// Sass-compiler wrapper
/// </summary>
public sealed class SassCompilerWrapper
{
/// <summary>
/// Instance of file manager
/// </summary>
private readonly IFileManager _fileManager;
/// <summary>
/// Synchronizer of compilation
/// </summary>
private static readonly object _compilationSynchronizer = new object();
/// <summary>
/// Constructs an instance of Sass-compiler wrapper
/// </summary>
public SassCompilerWrapper()
: this(null)
{ }
/// <summary>
/// Constructs an instance of Sass-compiler wrapper
/// </summary>
/// <param name="fileManager">File manager</param>
public SassCompilerWrapper(IFileManager fileManager)
{
_fileManager = fileManager;
}
/// <summary>
/// "Compiles" a Sass-code to CSS-code
/// </summary>
/// <param name="content">Text content written on Sass</param>
/// <param name="options">Compilation options</param>
/// <returns>Compilation result</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException" />
/// <exception cref="SassСompilationException">Sass compilation error.</exception>
public CompilationResult Compile(string content, CompilationOptions options = null)
{
CompilationResult result;
lock (_compilationSynchronizer)
{
SassCompiler.FileManager = _fileManager;
try
{
result = SassCompiler.Compile(content, options);
}
finally
{
SassCompiler.FileManager = null;
}
}
return result;
}
/// <summary>
/// "Compiles" a Sass-code to CSS-code
/// </summary>
/// <param name="content">Text content written on Sass</param>
/// <param name="indentedSyntax">Flag for whether to enable Sass Indented Syntax
/// for parsing the data string</param>
/// <param name="options">Compilation options</param>
/// <returns>Compilation result</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException" />
/// <exception cref="SassСompilationException">Sass compilation error.</exception>
public CompilationResult Compile(string content, bool indentedSyntax, CompilationOptions options = null)
{
CompilationResult result;
lock (_compilationSynchronizer)
{
SassCompiler.FileManager = _fileManager;
try
{
result = SassCompiler.Compile(content, indentedSyntax, options);
}
finally
{
SassCompiler.FileManager = null;
}
}
return result;
}
/// <summary>
/// "Compiles" a Sass-code to CSS-code
/// </summary>
/// <param name="content">Text content written on Sass</param>
/// <param name="inputPath">Path to input file</param>
/// <param name="outputPath">Path to output file</param>
/// <param name="sourceMapPath">Path to source map file</param>
/// <param name="options">Compilation options</param>
/// <returns>Compilation result</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException" />
/// <exception cref="SassСompilationException">Sass compilation error.</exception>
public CompilationResult Compile(string content, string inputPath, string outputPath = null,
string sourceMapPath = null, CompilationOptions options = null)
{
CompilationResult result;
lock (_compilationSynchronizer)
{
SassCompiler.FileManager = _fileManager;
try
{
result = SassCompiler.Compile(content, inputPath, outputPath, sourceMapPath, options);
}
finally
{
SassCompiler.FileManager = null;
}
}
return result;
}
/// <summary>
/// "Compiles" a Sass-file to CSS-code
/// </summary>
/// <param name="inputPath">Path to input file</param>
/// <param name="outputPath">Path to output file</param>
/// <param name="sourceMapPath">Path to source map file</param>
/// <param name="options">Compilation options</param>
/// <returns>Compilation result</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException" />
/// <exception cref="SassСompilationException">Sass compilation error.</exception>
public CompilationResult CompileFile(string inputPath, string outputPath = null,
string sourceMapPath = null, CompilationOptions options = null)
{
CompilationResult result;
lock (_compilationSynchronizer)
{
SassCompiler.FileManager = _fileManager;
try
{
result = SassCompiler.CompileFile(inputPath, outputPath, sourceMapPath, options);
}
finally
{
SassCompiler.FileManager = null;
}
}
return result;
}
}
} |
Thanks for the quick response! This worked great. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have two separate subsystems in which I use this library to compile Sass. The subsystems are completely disjoint and require different file managers. Since the
SassCompiler
is now static, how can I support this use case?The text was updated successfully, but these errors were encountered: