Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions src/Nancy.BundleIt/Bundles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Bundles Instance
internal Dictionary<string, string> _style_tag_bundles = new Dictionary<string, string>();
internal Dictionary<string, BundleAsset> _script_compressed_bundles = new Dictionary<string, BundleAsset>();
internal Dictionary<string, BundleAsset> _style_compressed_bundles = new Dictionary<string, BundleAsset>();

public Bundle AddScripts(string bundlename, List<BundleItFile> files)
{
bundlename = bundlename.ToUpper();
Expand Down Expand Up @@ -83,7 +83,7 @@ internal string GetBundleTags(string name, eBundleType type)

return _style_tag_bundles[n];
}

return string.Empty;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ void BuildDebugBundles()
var bundlefiles = _script_files.Where(f => f.bundle_name == bname).ToList();
bundlestring = new StringBuilder();
LoadDebugBundles(bname, bundlefiles, bundlestring, eBundleType.script);
_script_tag_bundles.Add(bname, bundlestring.ToString());
AddOrUpdateDictionary(bname, bundlestring.ToString(), _script_tag_bundles);
}

// styles
Expand All @@ -140,7 +140,7 @@ void BuildDebugBundles()
var bundlefiles = _style_files.Where(f => f.bundle_name == bname).ToList();
bundlestring = new StringBuilder();
LoadDebugBundles(bname, bundlefiles, bundlestring, eBundleType.style);
_style_tag_bundles.Add(bname, bundlestring.ToString());
AddOrUpdateDictionary(bname, bundlestring.ToString(), _style_tag_bundles);
}

}
Expand All @@ -150,7 +150,8 @@ void LoadDebugBundles(string bundlename, List<BundleItFile> files, StringBuilder
foreach (var s in files)
{
// load referenced bundle files
if(!string.IsNullOrEmpty(s.bundle_ref_name)){
if (!string.IsNullOrEmpty(s.bundle_ref_name))
{

// get files by bundle name
List<BundleItFile> refbundlefiles = null;
Expand All @@ -164,14 +165,14 @@ void LoadDebugBundles(string bundlename, List<BundleItFile> files, StringBuilder
}
else
{
if(type == eBundleType.script)
if (type == eBundleType.script)
bundlestring.Append(string.Format(_script_tag_standard_template, s.debugrelativepath) + "\n");
if(type == eBundleType.style)

if (type == eBundleType.style)
bundlestring.Append(string.Format(_style_tag_standard_template, s.debugrelativepath) + "\n");

}

}
}

Expand All @@ -189,10 +190,10 @@ void BuildReleaseBundles()

// check for cdn's
SplitBundlesWithCDNs(BundleResolvedFiles);

// generate release bundles
GenerateReleaseBundles(BundleResolvedFiles, eBundleType.script);

// generate bundle tags
GenerateReleaseBundleTags(BundleResolvedFiles, eBundleType.script);
}
Expand All @@ -214,7 +215,7 @@ void BuildReleaseBundles()
// generate bundle tags
GenerateReleaseBundleTags(BundleResolvedFiles, eBundleType.style);
}

}

void LoadReleaseBundles(string bundlename, List<BundleItFile> files, List<BundleItFile> bundle_resolved_files, eBundleType type)
Expand Down Expand Up @@ -265,7 +266,7 @@ void SplitBundlesWithCDNs(List<BundleItFile> BundleResolvedFiles)
f.sub_bundle_num = i;
prevsub = i;
}

}
}

Expand Down Expand Up @@ -341,7 +342,7 @@ void GenerateReleaseBundleTags(List<BundleItFile> BundleResolvedFiles, eBundleTy
{
tags = new StringBuilder();
var unique_resolved_bundles = BundleResolvedFiles.Where(b => b.bundle_name == bundle.bundle_name).DistinctBy(b2 => b2.resolved_bundle_name);

foreach (var rbundle in unique_resolved_bundles)
{
if (rbundle.IsCDN)
Expand All @@ -360,19 +361,20 @@ void GenerateReleaseBundleTags(List<BundleItFile> BundleResolvedFiles, eBundleTy
}

if (type == eBundleType.script)
_script_tag_bundles.Add(bundle.bundle_name, tags.ToString());
AddOrUpdateDictionary(bundle.bundle_name, tags.ToString(), _script_tag_bundles);

if (type == eBundleType.style)
_style_tag_bundles.Add(bundle.bundle_name, tags.ToString());
AddOrUpdateDictionary(bundle.bundle_name, tags.ToString(), _style_tag_bundles);
}
}

string LoadFile(string filepath)
{

if(!File.Exists(filepath)){
if (!File.Exists(filepath))
{

if(ConfigSettings.Instance.ThrowExceptionWhenFileMissing)
if (ConfigSettings.Instance.ThrowExceptionWhenFileMissing)
throw new FileNotFoundException("Could not find file '" + filepath + "'.", filepath);
else
return string.Empty;
Expand All @@ -398,7 +400,7 @@ string YUI_JS(string filesource, ConfigSettings.YUICompressionSettings.Js JsSett

return jscompressor.Compress(filesource);
}
catch(Exception ex)
catch (Exception ex)
{
var msg = ex.Message;
return filesource;
Expand All @@ -423,6 +425,16 @@ string YUI_CSS(string filesource, ConfigSettings.YUICompressionSettings.CSS CssS
}
}


private void AddOrUpdateDictionary(string key, string value, Dictionary<string, string> dictionary)
{
if (dictionary.ContainsKey(key))
{
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
}
}
}
}
}