Class: Html2Pdf::CLI
- Inherits:
-
Thor
- Object
- Thor
- Html2Pdf::CLI
- Defined in:
- lib/html2pdf/cli.rb
Instance Method Summary collapse
Instance Method Details
#export ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/html2pdf/cli.rb', line 14 def export opts = .symbolize_keys unless Html2Pdf.softwares_installed? fail "You must have valid `wkhtmltopdf` installation" end if opts[:version] puts "You are using Html2Pdf version #{Html2Pdf::VERSION}" exit end # Always expand path so that the '.' or '~' will work if specified base_dir = File.(opts[:base_dir]) input_files = CodeLister.files base_dir: base_dir, exts: %w[html xhtml], recursive: opts[:recursive] elapsed = AgileUtils::FileUtil.time do # Change the directory to the base diretory as the input_files is always # start with '.' relative to the base_dir FileUtils.cd(base_dir) Html2Pdf.to_pdfs(input_files) end generated_files = add_suffix(input_files, "pdf") output_file = "html2pdf_#{File.basename(File.(base_dir))}.tar.gz" AgileUtils::FileUtil.tar_gzip_files(generated_files, output_file) AgileUtils::FileUtil.delete(generated_files) puts "Convert files to pdfs took #{elapsed} ms" puts "Your final output is '#{File.absolute_path(output_file)}'" end |
#usage ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/html2pdf/cli.rb', line 47 def usage puts <<-EOT Usage: html2pdf Options: -b, [--base-dir=BASE_DIR] # Base directory # Default: . (current directory) -r, [--recursive], [--no-recursive] # Search for files recursively # Default: --recursive -v, [--version], [--no-version] # Display version information export multiple html files to pdfs EOT end |