Class: Himg::CLI
- Inherits:
-
Thor
- Object
- Thor
- Himg::CLI
- Defined in:
- lib/himg/cli.rb
Defined Under Namespace
Classes: Document
Constant Summary collapse
- CLI_ONLY_OPTIONS =
[:stdin, :http_headers].freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
93 94 95 |
# File 'lib/himg/cli.rb', line 93 def self.exit_on_failure? true end |
Instance Method Details
#screenshot(first_arg = nil, second_arg = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/himg/cli.rb', line 53 def screenshot(first_arg = nil, second_arg = nil) url, destination = parse_screenshot_args(first_arg, second_arg) [:http_headers]&.transform_values!(&:strip) Document.new(url, ).load do |content| = .transform_keys(&:to_sym) .reject { |k, _| CLI_ONLY_OPTIONS.include?(k) } [:base_url] ||= base_directory_url(url) if Document.http_url?(url) png = Himg.render(content, **) File.open(destination, "wb") { |f| f.write(png) } end end |
#usage ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/himg/cli.rb', line 13 def usage puts "himg v#{VERSION}" puts puts "Converts HTML to PNG images using a lightweight, minimal renderer." puts "Ideal for generating OpenGraph images from purpose-built HTML." puts CLI.command_help(Thor::Base.shell.new, 'screenshot') end |