Class: Bidi2pdf::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/bidi2pdf/cli.rb

Overview

rubocop:disable Metrics/AbcSize

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/bidi2pdf/cli.rb', line 81

def exit_on_failure?
  true
end

Instance Method Details

#renderObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bidi2pdf/cli.rb', line 86

def render
  load_config

  validate_required_options!

  configure

  Bidi2pdf.logger.info "Rendering: #{merged_options[:url]} -> #{merged_options[:output]}"
  Bidi2pdf.logger.info "Print options: #{print_options.inspect}" if print_options

  validate_print_options(print_options) if print_options

  launcher.launch
ensure
  launcher.stop if defined?(@launcher) && @launcher
end

#templateObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bidi2pdf/cli.rb', line 112

def template
  config = {
    "url" => "https://example.com",
    "output" => "output.pdf",
    "headless" => true,
    "print_options" => {
      "background" => true,
      "orientation" => "portrait",
      "margin" => {
        "top" => 1.0,
        "bottom" => 1.0,
        "left" => 1.0,
        "right" => 1.0
      }
    }
  }

  File.write(merged_options[:output], config.to_yaml)
  puts "Config template written to #{merged_options[:output]}"
end

#versionObject



105
106
107
# File 'lib/bidi2pdf/cli.rb', line 105

def version
  puts "bidi2pdf #{Bidi2pdf::VERSION}"
end