private void RegisterComponents(StringBuilder script, Dictionary <string, NgJsViewDeps> dependencies) { List <string> components = dependencies.Values.Select(d => d.Components).Aggregate( new List <string>(), (total, next) => total.Concat(next).ToList()) .Distinct().ToList(); script.AppendLine(); script.AppendLine("/** Register components: start **/"); foreach (string componentName in components) { NgJsBaseData componentData = Provider.GetComponentData(componentName); string componentJs = File.ReadAllText(NgJsHelper.MapPath(componentData.Path)); string componentScript = string.Format( "{0} ; app.component('{1}', {2});", componentJs, componentData.NgName, componentData.JsName); script.Append(ScriptHelper.WrapJsCodeInIIFE(componentScript)); script.AppendLine(); } script.AppendLine("/** Register components: end **/"); }
private void RegisterFilters(StringBuilder script, Dictionary <string, NgJsViewDeps> dependencies) { List <string> filters = dependencies.Values.Select(d => d.Filters).Aggregate( new List <string>(), (total, next) => total.Concat(next).ToList()) .Distinct().ToList(); script.AppendLine(); script.AppendLine("/** Register filters: start **/"); foreach (string filterName in filters) { NgJsBaseData filterData = Provider.GetFilterData(filterName); string filterJs = File.ReadAllText(NgJsHelper.MapPath(filterData.Path)); string filterScript = string.Format( "{0} ; app.filter('{1}', ['$sce', {2}]);", filterJs, filterData.NgName, filterData.JsName); script.Append(ScriptHelper.WrapJsCodeInIIFE(filterScript)); script.AppendLine(); } script.AppendLine("/** Register filters: end **/"); }
private void RegisterDirectives(StringBuilder script, Dictionary <string, NgJsViewDeps> dependencies) { List <string> directives = dependencies.Values.Select(d => d.Directives).Aggregate( new List <string>(), (total, next) => total.Concat(next).ToList()) .Distinct().ToList(); script.AppendLine(); script.AppendLine("/** Register directives: start **/"); foreach (string directiveName in directives) { NgJsBaseData directiveData = Provider.GetDirectiveData(directiveName); string directiveJs = File.ReadAllText(NgJsHelper.MapPath(directiveData.Path)); string directiveScript = string.Format( "{0} ; app.directive('{1}', {2});", directiveJs, directiveData.NgName, directiveData.JsName); script.Append(ScriptHelper.WrapJsCodeInIIFE(directiveScript)); script.AppendLine(); } script.AppendLine("/** Register directives: end **/"); }
public NgJsBaseData GetServiceData(string serviceName) { string basename = serviceName + DefaultServiceSuffix; return(new NgJsBaseData { Path = NgJsHelper.GetNgJsFilePath(ServicesPath, basename, JsExt), JsName = basename }); }
public NgJsBaseData GetFilterData(string filterName) { string basename = filterName + DefaultFilterSuffix; return(new NgJsBaseData { Path = NgJsHelper.GetNgJsFilePath(Path.Combine(FiltersPath, filterName), basename, JsExt), JsName = basename, NgName = filterName.FirstCharToLower() }); }
public NgJsBaseData GetDirectiveData(string directiveName) { string basename = directiveName + DefaultDirectiveSuffix; return(new NgJsBaseData { Path = NgJsHelper.GetNgJsFilePath(Path.Combine(DirectivesPath, directiveName), basename, JsExt), JsName = basename, NgName = directiveName.FirstCharToLower() }); }
public NgJsBaseData GetComponentData(string componentName) { string basename = componentName + DefaultComponentSuffix; return(new NgJsBaseData { Path = NgJsHelper.GetNgJsFilePath(Path.Combine(ComponentsPath, componentName), basename, JsExt), JsName = basename, NgName = componentName.FirstCharToLower() }); }
public NgJsViewData GetViewData(string viewName) { string baseDir = Path.Combine(ViewsPath, viewName); string baseFilename = viewName + DefaultViewSuffix; return(new NgJsViewData { Path = NgJsHelper.GetNgJsFilePath(baseDir, baseFilename, JsExt), JsName = viewName + DefaultControllerSuffix, InitFunctionJsName = viewName + DefaultControllerInitSuffix, TemplatePath = NgJsHelper.GetNgJsFilePath(baseDir, baseFilename, CshtmlExt) }); }
public NgJsBaseData GetConfigData(string moduleName) { string configName = string.Join( string.Empty, moduleName.Split(new char[] { '.', '-' }).Select(s => s.FirstCharToUpper()).ToList()) + DefaultConfigSuffix; return(new NgJsBaseData { Path = NgJsHelper.GetNgJsFilePath(ConfigsPath, configName, JsExt), JsName = configName }); }
private void RegisterServices(StringBuilder script, Dictionary <string, NgJsViewDeps> dependencies) { script.AppendLine(); script.AppendLine("/** Register services **/"); List <string> services = new List <string>(); foreach (string s in dependencies.Keys) { NgJsViewDeps dep = dependencies[s]; foreach (string service in dep.Services) { if (service != null) { services.Add(service.Trim()); } } } // include services one time only foreach (string service in services.Distinct()) { NgJsBaseData serviceData = Provider.GetServiceData(service); script.AppendLine(); if (IncludeMode == IncludeMode.Load) { string mappedPath = NgJsHelper.MapPath(serviceData.Path); if (File.Exists(mappedPath)) { script.Append(File.ReadAllText(mappedPath)); } } else { script.AppendLine("Include mode: link not implemented"); } script.AppendLine(); script.AppendFormat("app.service('{1}', {0});", serviceData.NgName, serviceData.JsName); } script.AppendLine("/** End Register services **/"); script.AppendLine(); }
private static void LoadView(NgJsViewDeps target, NgJsViewData viewData) { if (target.View != null) { throw new ArgumentException("Unable to load " + viewData.JsName + ": view has already been loaded!"); } string diskPath = NgJsHelper.MapPath(viewData.Path); target.View = "/** INCLUDE JS " + viewData.JsName + " @" + diskPath + "**/"; if (File.Exists(diskPath)) { target.View += File.ReadAllText(diskPath); } else { target.View = "/** js at '" + diskPath + "' not found **/"; } }
private void RegisterModulesConfig(StringBuilder script, List <string> moduleNames) { script.AppendLine(); script.AppendLine("/** Register modules config **/"); foreach (string module in moduleNames) { NgJsBaseData moduleConfig = Provider.GetConfigData(module); if (File.Exists(moduleConfig.Path)) { string jsCode = File.ReadAllText(NgJsHelper.MapPath(moduleConfig.Path)) + Environment.NewLine + string.Format("app.config({0});", moduleConfig.JsName); script.AppendLine(ScriptHelper.WrapJsCodeInIIFE(jsCode)); } } script.AppendLine("/** End Register modules config **/"); script.AppendLine(); }