예제 #1
0
        //Called from the Razor-Views or master page
        public static Scripts KraftScripts(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME, string rootVirtualPath = "/modules")
        {
            if (!profile.HasScriptBundle(profile.Key + "-scripts"))
            {
                ScriptBundle  scriptBundle     = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath), null, new List <IBundleTransform>(), false);
                StringBuilder contentTemplates = new StringBuilder(10000);
                bool          appendDiv        = false;

                //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}\"!");
                }

                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, kraftDepModule.DirectoryName, moduleDepStartFile, true);
                    if (kraftDepModule.ScriptKraftBundle != null)
                    {
                        using (KraftProfiler.Current.Step($"Time loading {kraftDepModule.Key}: "))
                        {
                            scriptBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.ScriptKraftBundle, kraftDepModule.ModulePath, kraftDepModule.Key, rootVirtualPath, _Logger));
                            scriptBundle.Transforms.Add(new JsCleanupTransformation());
                        }
                    }

                    if (kraftDepModule.TemplateKraftBundle != null && kraftDepModule.TemplateKraftBundle.TemplateFiles.Count > 0)
                    {
                        if (appendDiv)
                        {
                            contentTemplates.Append(",");
                        }
                        else
                        {
                            appendDiv = true;
                        }
                        HtmlTransformation htmlTransformation = new HtmlTransformation();
                        Func <StringBuilder, ILogger, StringBuilder> minifyHtml = htmlTransformation.Process;
                        contentTemplates.Append(new KraftHtml2JsAssocArrayTransformation().Process(kraftDepModule.TemplateKraftBundle, minifyHtml, _Logger));
                    }
                }

                scriptBundle.IncludeContent("Registers.addRegister(new TemplateRegister(\"module_templates\")); Registers.getRegister(\"module_templates\").$collection= {" + contentTemplates.Append("}"));

                profile.Add(scriptBundle);
                return(profile.Scripts);
            }
            else
            {
                return(profile.Scripts);
            }
        }
예제 #2
0
        internal KraftModule(string directoryName, string moduleName,
                             DependencyInjectionContainer dependencyInjectionContainer,
                             KraftModuleCollection moduleCollection,
                             ICachingService cachingService,
                             KraftDependableModule kraftDependableModule,
                             KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            _DependencyInjectionContainer = dependencyInjectionContainer;
            DirectoryName = directoryName;
            _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
            Key = moduleName;
            //dependencies
            Dependencies = new Dictionary <string, KraftModule>();
            foreach (KeyValuePair <string, IDependable <KraftDependableModule> > item in kraftDependableModule.Dependencies)
            {
                Dependencies.Add(item.Key, moduleCollection.GetModule(item.Key));
            }

            DependencyOrderIndex = kraftDependableModule.DependencyOrderIndex;
            KraftModuleRootConf  = kraftDependableModule.KraftModuleRootConf;

            //Bundles initialize
            StyleKraftBundle    = null;
            ScriptKraftBundle   = null;
            TemplateKraftBundle = null;

            ModulePath = Path.Combine(DirectoryName, moduleName);

            //read configs and dependencies
            InitConfiguredPlugins(Key, Path.Combine(ModulePath, CONFIGURATION_FILE_NAME), cachingService);
        }
예제 #3
0
        //Called from the Razor-Views or master page
        public static Scripts KraftScripts(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME)
        {
            if (!profile.HasScriptBundle(profile.Key + "-scripts"))
            {
                ScriptBundle  scriptBundle     = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath), null, new List <IBundleTransform>(), false);
                StringBuilder contentTemplates = new StringBuilder(10000);
                bool          appendDiv        = false;

                //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}\"!");
                }
예제 #4
0
        //Called from the Razor-Views or master page
        public static Styles KraftStyles(this Profile profile)
        {
            if (!profile.HasStyleBundle(profile.Key + "-css"))
            {
                KraftModuleCollection modulesCollection = _Builder.ApplicationServices.GetService <KraftModuleCollection>();
                StyleBundle           styleBundle       = new StyleBundle(profile.Key + "-css", new PhysicalFileProvider(modulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath), delegate() { return(_ModulesRootFolder); });
                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)
                {
                    if (kraftDepModule.StyleKraftBundle != null)
                    {
                        styleBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.StyleKraftBundle, _Logger));
                    }
                }

                profile.Add(styleBundle);
                return(profile.Styles);
            }
            else
            {
                return(profile.Styles);
            }
        }
예제 #5
0
        //Called from the Razor-Views or master page
        public static Scripts KraftScripts(this Profile profile)
        {
            if (!profile.HasScriptBundle(profile.Key + "-scripts"))
            {
                KraftModuleCollection modulesCollection = _Builder.ApplicationServices.GetService <KraftModuleCollection>();
                ScriptBundle          scriptBundle      = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(modulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath));
                StringBuilder         contentTemplates  = new StringBuilder(10000);
                bool appendDiv = false;

                //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)
                {
                    if (kraftDepModule.ScriptKraftBundle != null)
                    {
                        using (KraftProfiler.Current.Step($"Time loading {kraftDepModule.Key}: "))
                        {
                            scriptBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.ScriptKraftBundle, _Logger));
                        }
                    }

                    if (kraftDepModule.TemplateKraftBundle != null && kraftDepModule.TemplateKraftBundle.TemplateFiles.Count > 0)
                    {
                        if (appendDiv)
                        {
                            contentTemplates.Append(",");
                        }
                        else
                        {
                            appendDiv = true;
                        }
                        HtmlTransformation htmlTransformation = new HtmlTransformation();
                        Func <StringBuilder, ILogger, StringBuilder> minifyHtml = htmlTransformation.Process;
                        contentTemplates.Append(new KraftHtml2JsAssocArrayTransformation().Process(kraftDepModule.TemplateKraftBundle, minifyHtml, _Logger));
                    }
                }

                scriptBundle.IncludeContent("Registers.addRegister(new TemplateRegister(\"module_templates\")); Registers.getRegister(\"module_templates\").$collection= {" + contentTemplates.Append("}"));

                profile.Add(scriptBundle);
                return(profile.Scripts);
            }
            else
            {
                return(profile.Scripts);
            }
        }