예제 #1
0
        //Called from the Razor-Views or master page
        public static Styles KraftStyles(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME)
        {
            if (!profile.HasStyleBundle(profile.Key + "-css"))
            {
                StyleBundle styleBundle = new StyleBundle(profile.Key + "-css", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath));
                styleBundle.RemoveTransformationType(typeof(LessTransformation));
                StringBuilder contentTemplates = new StringBuilder(10000);

                //try to get the target module
                KraftModule profileTargetModule = _ModulesCollection.GetModule(profile.Key);
                if (profileTargetModule == null)
                {
                    throw new Exception($"No CoreKraft module found for bundle target \"{profile.Key}\"!");
                }

                void Dive(KraftModule kmodule, HashSet <KraftModule> deps)
                {
                    foreach (var dep in kmodule.Dependencies)
                    {
                        Dive(dep.Value as KraftModule, deps);
                    }
                    deps.Add(kmodule);
                }

                HashSet <KraftModule> targetDeps = new HashSet <KraftModule>();
                Dive(profileTargetModule, targetDeps);
                List <KraftModule> targetDepsSorted = targetDeps.OrderBy(x => x.DependencyOrderIndex).ToList <KraftModule>();

                foreach (KraftModule kraftDepModule in targetDepsSorted)
                {
                    kraftDepModule.ConstructResources(_CachingService, _KraftGlobalConfigurationSettings, moduleDepStartFile, false);
                    if (kraftDepModule.StyleKraftBundle != null)
                    {
                        styleBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.StyleKraftBundle, _Logger));
                    }
                }

                profile.Add(styleBundle);
                return(profile.Styles);
            }
            else
            {
                return(profile.Styles);
            }
        }