/// <summary> /// Go through all the dependencies and for each of the soy files, we need to compile it and save the path to the /// result. We send the list of the soy dependencies out as well as a complete list of all the exisitng JS /// dependencies with the newly generated JS files. /// </summary> /// <param name="dependencies">a list of all the dependencies</param> /// <param name="list">a new list of all the javascript files with the soy files replaced with the js counterpart</param> /// <returns>a list of all the newly created soy js source files</returns> private IEnumerable<string> CreateSoyJsFromDependencies(IEnumerable<string> dependencies, out List<string> list) { list = new List<string>(); List<string> soyDependencies = new List<string>(); ClosureTemplateRunner soyRunner = new ClosureTemplateRunner(this.Settings, this.Project); foreach (string dependency in dependencies) { // if this dependency is a soy, then we need to compile it and add the new temp file to the list. if (dependency.EndsWith(".soy")) { string soyJsSrcFile; string outputString; string errorString; // run compile soyRunner.Compile(dependency, out soyJsSrcFile, out outputString, out errorString); list.Add(soyJsSrcFile); soyDependencies.Add(soyJsSrcFile); } else if (dependency.Contains("/$$/$$")) { if (dependency.Equals(DependencyBuilder.BuiltInPathForSoyJsUseGoog, StringComparison.InvariantCultureIgnoreCase)) { string tempPath = Path.GetTempFileName(); string resourceContents = ResourceHelper.GetTextResourceById(InputHandler.SoyUtilsUseGoogResourceId); File.WriteAllText(tempPath, resourceContents); list.Add(tempPath); soyDependencies.Add(tempPath); } else if (dependency.Equals(DependencyBuilder.BuiltInPathForSoyUtilsJs, StringComparison.InvariantCultureIgnoreCase)) { string tempPath = Path.GetTempFileName(); string resourceContents = ResourceHelper.GetTextResourceById(InputHandler.SoyUtilsJsResourceId); File.WriteAllText(tempPath, resourceContents); list.Add(tempPath); soyDependencies.Add(tempPath); } } else { list.Add(dependency); } } return soyDependencies; }
/// <summary> /// When we run, we need to parse the URL for the specific file that's being requested. If the file that's being requested /// ends with a ".soy", then we pass it on to the SoyToJsSrcCompiler jar and show the results from that instead. Otherwise, /// it streams a file from the file system. /// </summary> public override void Run() { string relFilePath = GetFilePathFromUri(CurrentProject.Id); if (relFilePath.Equals(DependencyBuilder.BuiltInPathForGoogBaseJs, StringComparison.InvariantCultureIgnoreCase)) { string baseJs = Helpers.ResourceHelper.GetTextResourceById(InputHandler.GoogBaseJsResourceId); this.ShowJavaScriptResponse(baseJs); } else if( relFilePath.Equals(DependencyBuilder.BuiltInPathForSoyJsUseGoog, StringComparison.InvariantCultureIgnoreCase)) { string baseJs = Helpers.ResourceHelper.GetTextResourceById(InputHandler.SoyUtilsUseGoogResourceId); this.ShowJavaScriptResponse(baseJs); } else if (relFilePath.Equals(DependencyBuilder.BuiltInPathForSoyUtilsJs, StringComparison.InvariantCultureIgnoreCase)) { string baseJs = Helpers.ResourceHelper.GetTextResourceById(InputHandler.SoyUtilsJsResourceId); this.ShowJavaScriptResponse(baseJs); } foreach (string basePath in CurrentProject.Paths) { string fullFilePath = basePath + relFilePath; if (File.Exists(fullFilePath)) { if (fullFilePath.EndsWith(".soy")) { string plovrSoyContents; string output; string errorOutput; var closureTemplateRunner = new ClosureTemplateRunner(this.CurrentSettings, this.CurrentProject); closureTemplateRunner.GetCompile(fullFilePath, out plovrSoyContents, out output, out errorOutput); this.ShowJavaScriptResponse(plovrSoyContents); } else { this.ShowJavaScriptFileResponse(fullFilePath); } } } }