Added simple bundle manager.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 6991595175
commit 8f4b17cda5

@ -8,6 +8,8 @@
<html>
<head>
<title>title</title>
<vc:abp-style-bundle name="GlobalStyles"></vc:abp-style-bundle>
@RenderSection("styles", false)
</head>
@ -17,6 +19,8 @@
<vc:abp-menu menu-name="@StandardMenus.Main" view-name="Default"></vc:abp-menu>
@RenderBody()
<vc:abp-script-bundle name="GlobalScripts"></vc:abp-script-bundle>
</body>
</html>

@ -1,3 +1,4 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@addTagHelper *, AbpDesk.Web.Mvc

@ -1,5 +1,6 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.EmbeddedFiles;
using Volo.Abp.Modularity;
@ -14,6 +15,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
services.Configure<EmbeddedFileOptions>(options =>
{
options.Sources.Add(
new EmbeddedFileSet(
"/libs/",
GetType().GetTypeInfo().Assembly,
"Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.libs"
)
);
options.Sources.Add(
new EmbeddedFileSet(
"/Views/",
@ -22,6 +31,19 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
)
);
});
services.Configure<BundlingOptions>(options =>
{
options.StyleBundles.Add("GlobalStyles", new[]
{
"/libs/bootstrap/css/bootstrap.css"
});
options.ScriptBundles.Add("GlobalScripts", new[]
{
"/libs/bootstrap/js/bootstrap.js"
});
});
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -15,7 +15,8 @@
"buildOptions": {
"embed": {
"include": [
"Views/**/*.*"
"Views/**/*.*",
"libs/**/*.*"
]
}
}

@ -0,0 +1,31 @@
using System.Collections.Generic;
using Volo.ExtensionMethods.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.Bundling
{
public class BundleCollection
{
private readonly Dictionary<string, List<string>> _bundles;
public BundleCollection()
{
_bundles = new Dictionary<string, List<string>>();
}
public void Add(string bundleName, string[] files)
{
_bundles.GetOrAdd(bundleName, () => new List<string>()).AddRange(files);
}
public List<string> GetFiles(string bundleName)
{
var files = _bundles.GetOrDefault(bundleName);
if (files == null)
{
throw new AbpException("Undefined bundle: " + bundleName);
}
return files;
}
}
}

@ -0,0 +1,26 @@
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Volo.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.Bundling
{
public class BundleManager : IBundleManager, ITransientDependency
{
private readonly BundlingOptions _options;
public BundleManager(IOptions<BundlingOptions> options)
{
_options = options.Value;
}
public List<string> GetStyleBundleFiles(string bundleName)
{
return _options.StyleBundles.GetFiles(bundleName);
}
public List<string> GetScriptBundleFiles(string bundleName)
{
return _options.ScriptBundles.GetFiles(bundleName);
}
}
}

@ -0,0 +1,15 @@
namespace Volo.Abp.AspNetCore.Mvc.Bundling
{
public class BundlingOptions
{
public BundleCollection StyleBundles { get; set; }
public BundleCollection ScriptBundles { get; set; }
public BundlingOptions()
{
StyleBundles = new BundleCollection();
ScriptBundles = new BundleCollection();
}
}
}

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.Bundling
{
public interface IBundleManager
{
List<string> GetStyleBundleFiles(string bundleName);
List<string> GetScriptBundleFiles(string bundleName);
}
}

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Bundling;
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpScriptBundle
{
public class AbpScriptBundleViewComponent : ViewComponent
{
private readonly IBundleManager _bundleManager;
public AbpScriptBundleViewComponent(IBundleManager bundleManager)
{
_bundleManager = bundleManager;
}
public IViewComponentResult Invoke(string name)
{
var files = _bundleManager.GetScriptBundleFiles(name);
return View(files);
}
}
}

@ -0,0 +1,5 @@
@model List<string>
@foreach (var scriptFile in Model)
{
<script src="@scriptFile" type="text/javascript"></script>
}

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Bundling;
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpStyleBundle
{
public class AbpStyleBundleViewComponent : ViewComponent
{
private readonly IBundleManager _bundleManager;
public AbpStyleBundleViewComponent(IBundleManager bundleManager)
{
_bundleManager = bundleManager;
}
public IViewComponentResult Invoke(string name)
{
var files = _bundleManager.GetStyleBundleFiles(name);
return View(files);
}
}
}

@ -0,0 +1,5 @@
@model List<string>
@foreach (var styleFile in Model)
{
<link rel="stylesheet" type="text/css" href="@styleFile" />
}
Loading…
Cancel
Save