/// <summary> /// Creates a standalone wrapper executable for the <see cref="SassAndCoffee"/> library. /// <para>See also https://github.com/xpaulbettsx/SassAndCoffee/issues/44 </para> /// </summary> /// <param name="args">path, iscompressed, list of dependencies (;)</param> static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; // make sure we have enough args if (null == args || 0 == args.Count()) { throw new ArgumentNullException("You must provide at least a file path to compile"); } // get the args and defaults string path = args[0]; string outPath = args[1]; bool compressed = (args.Count() > 2 ? Convert.ToBoolean(args[1]) : false); string[] dependencies = (args.Count() > 3 ? args[3].Split(';') : new string[]{} ); Console.WriteLine("Building file [{0}]", path); Console.WriteLine(" as {0}compressed", compressed ? string.Empty : "un"); Console.WriteLine(" with dependencies [{0}]", string.Join(", ", dependencies)); // use the compiler using (var compiler = new SassCompiler()) { var compiled = compiler.Compile(path, compressed, dependencies.ToList()); // add prefix, etc compiled = string.Format("{1}{0}{0}{2}" , compressed ? string.Empty : Environment.NewLine , compressed ? Properties.Settings.Default.PrefixCompressed : Properties.Settings.Default.Prefix.Replace("{{date}}", DateTime.Now.ToString()) , compiled ); // n00b parse path ^^ string destination = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar; string desTmp; string[] outPathTmp = outPath.Split('/'); for (var i = 0; i < outPathTmp.Length; i++) { desTmp = null; if (outPathTmp[i] == "..") { destination = string.Format("{0}" , System.IO.Directory.GetParent(Path.GetDirectoryName(destination))); } else { desTmp = string.Format("{0}" , outPathTmp[i]); } destination += desTmp + Path.DirectorySeparatorChar; } //write to file destination = string.Format("{0}{1}.css" , destination , Path.GetFileNameWithoutExtension(path) ); File.WriteAllText(destination, compiled); Console.WriteLine("SASS Compiled to [{0}]", destination); } }
public void SassFeaturesSmokeTest() { var fixture = new SassCompiler(); string result = fixture.Compile( "features.scss", false, null ); Assert.False( string.IsNullOrWhiteSpace( result ) ); using ( var file = File.CreateText( "features.css" ) ) { file.WriteLine( result ); } }
public void OnContentLoaded(CombinatorResource resource) { var extension = Path.GetExtension(resource.AbsoluteUrl.ToString()).ToLowerInvariant(); if (extension != ".sass" && extension != ".scss") return; using (var compiler = new SassCompiler()) { resource.Content = compiler.Compile(_virtualPathProvider.MapPath(resource.RelativeVirtualPath).Replace("\\", @"\"), false, new List<string>()); } }
public override IEnumerable<PvcCore.PvcStream> Execute(IEnumerable<PvcCore.PvcStream> inputStreams) { var resultStreams = new List<PvcStream>(); foreach (var inputStream in inputStreams) { var sassContent = PvcUtil.StreamToTempFile(inputStream); var cssContent = new SassCompiler().Compile(sassContent, false, null); var newStreamName = Path.Combine(Path.GetDirectoryName(inputStream.StreamName), Path.GetFileNameWithoutExtension(inputStream.StreamName) + ".css"); var resultStream = PvcUtil.StringToStream(cssContent, newStreamName); resultStreams.Add(resultStream); } return resultStreams; }
string compileInput(string filename, string input) { var fixture = new SassCompiler(); using (var of = File.CreateText(filename)) { of.WriteLine(input); } try { // TODO: Fix this // fixture.Init(TODO); string result = fixture.Compile(filename, true, null); Console.WriteLine(result); return result; } finally { File.Delete(filename); } }
protected override void ExecuteTask() { SassCompiler compiler = new SassCompiler(); Regex extensionRegex = new Regex( ".s(a|c)ss$" ); foreach ( string filename in this.Files.FileNames ) { string targetFilename = extensionRegex.IsMatch( filename ) ? extensionRegex.Replace( filename, ".css" ) : ( filename + ".css" ); try { this.Log( Level.Info, "sass compiling " + filename ); if ( !File.Exists( filename ) ) { throw new Exception( "Can't sass compile because file doesn't exist: " + filename ); } string output = compiler.Compile( filename, this.Compress, dependentFileList: null ); File.WriteAllText( targetFilename, output ); } catch ( Exception ex ) { File.WriteAllText( targetFilename, string.Format( "Error sass compiling {0}: {1}", filename, ex.Message ) ); throw new BuildException( "Error sass compiling " + filename + ": " + ex.Message, ex ); } } this.Log( Level.Info, "sass compiling all files complete" ); }
/// <summary> /// Creates a standalone wrapper executable for the <see cref="SassAndCoffee"/> library. /// <para>See also https://github.com/xpaulbettsx/SassAndCoffee/issues/44 </para> /// </summary> /// <param name="args">path, iscompressed, list of dependencies (;)</param> static void Main(string[] args) { // make sure we have enough args if (null == args || 0 == args.Count()) { throw new ArgumentNullException("You must provide at least a file path to compile"); } // get the args and defaults string path = args[0]; bool compressed = (args.Count() > 1 ? Convert.ToBoolean(args[1]) : false); string[] dependencies = (args.Count() > 2 ? args[2].Split(';') : new string[]{} ); Console.WriteLine("Building file [{0}]", path); Console.WriteLine(" as {0}compressed", compressed ? string.Empty : "un"); Console.WriteLine(" with dependencies [{0}]", string.Join(", ", dependencies)); // use the compiler using (var compiler = new SassCompiler()) { var compiled = compiler.Compile(path, compressed, dependencies.ToList()); // add prefix, etc compiled = string.Format("{1}{0}{0}{2}" , compressed ? string.Empty : Environment.NewLine , compressed ? Properties.Settings.Default.PrefixCompressed : Properties.Settings.Default.Prefix.Replace("{{date}}", DateTime.Now.ToString()) , compiled ); //write to file var destination = string.Format("{1}{0}{2}.css" , Path.DirectorySeparatorChar , Path.GetDirectoryName(path) , Path.GetFileNameWithoutExtension(path) ); File.WriteAllText(destination, compiled); Console.WriteLine("SASS Compiled to [{0}]", destination); } }
public static int Main( string[] TheArgs ) { bool compress = false; bool quiet = false; List<string> filenames = new List<string>(); if ( TheArgs == null || TheArgs.Length < 1 ) { Console.Error.WriteLine( "No argumentes passed" ); if ( !quiet ) { Help(); } return -2; } List<string> args = new List<string>( TheArgs ); while ( args.Count > 0 ) { string arg = args[0]; args.RemoveAt( 0 ); if ( string.IsNullOrEmpty( arg ) ) { continue; } if ( arg.StartsWith( "-" ) ) { switch ( arg ) { case "-compress": compress = true; break; case "-quiet": case "-q": quiet = true; break; default: Console.Error.WriteLine( "Unknown parameter: " + arg ); if ( !quiet ) { Help(); } return -2; } } else { // The rest is the list of files filenames.Add( arg ); if ( args.Count > 0 ) { filenames.AddRange( args ); } break; } } if ( filenames.Count < 1 ) { Console.Error.WriteLine( "No files to sass compile" ); if ( !quiet ) { Help(); } return -1; } SassCompiler compiler = new SassCompiler(); Regex extensionRegex = new Regex( ".s(a|c)ss$" ); foreach ( var filename in filenames ) { string targetFilename = extensionRegex.IsMatch( filename ) ? extensionRegex.Replace( filename, ".css" ) : ( filename + ".css" ); try { if ( !File.Exists( filename ) ) { Console.Error.WriteLine( "Can't sass compile because file doesn't exist: " + filename ); return -1; } string output = compiler.Compile( filename, compress, dependentFileList: null ); File.WriteAllText( targetFilename, output ); } catch ( Exception ex ) { File.WriteAllText( targetFilename, string.Format( "Error sass compiling {0}: {1}", filename, ex.Message ) ); Console.Error.WriteLine( "Error compiling {0}: {1}", filename, ex.Message ); return -1; } } return 0; }