class Asciidoctor::AbstractNode
def read_contents target, opts = {}
--
Returns the contents of the resolved target or nil if the resolved target cannot be read
* :warn_if_empty a Boolean that indicates whether a warning is issued if contents of target is empty (default: false)
* :warn_on_failure a Boolean that indicates whether warnings are issued if the target cannot be read (default: true)
* :start the String relative base path to use when resolving the target (default: nil)
* :normalize a Boolean that indicates whether the data should be normalized (default: false)
* :label the String label of the target to use in warning messages (default: 'asset')
opts - a Hash of options to control processing (default: {})
target - The URI or local path from which to read the data.
file system. If the normalize option is set, the data will be normalized.
attribute is also set. If the resolved path is not a URI, read the contents of the file from the
contents from the URI if the allow-uri-read attribute is set, enabling caching if the cache-uri
The URI or system path of the target is first resolved. If the resolved path is a URI, read the
Public: Resolve the URI or system path to the specified target, then read and return its contents
def read_contents target, opts = {} doc = @document if (Helpers.uriish? target) || ((start = opts[:start]) && (Helpers.uriish? start) && (target = doc.path_resolver.web_path target, start)) if doc.attr? 'allow-uri-read' Helpers.require_library 'open-uri/cached', 'open-uri-cached' if doc.attr? 'cache-uri' begin if opts[:normalize] contents = (Helpers.prepare_source_string ::OpenURI.open_uri(target, URI_READ_MODE) {|f| f.read }).join LF else contents = ::OpenURI.open_uri(target, URI_READ_MODE) {|f| f.read } end rescue logger.warn %(could not retrieve contents of #{opts[:label] || 'asset'} at URI: #{target}) if opts.fetch :warn_on_failure, true end elsif opts.fetch :warn_on_failure, true logger.warn %(cannot retrieve contents of #{opts[:label] || 'asset'} at URI: #{target} (allow-uri-read attribute not enabled)) end else target = normalize_system_path target, opts[:start], nil, target_name: (opts[:label] || 'asset') contents = read_asset target, normalize: opts[:normalize], warn_on_failure: (opts.fetch :warn_on_failure, true), label: opts[:label] end logger.warn %(contents of #{opts[:label] || 'asset'} is empty: #{target}) if contents && opts[:warn_if_empty] && contents.empty? contents end