Пример #1
0
        public string OutputFile(string fileName, bool overwrite = false)
        {
            if (Skip)
            {
                return(null);
            }

            if (fileName.Contains("{{"))
            {
                // trick handlebars on Windows file names
                var escapeAvailable = false;
                if (fileName.Contains("\\"))
                {
                    escapeAvailable = true;
                    fileName        = fileName.Replace("\\", "/");
                }

                fileName = FluentHandlebars.Create(this)
                           .HavingModel(_model)
                           .UsingTemplate(fileName)
                           .OutputString();

                if (escapeAvailable)
                {
                    fileName = fileName.Replace("/", "\\");
                }
            }

            var result = OutputString();

            if (!overwrite && File.Exists(fileName))
            {
                Log.Warning($"Skipping {fileName} - File already exists");
                return(fileName);
            }

            try
            {
                fileName.EnsureFolderExists();
                File.WriteAllText(fileName, result, System.Text.Encoding.UTF8);
                return(fileName);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw;
            }
        }
Пример #2
0
 public static FluentHandlebars Create(object caller)
 {
     return(_fluentInstance = new FluentHandlebars(caller));
 }