Example #1
0
        private static PdfJsonConfig ParseOptions(PdfCommandOptions options)
        {
            var           configFile = BuildCommand.GetConfigFilePath(options);
            PdfJsonConfig config;

            if (configFile == null)
            {
                if (options.Content == null && options.Resource == null)
                {
                    throw new OptionParserException("Either provide config file or specify content files to start building documentation.");
                }

                config = new PdfJsonConfig()
                {
                    BaseDirectory = EnvironmentContext.BaseDirectory
                };
                MergeOptionsToConfig(options, config);
                return(config);
            }

            config = CommandUtility.GetConfig <PdfConfig>(configFile).Item;
            if (config == null)
            {
                throw new DocumentException($"Unable to find pdf subcommand config in file '{configFile}'.");
            }

            config.BaseDirectory = Path.GetDirectoryName(configFile);

            MergeOptionsToConfig(options, config);
            return(config);
        }
Example #2
0
        private static void MergeOptionsToConfig(PdfCommandOptions options, PdfJsonConfig config)
        {
            BuildCommand.MergeOptionsToConfig(options, config);

            if (options.ExcludedTocs?.Count > 0)
            {
                config.ExcludedTocs = new ListWithStringFallback(options.ExcludedTocs);
            }

            if (!string.IsNullOrEmpty(options.CssFilePath))
            {
                config.CssFilePath = options.CssFilePath;
            }

            if (!string.IsNullOrEmpty(options.Name))
            {
                config.Name = options.Name;
            }

            if (!string.IsNullOrEmpty(options.Host))
            {
                config.Host = options.Host;
            }

            if (!string.IsNullOrEmpty(options.Locale))
            {
                config.Locale = options.Locale;
            }

            if (!string.IsNullOrEmpty(options.BasePath))
            {
                config.BasePath = options.BasePath;
            }

            if (!string.IsNullOrEmpty(options.RawOutputFolder))
            {
                config.RawOutputFolder = options.RawOutputFolder;
            }

            if (!string.IsNullOrEmpty(options.LoadErrorHandling))
            {
                config.LoadErrorHandling = options.LoadErrorHandling;
            }

            if (options.GeneratesAppendices.HasValue)
            {
                config.GeneratesAppendices = options.GeneratesAppendices.Value;
            }

            if (options.KeepRawFiles.HasValue)
            {
                config.KeepRawFiles = options.KeepRawFiles.Value;
            }

            if (options.GeneratesExternalLink.HasValue)
            {
                config.GeneratesExternalLink = options.GeneratesExternalLink.Value;
            }
        }
Example #3
0
        public PdfCommand(PdfCommandOptions options)
        {
            _config = ParseOptions(options);
            if (_config.Serve == true)
            {
                Logger.LogWarning("--serve is not supported in pdf command, ignored");
                _config.Serve = false;
            }

            if (_config.Templates == null || _config.Templates.Count == 0)
            {
                _config.Templates = new ListWithStringFallback(new List <string> {
                    "pdf.default"
                });
            }

            _innerBuildCommand = new BuildCommand(_config);
        }
Example #4
0
        public PdfCommand(PdfCommandOptions options)
        {
            _config = ParseOptions(options);
            _wkhtmltopdfFilePath = _config.Wkhtmltopdf?.FilePath.GetFullFilePath(_config.BaseDirectory);
            ConvertWrapper.PrerequisiteCheck(_wkhtmltopdfFilePath);

            if (_config.Serve == true)
            {
                Logger.LogWarning("--serve is not supported in pdf command, ignored");
                _config.Serve = false;
            }

            if (_config.Templates == null || _config.Templates.Count == 0)
            {
                _config.Templates = new ListWithStringFallback(new List <string> {
                    "pdf.default"
                });
            }

            _innerBuildCommand = new BuildCommand(_config);
        }
Example #5
0
        private static void MergeOptionsToConfig(PdfCommandOptions options, PdfJsonConfig config)
        {
            BuildCommand.MergeOptionsToConfig(options, config);

            if (options.ExcludedTocs?.Count > 0)
            {
                config.ExcludedTocs = new ListWithStringFallback(options.ExcludedTocs);
            }

            if (!string.IsNullOrEmpty(options.CssFilePath))
            {
                config.CssFilePath = options.CssFilePath;
            }

            if (!string.IsNullOrEmpty(options.Name))
            {
                config.Name = options.Name;
            }

            if (!string.IsNullOrEmpty(options.Host))
            {
                config.Host = options.Host;
            }

            if (!string.IsNullOrEmpty(options.Locale))
            {
                config.Locale = options.Locale;
            }

            if (!string.IsNullOrEmpty(options.BasePath))
            {
                config.BasePath = options.BasePath;
            }

            if (!string.IsNullOrEmpty(options.RawOutputFolder))
            {
                config.RawOutputFolder = options.RawOutputFolder;
            }

            if (!string.IsNullOrEmpty(options.LoadErrorHandling))
            {
                config.LoadErrorHandling = options.LoadErrorHandling;
            }

            if (options.GeneratesAppendices.HasValue)
            {
                config.GeneratesAppendices = options.GeneratesAppendices.Value;
            }

            if (options.KeepRawFiles.HasValue)
            {
                config.KeepRawFiles = options.KeepRawFiles.Value;
            }

            if (options.ExcludeDefaultToc.HasValue)
            {
                config.ExcludeDefaultToc = options.ExcludeDefaultToc.Value;
            }

            if (options.GeneratesExternalLink.HasValue)
            {
                config.GeneratesExternalLink = options.GeneratesExternalLink.Value;
            }

            if (options.NoInputStreamArgs.HasValue)
            {
                config.NoInputStreamArgs = options.NoInputStreamArgs.Value;
            }

            if (!string.IsNullOrEmpty(options.FilePath))
            {
                config.Wkhtmltopdf.FilePath = options.FilePath.GetFullFilePath(Environment.CurrentDirectory);
            }
        }