public static IHtmlString Config(string bundlePath) { if (bundlePath == null) { throw new ArgumentNullException("bundlePath"); } var defines = new List <String>(); var files = BundleResolver.Current.GetBundleContents(bundlePath); var filenamesByPath = files.ToDictionary(f => ModuleRegistry.GetModuleName(f), f => f); if (BundleTable.EnableOptimizations) { var moduleNames = filenamesByPath.Keys.Select(k => k.TrimBaseUrl(_absoluteBaseUrl)); defines.Add(string.Format("'{0}': ['{1}']", Scripts.Url(bundlePath), string.Join("','", moduleNames))); } else { defines.Add(String.Join(",", filenamesByPath.Select(k => { var absolutePath = Scripts.Url(k.Value).ToString(); var moduleName = k.Key.TrimBaseUrl(_absoluteBaseUrl); var modulePath = absolutePath.RemoveJsFromFileName().TrimBaseUrl(_absoluteBaseUrl); return(string.Format("'{0}': '{1}'", moduleName, modulePath)); }))); } var propertyName = BundleTable.EnableOptimizations ? "bundles" : "paths"; return(new HtmlString(String.Format("require.config({{baseUrl: '{0}', {1}: {{{2}}}}});", _absoluteBaseUrl, propertyName, string.Join(",", defines)))); }
public string Process(string includedVirtualPath, string input) { ModuleRegistry.Define(_moduleName, includedVirtualPath); if (_moduleName.StartsWith("text!")) { var sanitizedInput = input .Replace(Environment.NewLine, "\\r\\n") .Replace("\"", "\\\""); return(string.Format(@"define(""{0}"",[],function(){{return ""{1}"";}});", _moduleName, sanitizedInput)); } return(_defineRegex.Replace(input, "define('" + _moduleName + "', ")); //The regex takes the opening bracket as well }