Class: Html2img::CLI
- Inherits:
-
Object
- Object
- Html2img::CLI
- Defined in:
- lib/html2img/cli.rb
Overview
Command line interface, installed as the html2img executable.
html2img test
html2img html card.html --width 1200 --height 630 --out card.png
html2img screenshot https://example.com --fullpage --out shot.png
html2img template invoice-image --data '{"number": 1042}'
Constant Summary collapse
- TEST_DOCUMENT =
<<~HTML.gsub(/\n\s*/, "") <!doctype html><html><body style="font-family:system-ui;display:flex;align-items:center; justify-content:center;height:180px;margin:0;background:#0f172a;color:#fff"> <h1>html2img is configured</h1></body></html> HTML
- COMMANDS =
%w[test html screenshot template].freeze
- RENDER_KEYS =
%i[css width height dpi ms_delay wait_for_selector webhook_url fullpage format].freeze
Class Method Summary collapse
-
.run(argv, out: $stdout, err: $stderr) ⇒ Integer
A process exit code.
Instance Method Summary collapse
-
#initialize(out: $stdout, err: $stderr) ⇒ CLI
constructor
A new instance of CLI.
-
#run(argv) ⇒ Integer
A process exit code.
Constructor Details
#initialize(out: $stdout, err: $stderr) ⇒ CLI
Returns a new instance of CLI.
32 33 34 35 36 |
# File 'lib/html2img/cli.rb', line 32 def initialize(out: $stdout, err: $stderr) @out = out @err = err @options = {} end |
Class Method Details
.run(argv, out: $stdout, err: $stderr) ⇒ Integer
Returns a process exit code.
28 29 30 |
# File 'lib/html2img/cli.rb', line 28 def self.run(argv, out: $stdout, err: $stderr) new(out: out, err: err).run(argv) end |
Instance Method Details
#run(argv) ⇒ Integer
Returns a process exit code.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/html2img/cli.rb', line 39 def run(argv) argv = argv.dup parser = build_parser parser.order!(argv) command = argv.shift return version if @options[:version] return usage(parser) if @options[:help] || command.nil? return unknown(command) unless COMMANDS.include?(command) parser.parse!(argv) execute(command, argv) rescue OptionParser::ParseError => e fail_with(e.) end |