Module: Yard::Yaml::TemplateHelpers
- Defined in:
- lib/yard/yaml/template_helpers.rb
Overview
View/template helpers for rendering YAML blocks and files.
Phase 5 scope:
- Provide simple helpers independent of YARD templates so they are unit-testable.
- Use Converter with current config and safe defaults.
- For files: resolve relative paths against a provided base_dir (default: Dir.pwd).
Class Method Summary collapse
-
.render_yaml_block(text, config: Yard::Yaml.config) ⇒ String
Render inline YAML text to HTML via Converter.
-
.render_yaml_file(path, base_dir: Dir.pwd, config: Yard::Yaml.config) ⇒ String
Render a YAML file to HTML via Converter.
Class Method Details
.render_yaml_block(text, config: Yard::Yaml.config) ⇒ String
Render inline YAML text to HTML via Converter.
19 20 21 22 |
# File 'lib/yard/yaml/template_helpers.rb', line 19 def render_yaml_block(text, config: Yard::Yaml.config) res = Yard::Yaml::Converter.from_string(text.to_s, {}, config: config) res[:html].to_s end |
.render_yaml_file(path, base_dir: Dir.pwd, config: Yard::Yaml.config) ⇒ String
Render a YAML file to HTML via Converter.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yard/yaml/template_helpers.rb', line 30 def render_yaml_file(path, base_dir: Dir.pwd, config: Yard::Yaml.config) resolved = resolve_path(path, base_dir) res = Yard::Yaml::Converter.from_file(resolved, {}, config: config) res[:html].to_s rescue Yard::Yaml::Error # strict mode errors bubble from converter; re-raise raise rescue StandardError => e # Non-strict paths should already be handled by converter; this is a last-resort guard. if defined?(::Yard) && ::Yard.const_defined?(:Yaml) ::Yard::Yaml.warn("#{e.class}: #{e.} while rendering #{path}") else Kernel.warn("yard-yaml: #{e.class}: #{e.} while rendering #{path}") end "" end |