Class: Grover
- Defined in:
- lib/grover.rb,
lib/grover/utils.rb,
lib/grover/errors.rb,
lib/grover/version.rb,
lib/grover/processor.rb,
lib/grover/middleware.rb,
lib/grover/configuration.rb,
lib/grover/options_fixer.rb,
lib/grover/options_builder.rb,
lib/grover/html_preprocessor.rb
Overview
Grover interface for converting HTML to PDF
Defined Under Namespace
Modules: HTMLPreprocessor, JavaScript Classes: Configuration, Middleware, OptionsBuilder, OptionsFixer, Processor, Utils
Constant Summary collapse
- DEFAULT_HEADER_TEMPLATE =
"<div class='date text left'></div><div class='title text center'></div>"
- DEFAULT_FOOTER_TEMPLATE =
<<~HTML <div class='url text left grow'></div> <div class='text right'><span class='pageNumber'></span>/<span class='totalPages'></span></div> HTML
- Error =
Error classes for calling out to Puppeteer NodeJS library
Heavily based on the Schmooze library github.com/Shopify/schmooze
Class.new(StandardError)
- DependencyError =
Class.new(Error)
- UnsafeConfigurationError =
Class.new(Error)
- VERSION =
'1.2.1'
Instance Attribute Summary collapse
-
#back_cover_path ⇒ Object
readonly
Returns the value of attribute back_cover_path.
-
#front_cover_path ⇒ Object
readonly
Returns the value of attribute front_cover_path.
Class Method Summary collapse
-
.configuration ⇒ Object
Configuration for the conversion.
- .configure {|configuration| ... } ⇒ Object
Instance Method Summary collapse
-
#initialize(uri, **options) ⇒ Grover
constructor
A new instance of Grover.
-
#inspect ⇒ Object
Instance inspection.
-
#screenshot(path: nil, format: nil) ⇒ String
Request URI with provided options and create screenshot.
-
#show_back_cover? ⇒ Boolean
Returns whether a back cover (request) path has been specified in the options.
-
#show_front_cover? ⇒ Boolean
Returns whether a front cover (request) path has been specified in the options.
-
#to_html ⇒ String
Request URI with provided options and render HTML.
-
#to_jpeg(path = nil) ⇒ String
Request URI with provided options and create JPEG.
-
#to_pdf(path = nil) ⇒ String
Request URI with provided options and create PDF.
-
#to_png(path = nil) ⇒ String
Request URI with provided options and create PNG.
Constructor Details
#initialize(uri, **options) ⇒ Grover
Returns a new instance of Grover.
36 37 38 39 40 41 42 |
# File 'lib/grover.rb', line 36 def initialize(uri, **) @uri = uri.to_s @options = OptionsBuilder.new(, @uri) @root_path = @options.delete 'root_path' @front_cover_path = @options.delete 'front_cover_path' @back_cover_path = @options.delete 'back_cover_path' end |
Instance Attribute Details
#back_cover_path ⇒ Object (readonly)
Returns the value of attribute back_cover_path.
28 29 30 |
# File 'lib/grover.rb', line 28 def back_cover_path @back_cover_path end |
#front_cover_path ⇒ Object (readonly)
Returns the value of attribute front_cover_path.
28 29 30 |
# File 'lib/grover.rb', line 28 def front_cover_path @front_cover_path end |
Class Method Details
.configuration ⇒ Object
Configuration for the conversion
129 130 131 |
# File 'lib/grover.rb', line 129 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
133 134 135 |
# File 'lib/grover.rb', line 133 def self.configure yield(configuration) end |
Instance Method Details
#inspect ⇒ Object
Instance inspection
117 118 119 120 121 122 123 124 |
# File 'lib/grover.rb', line 117 def inspect format( '#<%<class_name>s:0x%<object_id>p @uri="%<uri>s">', class_name: self.class.name, object_id: object_id, uri: @uri ) end |
#screenshot(path: nil, format: nil) ⇒ String
Request URI with provided options and create screenshot
70 71 72 73 74 |
# File 'lib/grover.rb', line 70 def screenshot(path: nil, format: nil) = (path: path) ['type'] = format if %w[png jpeg].include? format processor.convert :screenshot, @uri, end |
#show_back_cover? ⇒ Boolean
Returns whether a back cover (request) path has been specified in the options
110 111 112 |
# File 'lib/grover.rb', line 110 def show_back_cover? back_cover_path.is_a?(::String) && back_cover_path.start_with?('/') end |
#show_front_cover? ⇒ Boolean
Returns whether a front cover (request) path has been specified in the options
101 102 103 |
# File 'lib/grover.rb', line 101 def show_front_cover? front_cover_path.is_a?(::String) && front_cover_path.start_with?('/') end |
#to_html ⇒ String
Request URI with provided options and render HTML
59 60 61 |
# File 'lib/grover.rb', line 59 def to_html processor.convert :content, @uri, (path: nil) end |
#to_jpeg(path = nil) ⇒ String
Request URI with provided options and create JPEG
92 93 94 |
# File 'lib/grover.rb', line 92 def to_jpeg(path = nil) screenshot path: path, format: 'jpeg' end |
#to_pdf(path = nil) ⇒ String
Request URI with provided options and create PDF
50 51 52 |
# File 'lib/grover.rb', line 50 def to_pdf(path = nil) processor.convert :pdf, @uri, (path: path) end |
#to_png(path = nil) ⇒ String
Request URI with provided options and create PNG
82 83 84 |
# File 'lib/grover.rb', line 82 def to_png(path = nil) screenshot path: path, format: 'png' end |