コード例 #1
0
        public async Task <XDocument> WriteSpriteRecipe()
        {
            string            root     = ProjectHelpers.GetRootFolder();
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };
            XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

            if (string.IsNullOrEmpty(root))
            {
                root = ProjectHelpers.GetProjectFolder(FileName);
            }

            ProjectHelpers.CheckOutFileFromSourceControl(FileName);

            using (XmlWriter writer = await Task.Run(() => XmlWriter.Create(FileName, settings)))
            {
                XDocument doc =
                    new XDocument(
                        new XElement("sprite",
                                     new XAttribute(XNamespace.Xmlns + "xsi", xsi),
                                     new XAttribute(xsi + "noNamespaceSchemaLocation", "http://vswebessentials.com/schemas/v1/sprite.xsd"),
                                     new XElement("settings",
                                                  new XComment("Determines if the sprite image should be automatically optimized after creation/update."),
                                                  new XElement("optimize", Optimize.ToString().ToLowerInvariant()),
                                                  new XComment("Determines the orientation of images to form this sprite. The value must be vertical or horizontal."),
                                                  new XElement("orientation", IsVertical ? "vertical" : "horizontal"),
                                                  new XComment("The margin (in pixel) around and between the constituent images."),
                                                  new XElement("margin", Margin),
                                                  new XComment("File extension of sprite image."),
                                                  new XElement("outputType", FileExtension.ToString().ToLowerInvariant()),
                                                  new XComment("Determine whether to generate/re-generate this sprite on building the solution."),
                                                  new XElement("runOnBuild", RunOnBuild.ToString().ToLowerInvariant()),
                                                  new XComment("Use full path to generate unique class or mixin name in CSS, LESS and SASS files. Consider disabling this if you want class names to be filename only."),
                                                  new XElement("fullPathForIdentifierName", UseFullPathForIdentifierName.ToString().ToLowerInvariant()),
                                                  new XComment("Use absolute path in the generated CSS-like files. By default, the URLs are relative to sprite image file (and the location of CSS, LESS and SCSS)."),
                                                  new XElement("useAbsoluteUrl", UseAbsoluteUrl.ToString().ToLowerInvariant()),
                                                  new XComment("Specifies a custom subfolder to save files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                                  new XElement("outputDirectory", OutputDirectory),
                                                  new XComment("Specifies a custom subfolder to save CSS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                                  new XElement("outputDirectoryForCss", CssOutputDirectory),
                                                  new XComment("Specifies a custom subfolder to save LESS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                                  new XElement("outputDirectoryForLess", LessOutputDirectory),
                                                  new XComment("Specifies a custom subfolder to save SCSS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                                  new XElement("outputDirectoryForScss", ScssOutputDirectory)
                                                  ),
                                     new XComment("The order of the <file> elements determines the order of the images in the sprite."),
                                     new XElement("files", BundleAssets.Select(file => new XElement("file", "/" + FileHelpers.RelativePath(root, file))))
                                     )
                        );

                doc.Save(writer);

                return(doc);
            }
        }
コード例 #2
0
        public async Task WriteBundleRecipe()
        {
            string            root     = ProjectHelpers.GetRootFolder();
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };
            XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

            using (XmlWriter writer = await Task.Run(() => XmlWriter.Create(FileName, settings)))
            {
                new XDocument(
                    new XElement("sprite",
                                 new XAttribute(XNamespace.Xmlns + "xsi", xsi),
                                 new XAttribute(xsi + "noNamespaceSchemaLocation", "http://vswebessentials.com/schemas/v1/sprite.xsd"),
                                 new XElement("settings",
                                              new XComment("Determines if the sprite image should be automatically optimized after creation/update"),
                                              new XElement("optimize", Optimize.ToString().ToLowerInvariant()),
                                              new XElement("orientation", IsVertical ? "vertical" : "horizontal"),
                                              new XElement("outputType", FileExtension.ToString().ToLowerInvariant()),
                                              new XComment("Use full path to generate unique class or mixin name in CSS, LESS and SASS files. Consider disabling this if you want class names to be filename only."),
                                              new XElement("fullPathForIdentifierName", UseFullPathForIdentifierName.ToString().ToLowerInvariant()),
                                              new XComment("Use absolute path in the generated CSS-like files. By default, the URLs are relative to sprite image file (and the location of CSS, LESS and SCSS)."),
                                              new XElement("useAbsoluteUrl", UseAbsoluteUrl.ToString().ToLowerInvariant()),
                                              new XComment("Specifies a custom subfolder to save CSS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                              new XElement("outputDirectoryForCss", CssOutputDirectory),
                                              new XComment("Specifies a custom subfolder to save LESS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                              new XElement("outputDirectoryForLess", LessOutputDirectory),
                                              new XComment("Specifies a custom subfolder to save SCSS files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                              new XElement("outputDirectoryForScss", ScssOutputDirectory)
                                              ),
                                 new XComment("The order of the <file> elements determines the order of the images in the sprite."),
                                 new XElement("files", ImageFiles.Select(file => new XElement("file", "/" + FileHelpers.RelativePath(root, file))))
                                 )
                    ).Save(writer);
            }
        }