Browse Source

Implemented inheriting bundles from other bundles.

pull/301/head
Halil ibrahim Kalkan 8 years ago
parent
commit
aab9791eef
  1. 8
      src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs
  2. 7
      src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs
  3. 28
      src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationExtensions.cs
  4. 42
      src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs
  5. 3
      src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs

8
src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs

@ -1,4 +1,6 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public class BundleConfiguration
{
@ -6,10 +8,14 @@
public BundleContributorCollection Contributors { get; }
public List<string> BaseBundles { get; }
public BundleConfiguration(string name)
{
Name = name;
Contributors = new BundleContributorCollection();
BaseBundles = new List<string>();
}
}
}

7
src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs

@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Theming;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public class BundleConfigurationContext : IBundleConfigurationContext
{
public List<string> Files { get; }
public ITheme Theme { get; }
public IServiceProvider ServiceProvider { get; }
public BundleConfigurationContext(List<string> files, ITheme theme, IServiceProvider serviceProvider)
public BundleConfigurationContext(IServiceProvider serviceProvider)
{
Files = files;
Theme = theme;
Files = new List<string>();
ServiceProvider = serviceProvider;
}
}

28
src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs → src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationExtensions.cs

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
@ -13,25 +12,32 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors)
{
if (!contributors.IsNullOrEmpty())
Check.NotNull(contributors, nameof(contributors));
foreach (var contributor in contributors)
{
foreach (var contributor in contributors)
{
bundleConfiguration.Contributors.Add(contributor);
}
bundleConfiguration.Contributors.Add(contributor);
}
return bundleConfiguration;
}
public static BundleConfiguration AddBaseBundles(this BundleConfiguration bundleConfiguration, params string[] bundleNames)
{
Check.NotNull(bundleNames, nameof(bundleNames));
bundleConfiguration.BaseBundles.AddRange(bundleNames);
return bundleConfiguration;
}
public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params Type[] contributorTypes)
{
if (!contributorTypes.IsNullOrEmpty())
Check.NotNull(contributorTypes, nameof(contributorTypes));
foreach (var contributorType in contributorTypes)
{
foreach (var contributorType in contributorTypes)
{
bundleConfiguration.Contributors.Add(contributorType);
}
bundleConfiguration.Contributors.Add(contributorType);
}
return bundleConfiguration;

42
src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
@ -46,27 +47,28 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
public List<string> GetStyleBundleFiles(string bundleName)
{
return GetBundleFiles(_options.StyleBundles.Get(bundleName), _styleBundler);
return GetBundleFiles(_options.StyleBundles, bundleName, _styleBundler);
}
public List<string> GetScriptBundleFiles(string bundleName)
{
return GetBundleFiles(_options.ScriptBundles.Get(bundleName), _scriptBundler);
return GetBundleFiles(_options.ScriptBundles, bundleName, _scriptBundler);
}
protected virtual List<string> GetBundleFiles(BundleConfiguration bundleConfiguration, IBundler bundler)
protected virtual List<string> GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler)
{
//TODO: Caching
//TODO: Concurrency
var files = CreateFileListFromConfiguration(bundleConfiguration);
var files = CreateFileList(bundles, bundleName);
if (!IsBundlingEnabled())
{
return files;
}
var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleConfiguration.Name + "." + bundler.FileExtension;
var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundler.FileExtension;
var bundleResult = bundler.Bundle(new BundlerContext(bundleRelativePath, files));
@ -101,17 +103,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
//return !_hostingEnvironment.IsDevelopment();
}
protected virtual List<string> CreateFileListFromConfiguration(BundleConfiguration bundleConfiguration)
protected virtual List<string> CreateFileList(BundleConfigurationCollection bundles, string bundleName)
{
using (var scope = _serviceProvider.CreateScope())
{
var context = new BundleConfigurationContext(
new List<string>(),
_themeManager.CurrentTheme,
scope.ServiceProvider
);
var contributors = new List<IBundleContributor>();
var context = new BundleConfigurationContext(scope.ServiceProvider);
AddContributorsWithBaseBundles(contributors, bundles, context, bundleName);
foreach (var contributor in bundleConfiguration.Contributors.GetAll())
foreach (var contributor in contributors)
{
contributor.ConfigureBundle(context);
}
@ -119,5 +120,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return context.Files;
}
}
protected virtual void AddContributorsWithBaseBundles(List<IBundleContributor> contributors, BundleConfigurationCollection bundles, BundleConfigurationContext context, string bundleName)
{
var bundleConfiguration = bundles.Get(bundleName);
foreach (var baseBundleName in bundleConfiguration.BaseBundles)
{
AddContributorsWithBaseBundles(contributors, bundles, context, baseBundleName); //Recursive call
}
var selfContributors = bundleConfiguration.Contributors.GetAll();
if (selfContributors.Any())
{
contributors.AddRange(selfContributors);
}
}
}
}

3
src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Theming;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
@ -7,7 +6,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
public interface IBundleConfigurationContext : IServiceProviderAccessor
{
List<string> Files { get; }
ITheme Theme { get; }
}
}
Loading…
Cancel
Save