Class: Vivlio::PDF::Viewer
- Inherits:
-
Object
- Object
- Vivlio::PDF::Viewer
- Defined in:
- lib/vivlio/pdf/viewer.rb
Overview
The Vivliostyle Viewer installation used for rendering: a directory of static files containing index.html.
Defaults to the copy vendored in this gem; pass another path to run a different release without rebuilding the gem.
Constant Summary collapse
- VENDORED_PATH =
File.('../../../vendor/viewer', __dir__)
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Accepts a Viewer, a path, or nil (meaning the vendored viewer).
- .default ⇒ Object
Instance Method Summary collapse
- #index_path ⇒ Object
-
#initialize(path) ⇒ Viewer
constructor
A new instance of Viewer.
- #to_s ⇒ Object
-
#url_for(source, book_mode: true, style: nil) ⇒ Object
Viewer URL loading
source.
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/vivlio/pdf/viewer.rb', line 15 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
15 16 17 |
# File 'lib/vivlio/pdf/viewer.rb', line 15 def version @version end |
Class Method Details
.coerce(value) ⇒ Object
Accepts a Viewer, a path, or nil (meaning the vendored viewer).
22 23 24 25 26 27 28 |
# File 'lib/vivlio/pdf/viewer.rb', line 22 def self.coerce(value) case value when Viewer then value when nil then default else new(value) end end |
.default ⇒ Object
17 18 19 |
# File 'lib/vivlio/pdf/viewer.rb', line 17 def self.default @default ||= new(VENDORED_PATH) end |
Instance Method Details
#index_path ⇒ Object
37 38 39 |
# File 'lib/vivlio/pdf/viewer.rb', line 37 def index_path @index.path end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/vivlio/pdf/viewer.rb', line 61 def to_s path end |
#url_for(source, book_mode: true, style: nil) ⇒ Object
Viewer URL loading source.
Fragment parameters:
src document to load
bookMode follow the spine/TOC to load the whole publication
renderAllPages paginate everything up front (required before print)
style additional stylesheet(s)
A stylesheet the viewer cannot find is silently ignored, so the paths are resolved here and a missing one is reported instead.
51 52 53 54 55 56 57 58 59 |
# File 'lib/vivlio/pdf/viewer.rb', line 51 def url_for(source, book_mode: true, style: nil) parameters = ["src=#{Source.coerce(source).url}"] parameters << 'bookMode=true' if book_mode parameters << 'renderAllPages=true' Array(style).each do |sheet| parameters << "style=#{LocalFile.new(sheet, kind: 'stylesheet').url}" end "#{@index.url}##{parameters.join('&')}" end |