Class: Yard::Yaml::Converter
- Inherits:
-
Object
- Object
- Yard::Yaml::Converter
- 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
-
.backend ⇒ Object
Backend accessor with auto-discovery.
Class Method Summary collapse
-
.from_file(path, options = {}, config: Yard::Yaml.config) ⇒ Hash
Convert a YAML file from disk.
-
.from_string(yaml, options = {}, config: Yard::Yaml.config) ⇒ Hash
Convert a YAML string into an HTML result.
Class Attribute Details
.backend ⇒ Object
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.
36 37 38 39 40 |
# File 'lib/yard/yaml/converter.rb', line 36 def from_file(path, = {}, config: Yard::Yaml.config) content = read_file(path) return empty_result if content.nil? run_convert(content, .merge(source_path: path.to_s), config) end |