public BuildCommand(BuildCommandOptions options) { Config = ParseOptions(options); if (Config.Templates == null || Config.Templates.Count == 0) { Config.Templates = new ListWithStringFallback { DocAsCode.Constants.DefaultTemplateName }; } var assembly = typeof(Program).Assembly; _templateManager = new TemplateManager(assembly, "Template", Config.Templates, Config.Themes, Config.BaseDirectory); }
private void ExecExportTemplate() { var outputFolder = string.IsNullOrEmpty(_exportTemplateConfig.OutputFolder) ? DefaultOutputFolder : _exportTemplateConfig.OutputFolder; if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder); List<string> templates = (_exportTemplateConfig.All ? ExistingTemplates : _exportTemplateConfig.Templates).ToList(); foreach (var template in templates) { Logger.LogInfo($"Exporting {template} to {outputFolder}"); var manager = new TemplateManager(this.GetType().Assembly, "Template", new List<string> { template }, null, null); if (manager.TryExportTemplateFiles(Path.Combine(outputFolder, template))) { Logger.LogInfo($"{template} is exported to {outputFolder}"); } else { Logger.LogWarning($"{template} is not an embeded template."); } } }
private ParseResult InternalExec(BuildJsonConfig config, RunningContext context) { var parameters = ConfigToParameter(config); if (parameters.Files.Count == 0) return new ParseResult(ResultLevel.Warning, "No files found, nothing is to be generated"); try { _builder.Build(parameters); } catch (AggregateDocumentException aggEx) { return new ParseResult(ResultLevel.Warning, "following document error:" + Environment.NewLine + string.Join(Environment.NewLine, from ex in aggEx.InnerExceptions select ex.Message)); } catch (DocumentException ex) { return new ParseResult(ResultLevel.Warning, "document error:" + ex.Message); } var documentContext = DocumentBuildContext.DeserializeFrom(parameters.OutputBaseDir); var assembly = typeof(Program).Assembly; if (config.Templates == null || config.Templates.Count == 0) { config.Templates = new ListWithStringFallback { Constants.DefaultTemplateName }; } // If RootOutput folder is specified from command line, use it instead of the base directory var outputFolder = Path.Combine(config.OutputFolder ?? config.BaseDirectory ?? string.Empty, config.Destination ?? string.Empty); using (var manager = new TemplateManager(assembly, "Template", config.Templates, config.Themes, config.BaseDirectory)) { manager.ProcessTemplateAndTheme(documentContext, outputFolder, true); } // TODO: SEARCH DATA if (config.Serve) { ServeCommand.Serve(outputFolder, config.Port); } return ParseResult.SuccessResult; }
public static void BuildDocument(BuildJsonConfig config, string baseDirectory, string outputDirectory, string pluginDirectory) { try { var templateManager = new TemplateManager(typeof(DocumentBuilderWrapper).Assembly, "Template", config.Templates, config.Themes, config.BaseDirectory); using (var builder = new DocumentBuilder(LoadPluginAssemblies(pluginDirectory))) { var parameters = ConfigToParameter(config, baseDirectory, outputDirectory); if (parameters.Files.Count == 0) { Logger.LogWarning("No files found, nothing is to be generated"); return; } using (var processor = templateManager.GetTemplateProcessor()) { parameters.TemplateCollection = processor.Templates; processor.ProcessDependencies(parameters.OutputBaseDir); builder.Build(parameters); } } } catch (DocumentException ex) { Logger.LogWarning("Document error occurs:" + ex.Message); } catch (Exception ex) { Logger.LogError(ex.ToString()); } }