예제 #1
0
        private static string GetFileName(string imageFileName, SpriteDocument sprite, ExportFormat format)
        {
            switch (format)
            {
            case ExportFormat.Css:
                if (sprite.CssOutputDirectory != null)
                {
                    return(imageFileName = ProjectHelpers.GetAbsolutePathFromSettings(sprite.CssOutputDirectory, imageFileName + ".css"));
                }
                return(imageFileName + ".css");

            case ExportFormat.Less:
                if (sprite.CssOutputDirectory != null)
                {
                    return(imageFileName = ProjectHelpers.GetAbsolutePathFromSettings(sprite.LessOutputDirectory, imageFileName + ".less"));
                }
                return(imageFileName + ".less");

            case ExportFormat.Scss:
                if (sprite.CssOutputDirectory != null)
                {
                    return(imageFileName = ProjectHelpers.GetAbsolutePathFromSettings(sprite.ScssOutputDirectory, imageFileName + ".scss"));
                }
                return(imageFileName + ".scss");

            case ExportFormat.Json:
                return(imageFileName + ".map");
            }

            return(null);
        }
예제 #2
0
        private async Task GenerateAsync(SpriteDocument sprite, bool hasUpdated = false)
        {
            _dte.StatusBar.Text = "Generating sprite...";

            ProjectHelpers.AddFileToProject(Path.GetDirectoryName(sprite.FileName), sprite.FileName);

            string imageFile = Path.ChangeExtension(sprite.FileName, sprite.FileExtension);

            if (string.IsNullOrEmpty(sprite.OutputDirectory))
            {
                imageFile = ProjectHelpers.GetAbsolutePathFromSettings(sprite.OutputDirectory, Path.ChangeExtension(sprite.FileName, sprite.FileExtension));
            }

            ProjectHelpers.CreateDirectoryInProject(imageFile);

            IEnumerable <SpriteFragment> fragments = await SpriteGenerator.MakeImage(sprite, imageFile, UpdateSpriteAsync);

            ProjectHelpers.AddFileToProject(sprite.FileName, imageFile);

            if (!hasUpdated)
            {
                WebEssentialsPackage.DTE.ItemOperations.OpenFile(sprite.FileName);
            }

            await Export(fragments, imageFile, sprite);

            if (sprite.Optimize)
            {
                await new ImageCompressor().CompressFilesAsync(imageFile);
            }

            _dte.StatusBar.Text = "Sprite generated";
        }