Class: Grover

Inherits:
Object show all
Defined in:
lib/grover.rb,
lib/grover/utils.rb,
lib/grover/version.rb,
lib/grover/middleware.rb,
lib/grover/configuration.rb,
lib/grover/html_preprocessor.rb

Overview

Grover interface for converting HTML to PDF

Defined Under Namespace

Modules: HTMLPreprocessor Classes: Configuration, Middleware, Utils

Constant Summary collapse

DEFAULT_HEADER_TEMPLATE =
"<div class='date text left'></div><div class='title text center'></div>".freeze
Utils.strip_heredoc("  <div class='url text left grow'></div>\n  <div class='text right'><span class='pageNumber'></span>/<span class='totalPages'></span></div>\n").freeze
VERSION =
'0.6.1'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Grover



97
98
99
100
101
102
103
104
# File 'lib/grover.rb', line 97

def initialize(url, options = {})
  @url = url
  @options = combine_options options

  @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_pathObject (readonly)

Returns the value of attribute back_cover_path.



90
91
92
# File 'lib/grover.rb', line 90

def back_cover_path
  @back_cover_path
end

#front_cover_pathObject (readonly)

Returns the value of attribute front_cover_path.



90
91
92
# File 'lib/grover.rb', line 90

def front_cover_path
  @front_cover_path
end

Class Method Details

.configurationObject

Configuration for the conversion



152
153
154
# File 'lib/grover.rb', line 152

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



156
157
158
# File 'lib/grover.rb', line 156

def self.configure
  yield(configuration)
end

Instance Method Details

#inspectObject

Instance inspection



140
141
142
143
144
145
146
147
# File 'lib/grover.rb', line 140

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

#show_back_cover?Boolean

Returns whether a back cover (request) path has been specified in the options



133
134
135
# File 'lib/grover.rb', line 133

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



124
125
126
# File 'lib/grover.rb', line 124

def show_front_cover?
  front_cover_path.is_a?(::String) && front_cover_path.start_with?('/')
end

#to_pdf(path = nil) ⇒ String

Request URL with provided options and create PDF



112
113
114
115
116
117
# File 'lib/grover.rb', line 112

def to_pdf(path = nil)
  normalized_options = Utils.normalize_object @options
  normalized_options['path'] = path if path.is_a? ::String
  result = processor.convert_pdf @url, normalized_options
  result['data'].pack('c*')
end