public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder); var module = new AngularModule(name + "Module"); var formFields = new List <FormField>(); generatorConfiguration.ModuleAssemblies.Push(module); foreach (var childObject in parentObject.GetFormFields(generatorConfiguration.PartsAliasResolver)) { if (childObject is IAttribute) { formFields.Add(new FormField((IAttribute)childObject, generatorConfiguration)); } else { } } $basename$PageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, module, formFields); return(true); }
public static void GenerateModule(IBase baseObject, AngularModule angularModule, string moduleFolderPath, string moduleName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports) { var host = new TemplateEngineHost(); Dictionary <string, object> sessionVariables; FileInfo fileInfo; string fileLocation; string filePath; string output; try { // Module class sessionVariables = new Dictionary <string, object>(); sessionVariables.Add("ModuleName", angularModule.Name); sessionVariables.Add("AngularModule", angularModule); sessionVariables.Add("Imports", imports); fileLocation = moduleFolderPath; filePath = PathCombine(fileLocation, moduleName.ToLower() + ".module.ts"); fileInfo = new FileInfo(filePath); output = host.Generate <RootModuleClassTemplate>(sessionVariables, false); sessionVariables.Add("Output", output); generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule); } catch (Exception e) { generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString()); } }
public static IEnumerable <Route> CreateRoutesTo(this AngularModule module, AngularModule routeToModule) { var routes = new List <Route>(); var path = Path.GetFileNameWithoutExtension(routeToModule.ForChildFile.FullName); Route route; string code; if (routeToModule.UILoadKind == UILoadKind.RootPage) { route = new Route { Path = string.Empty, RedirectTo = path, PathMatch = "full" }; code = route.Code; routes.Add(route); } route = new Route { Path = path, LoadChildren = new LoadChildren(module, routeToModule) }; code = route.Code; routes.Add(route); return(routes); }
public static void GenerateModule(IBase baseObject, AngularModule angularModule, string moduleFolderPath, string moduleName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports) { var host = new TemplateEngineHost(); Dictionary <string, object> sessionVariables; FileInfo fileInfo; string fileLocation; string filePath; string output; try { // Module class sessionVariables = new Dictionary <string, object>(); sessionVariables.Add("ModuleName", angularModule.Name); sessionVariables.Add("AngularModule", angularModule); sessionVariables.Add("AppName", generatorConfiguration.AppName); sessionVariables.Add("Imports", imports); fileLocation = moduleFolderPath; filePath = PathCombine(fileLocation, "app.module.ts"); fileInfo = new FileInfo(filePath); if (!generatorConfiguration.NoFileCreation) { output = host.Generate <AppModuleClassTemplate>(sessionVariables, false); } else { output = host.Generate <BlankAppModuleClassTemplate>(sessionVariables, false); } generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule); // Routing module class sessionVariables = new Dictionary <string, object>(); angularModule.AddImportsAndRoutes(imports); sessionVariables.Add("ModuleName", angularModule.RoutingName); sessionVariables.Add("IsRoot", angularModule.UILoadKind == DataAnnotations.UILoadKind.RootPage); sessionVariables.Add("Routes", angularModule.Routes); fileLocation = moduleFolderPath; filePath = PathCombine(fileLocation, "app-routing.module.ts"); fileInfo = new FileInfo(filePath); output = host.Generate <RoutingModuleClassTemplate>(sessionVariables, false); generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule); } catch (Exception e) { generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString()); } }
public static void AddImportsAndRoutes(this AngularModule module, IEnumerable <ModuleImportDeclaration> imports) { foreach (var import in imports.Select(i => i.ModuleOrAssembly).OfType <AngularModule>()) { module.Routes.AddRange(module.CreateRoutesTo(import)); module.Imports.Add(import); } }
public void CreateAngularModule(AngularModule module) { var template = _ModuleTemplate.Clone().ToString() .Replace("$moduleProviders$", string.Join(",\r\n ", module.EntitySets.Select(a => a.Name))) .Replace("$moduleName$", module.Name); DoRender(module, template); }
public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var projectRootPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.AppProjectRoot]; var appPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.App]; var module = generatorConfiguration.PushModuleAssembly <AngularModule>("App"); var folder = (Folder)generatorConfiguration.FileSystem[appPath]; generatorConfiguration.AddPackageInstalls(this); module.BaseObject = baseObject.Parent; appModule = (AngularModule)module; generatorConfiguration.SetModuleAssemblyFolder(folder); EmbeddedFilesGenerator.Generate(projectRootPath, generatorConfiguration); return(true); }
public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder); var module = new AngularModule(name + "Module"); var inputObjects = new List <object>(); // TODO - change, preferably to a typed List, to match your needs generatorConfiguration.ModuleAssemblies.Push(module); foreach (var childObject in parentObject.GetFollowingChildren(generatorConfiguration.PartsAliasResolver)) { // TODO - add code to capture children elements inputObjects.Add(new object()); } $basename$PageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, module /* , .. TODO - add additional parameters */); return(true); }
public static void GenerateProvider(IBase baseObject, string providersFolderPath, string providerName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports, AngularModule angularModule, List <object> inputObjects) { var host = new TemplateEngineHost(); var pass = generatorConfiguration.CurrentPass; var exports = new List <ESModule>(); var declarations = new List <IDeclarable>(); Dictionary <string, object> sessionVariables; FolderStructure.File file; string fileLocation; string filePath; string output; try { // $basename$ provider sessionVariables = new Dictionary <string, object>(); // TODO - change to match above sessionVariables.Add("Input", inputObjects); sessionVariables.Add("Imports", imports); sessionVariables.Add("Exports", exports); sessionVariables.Add("Declarations", declarations); sessionVariables.Add("ProviderName", providerName); sessionVariables.Add("EntityName", baseObject.Name); fileLocation = PathCombine(providersFolderPath, providerName); filePath = PathCombine(fileLocation, providerName + ".ts"); output = host.Generate <$basename$ClassTemplate> (sessionVariables, false); foreach (var export in exports) { angularModule.AddExport(baseObject, export); } angularModule.Declarations.AddRange(declarations); if (pass == GeneratorPass.Files) { if (File.Exists(filePath)) { File.Delete(filePath); } if (!Directory.Exists(fileLocation)) { Directory.CreateDirectory(fileLocation); } using (FileStream fileStream = File.Create(filePath)) { fileStream.Write(output); generatorConfiguration.FileSystem.DeleteFile(filePath); file = generatorConfiguration.FileSystem.AddSystemLocalFile(new FileInfo(filePath)); file.Folder.AddAssembly(angularModule); } } else if (pass == GeneratorPass.HierarchyOnly) { file = generatorConfiguration.FileSystem.AddSystemLocalFile(new FileInfo(filePath), generatorConfiguration.GenerateInfo(sessionVariables, "$basename$ Provider Class")); file.Folder.AddAssembly(angularModule); } } catch (Exception e) { generatorConfiguration.Engine.WriteError(e.ToString()); } }
public LoadChildren(AngularModule module, AngularModule routedToModule) { this.RoutedToModule = routedToModule; this.Module = module; }
public static List <Module> GetModules(string contents, string fileName) { var currentAst = new TypeScriptAST(); var modules = new List <Module>(); currentAst.MakeAST(contents, fileName); foreach (var functionDeclaration in currentAst.RootNode.Children.OfType <FunctionDeclaration>().Where(f => f.Modifiers != null && f.Modifiers.Any(m => m.Kind == SyntaxKind.ExportKeyword))) { var module = new ExportedFunction(functionDeclaration.IdentifierStr); modules.Add(module); } foreach (var classDeclaration in currentAst.GetDescendants().OfType <ClassDeclaration>()) { Module module = null; if (classDeclaration.Decorators != null) { foreach (var decorator in classDeclaration.Decorators) { if (decorator.Expression is CallExpression) { var callExpression = (CallExpression)decorator.Expression; switch (callExpression.IdentifierStr) { case "NgModule": { module = new AngularModule(classDeclaration.IdentifierStr); modules.Add(module); } break; case "Component": { module = new Page(classDeclaration.IdentifierStr); modules.Add(module); } break; case "Pipe": { module = new Pipe(classDeclaration.IdentifierStr); modules.Add(module); } break; case "Directive": { module = new Directive(classDeclaration.IdentifierStr); modules.Add(module); } break; case "Injectable": { module = new Provider(classDeclaration.IdentifierStr); modules.Add(module); } break; default: { DebugUtils.Break(); break; } } } else { DebugUtils.Break(); } } } if (module == null) { module = new ESModule(classDeclaration.IdentifierStr); modules.Add(module); } } return(modules); }