Class: Html2Pdf::CLI
- Inherits:
-
Thor
- Object
- Thor
- Html2Pdf::CLI
- Defined in:
- lib/html2pdf/cli.rb
Instance Method Summary collapse
Instance Method Details
#export ⇒ Object
12 13 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 |
# File 'lib/html2pdf/cli.rb', line 12 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.expand_path(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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/html2pdf/cli.rb', line 45 def usage puts "Usage:\n html2pdf\n\nOptions:\n -b, [--base-dir=BASE_DIR] # Base directory\n # Default: . (current directory)\n -r, [--recursive], [--no-recursive] # Search for files recursively\n # Default: --recursive\n -v, [--version], [--no-version] # Display version information\n\nexport multiple html files to pdfs\n EOT\nend\n" |