/// <summary> /// Returns the controller script content. /// </summary> private static string GetControllerScriptContents(MvcConfig.View configView) { StringBuilder baseSB = new StringBuilder(File.ReadAllText(TemplateFilePath("Controller"))); baseSB.Replace("{0}", configView.Name); return(baseSB.ToString()); }
/// <summary> /// Creates an MVC autogen script file. /// </summary> public static void Create(string autogenPath, string workspacePath, MvcConfig.View configView) { // Generate base script string baseScriptPath = GetBaseScriptPath(autogenPath, configView.Name); File.WriteAllText(baseScriptPath, GetBaseScriptContents(configView)); // Generate view, model, controller scripts. // They must be generated ONLY if there is no existing file. CreateViewDirectory(configView); string viewScriptPath = GetViewScriptPath(workspacePath, configView.Name); string modelScriptPath = GetModelScriptPath(workspacePath, configView.Name); string controllerScriptPath = GetControllerScriptPath(workspacePath, configView.Name); if (!File.Exists(viewScriptPath)) { File.WriteAllText(viewScriptPath, GetViewScriptContents(configView)); } if (!File.Exists(modelScriptPath)) { File.WriteAllText(modelScriptPath, GetModelScriptContents(configView)); } if (!File.Exists(controllerScriptPath)) { File.WriteAllText(controllerScriptPath, GetControllerScriptContents(configView)); } }
/// <summary> /// Creates directory for the view, model, and controller scripts. /// </summary> private static void CreateViewDirectory(MvcConfig.View configView) { string viewDir = MvcWorkspace.GetWorkspacePath(string.Format(ViewDirectory, configView.Name)); if (!Directory.Exists(viewDir)) { Directory.CreateDirectory(viewDir); } }
/// <summary> /// Returns the resource path for specified config view. /// </summary> public static string GetViewPrefabPath(MvcConfig.View view, string viewName, bool fullPath = false) { string path = Path.Combine(GetResourcePath(fullPath), viewName); if (fullPath) { path += ".prefab"; } return(path); }