コード例 #1
0
        static void CreateThemes(string sourcePath, string version, string outputPath)
        {
            Directory.CreateDirectory(outputPath);

            var lessCache = new CompiledLessCache(sourcePath);

            lessCache.Inflate(PersistentCache.Instance);

            foreach (var distributionName in LessRegistry.CssDistributions.Keys)
            {
                var aggregate = LessAggregation.EnumerateAllItems(sourcePath, distributionName);
                foreach (var item in aggregate)
                {
                    using (var stream = File.Create(Path.Combine(outputPath, item.CssFile.GetFileName())))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.WriteLine(LicenseHeaderHelper.FormatForCssDistribution(distributionName, version));

                            foreach (var segment in item.Segments)
                            {
                                writer.WriteLine(lessCache.GetCssForSegment(segment.Key));
                            }
                        }
                }
            }

            CopyFonts(sourcePath, outputPath, "icons");
            CopyFonts(sourcePath, outputPath, "fonts");
        }
コード例 #2
0
        public string KnownCssFiles()
        {
            var paths = from distributionName in LessRegistry.CssDistributions.Keys
                        from item in LessAggregation.EnumerateAllItems(Utils.GetStylesPath(), distributionName)
                        select item.CssFile.GetFileName();

            Response.ContentType = "text/javascript";

            return("window.knownCssFiles = " + JsonConvert.SerializeObject(paths));
        }
コード例 #3
0
        public void Inflate(PersistentCache persistentCache)
        {
            var knownSegments = new HashSet <string>();
            var parallelTasks = new List <Task>();

            foreach (var distributionName in LessRegistry.CssDistributions.Keys)
            {
                foreach (var item in LessAggregation.EnumerateAllItems(_sourcePath, distributionName))
                {
                    LessAggregation.CheckLessDuplicates(item);

                    foreach (var segment in item.Segments)
                    {
                        if (knownSegments.Contains(segment.Key))
                        {
                            continue;
                        }

                        knownSegments.Add(segment.Key);
                        parallelTasks.Add(new Task(delegate()
                        {
                            var paths = segment.LessFiles.Select(i => Path.Combine(_sourcePath, i));
                            var bag   = persistentCache.Get(new[] { "css", segment.Key }, paths, delegate()
                            {
                                if (distributionName == LessRegistry.CSS_DISTRIBUTION_DEFAULT)
                                {
                                    CheckUnusedLessConsts(paths);
                                }

                                var css = LessAggregation.CompileLessPaths(paths);
                                css     = ImageInliner.InlineImages(css, _sourcePath);
                                css     = CssHelper.StripCommentsOnly(css);
                                return(new Dictionary <string, string> {
                                    { "_", css }
                                });
                            });
                            _SegmentCache[segment.Key] = bag["_"];
                        }));
                    }
                }
            }

            foreach (var t in parallelTasks)
            {
                t.Start();
                if (Utils.IsDocker())
                {
                    // limit CPU usage in Docker builds
                    t.Wait();
                }
            }

            Task.WaitAll(parallelTasks.ToArray());
        }
コード例 #4
0
        public void KnownCssFiles()
        {
            var paths = from distributionName in LessRegistry.CssDistributions.Keys
                        from item in LessAggregation.EnumerateAllItems(Utils.GetStylesPath(), distributionName)
                        select item.CssFile.GetFileName();

            Response.ContentType = "text/javascript";

            using (var writer = new StreamWriter(Response.Body))
            {
                writer.Write("window.knownCssFiles = ");
                writer.Write(JsonConvert.SerializeObject(paths));
            }
        }
コード例 #5
0
        static void CreateThemes(string sourcePath, string version, string outputPath)
        {
            Directory.CreateDirectory(outputPath);

            var lessCache = new CompiledLessCache(sourcePath);

            lessCache.Inflate(PersistentCache.Instance);

            foreach (var distributionName in LessRegistry.CssDistributions.Keys)
            {
                var aggregate = LessAggregation.EnumerateAllItems(sourcePath, distributionName);
                foreach (var item in aggregate)
                {
                    using (var stream = File.Create(Path.Combine(outputPath, item.CssFile.GetFileName())))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.WriteLine(LicenseHeaderHelper.FormatForCssDistribution(distributionName, version));

                            foreach (var segment in item.Segments)
                            {
                                writer.WriteLine(lessCache.GetCssForSegment(segment.Key));
                            }
                        }
                }
            }

            var iconsSrcFolder  = LessRegistry.GetIconsPath(sourcePath);
            var iconsDestFolder = Path.Combine(outputPath, "icons");

            Directory.GetFiles(iconsSrcFolder, "*.*", SearchOption.AllDirectories).ToList()
            .ForEach(fileName =>
            {
                string relativePath = fileName.Remove(0, iconsSrcFolder.Length);
                string destFileName = iconsDestFolder + relativePath;
                if (!Directory.Exists(Path.GetDirectoryName(destFileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
                }

                File.Copy(fileName, destFileName, true);
            });
        }