Class: Docbook::Services::ImageResolver
- Inherits:
-
Object
- Object
- Docbook::Services::ImageResolver
- Defined in:
- lib/docbook/services/image_resolver.rb
Overview
Resolves relative image paths to absolute URLs.
Walks a DocbookMirror JSON structure and converts image src values from relative paths to absolute URLs using the configured strategy.
Usage: resolver = ImageResolver.new( search_dirs: ["/path/to/xml", "/path/to/resources"], strategy: :file_url # or :data_url, :relative ) resolver.resolve(data)
Constant Summary collapse
- STRATEGIES =
%i[file_url data_url relative].freeze
Instance Attribute Summary collapse
-
#search_dirs ⇒ Object
readonly
Returns the value of attribute search_dirs.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#initialize(search_dirs:, strategy: :file_url, base_url: nil) ⇒ ImageResolver
constructor
A new instance of ImageResolver.
-
#resolve(data) ⇒ Object
Resolve image paths in a DocbookMirror JSON structure (mutates in place).
Constructor Details
#initialize(search_dirs:, strategy: :file_url, base_url: nil) ⇒ ImageResolver
Returns a new instance of ImageResolver.
28 29 30 31 32 |
# File 'lib/docbook/services/image_resolver.rb', line 28 def initialize(search_dirs:, strategy: :file_url, base_url: nil) @search_dirs = Array(search_dirs) @strategy = strategy @base_url = base_url end |
Instance Attribute Details
#search_dirs ⇒ Object (readonly)
Returns the value of attribute search_dirs.
20 21 22 |
# File 'lib/docbook/services/image_resolver.rb', line 20 def search_dirs @search_dirs end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
20 21 22 |
# File 'lib/docbook/services/image_resolver.rb', line 20 def strategy @strategy end |
Instance Method Details
#resolve(data) ⇒ Object
Resolve image paths in a DocbookMirror JSON structure (mutates in place).
36 37 38 |
# File 'lib/docbook/services/image_resolver.rb', line 36 def resolve(data) walk(data) end |