Class: Yard::Yaml::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/yaml/converter.rb

Overview

Thin wrapper around the yaml-converter gem with safe defaults.

Phase 2 scope:

  • Provide class methods to convert from a YAML string or a file path.
  • Apply safe defaults and respect config toggles (strict, allow_erb, front_matter).
  • Delegate conversion to an underlying backend (default: ::Yaml::Converter if available).
  • Return a normalized result Hash: { html:, title:, description:, meta: }.

Note: We intentionally keep the contract minimal and stable. Tests stub the backend.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backendObject

Backend accessor with auto-discovery.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yard/yaml/converter.rb', line 43

def backend
  return @backend if defined?(@backend) && @backend
  begin
    require "yaml/converter"
  rescue LoadError
    # ignore; backend may be set by tests
  end
  @backend = if defined?(::Yaml) && ::Yaml.const_defined?(:Converter)
    ::Yaml::Converter
  end
end

Class Method Details

.from_file(path, options = {}, config: Yard::Yaml.config) ⇒ Hash

Convert a YAML file from disk.

Parameters:

  • path (String)
  • options (Hash) (defaults to: {})
  • config (Yard::Yaml::Config) (defaults to: Yard::Yaml.config)

Returns:

  • (Hash)


36
37
38
39
40
# File 'lib/yard/yaml/converter.rb', line 36

def from_file(path, options = {}, config: Yard::Yaml.config)
  content = read_file(path)
  return empty_result if content.nil?
  run_convert(content, options.merge(source_path: path.to_s), config)
end

.from_string(yaml, options = {}, config: Yard::Yaml.config) ⇒ Hash

Convert a YAML string into an HTML result.

Parameters:

  • yaml (String)
  • options (Hash) (defaults to: {})

    additional options passed to backend

  • config (Yard::Yaml::Config) (defaults to: Yard::Yaml.config)

    yard-yaml config (defaults to Yard::Yaml.config)

Returns:

  • (Hash)

    { html:, title:, description:, meta: }



26
27
28
# File 'lib/yard/yaml/converter.rb', line 26

def from_string(yaml, options = {}, config: Yard::Yaml.config)
  run_convert(yaml.to_s, options, config)
end