Class: Grover
- Defined in:
- lib/grover.rb,
lib/grover/utils.rb,
lib/grover/version.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 Classes: Configuration, Middleware, OptionsBuilder, OptionsFixer, 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
- VERSION =
'0.11.3'
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(url, options = {}) ⇒ Grover
constructor
A new instance of Grover.
-
#inspect ⇒ Object
Instance inspection.
-
#screenshot(path: nil, format: nil) ⇒ String
Request URL 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_jpeg(path = nil) ⇒ String
Request URL with provided options and create JPEG.
-
#to_pdf(path = nil) ⇒ String
Request URL with provided options and create PDF.
-
#to_png(path = nil) ⇒ String
Request URL with provided options and create PNG.
Constructor Details
#initialize(url, options = {}) ⇒ Grover
Returns a new instance of Grover.
153 154 155 156 157 158 159 |
# File 'lib/grover.rb', line 153 def initialize(url, = {}) @url = url @options = OptionsBuilder.new(, url) @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.
146 147 148 |
# File 'lib/grover.rb', line 146 def back_cover_path @back_cover_path end |
#front_cover_path ⇒ Object (readonly)
Returns the value of attribute front_cover_path.
146 147 148 |
# File 'lib/grover.rb', line 146 def front_cover_path @front_cover_path end |
Class Method Details
.configuration ⇒ Object
Configuration for the conversion
243 244 245 |
# File 'lib/grover.rb', line 243 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
247 248 249 |
# File 'lib/grover.rb', line 247 def self.configure yield(configuration) end |
Instance Method Details
#inspect ⇒ Object
Instance inspection
231 232 233 234 235 236 237 238 |
# File 'lib/grover.rb', line 231 def inspect format( '#<%<class_name>s:0x%<object_id>p @url="%<url>s">', class_name: self.class.name, object_id: object_id, url: @url ) end |
#screenshot(path: nil, format: nil) ⇒ String
Request URL with provided options and create screenshot
181 182 183 184 185 186 187 188 |
# File 'lib/grover.rb', line 181 def screenshot(path: nil, format: nil) = (path: path) ['type'] = format if format.is_a? ::String result = processor.convert_screenshot @url, return unless result result['data'].pack('C*') end |
#show_back_cover? ⇒ Boolean
Returns whether a back cover (request) path has been specified in the options
224 225 226 |
# File 'lib/grover.rb', line 224 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
215 216 217 |
# File 'lib/grover.rb', line 215 def show_front_cover? front_cover_path.is_a?(::String) && front_cover_path.start_with?('/') end |
#to_jpeg(path = nil) ⇒ String
Request URL with provided options and create JPEG
206 207 208 |
# File 'lib/grover.rb', line 206 def to_jpeg(path = nil) screenshot(path: path, format: 'jpeg') end |
#to_pdf(path = nil) ⇒ String
Request URL with provided options and create PDF
167 168 169 170 171 172 |
# File 'lib/grover.rb', line 167 def to_pdf(path = nil) result = processor.convert_pdf @url, (path: path) return unless result result['data'].pack('C*') end |
#to_png(path = nil) ⇒ String
Request URL with provided options and create PNG
196 197 198 |
# File 'lib/grover.rb', line 196 def to_png(path = nil) screenshot(path: path, format: 'png') end |