PM::Parsed¶
The result object returned by PM.parse and PM.parse_string. An immutable Data with two fields: metadata and content.
Source¶
lib/pm/parsed.rb (rendering lives in lib/pm/renderer.rb and lib/pm/render_scope.rb)
Structure¶
Fields¶
| Field | Type | Description |
|---|---|---|
metadata |
PM::Metadata | Parsed YAML front matter plus shell/erb flags and any file-derived keys |
content |
String | Content after comment stripping, metadata extraction, and shell expansion |
Parsed itself is immutable, but metadata is a mutable object: to_s writes the
includes tree into it.
Methods¶
[](key) → Object¶
Bracket accessor that delegates to metadata:
parsed = PM.parse("---\ntitle: Hello\n---\nContent")
parsed[:title] #=> "Hello"
parsed['title'] #=> "Hello"
key?(key) → Boolean¶
Whether the metadata has the key.
parameters → Hash¶
The parameters mapping from the front matter, or {} when absent.
to_s(values = {}) → String¶
Render the prompt content with ERB template evaluation.
Parameters:
| Name | Type | Description |
|---|---|---|
values |
Hash | Parameter values to merge with defaults (String or Symbol keys) |
Returns: Rendered prompt as String.
Raises: PM::MissingParameterError (an ArgumentError) if required parameters (those with nil defaults) are not provided; PM::UnknownParameterError in strict mode for an unknown name; NoMethodError for an unknown name called with arguments when strict mode is off; the include and shell errors from any directive that runs.
Behavior:
- Resets
metadata.includesto[] - If
erb: false, returns content as-is - Merges provided values with parameter defaults from metadata
- Validates all required parameters are present
- Evaluates ERB with parameters and registered directives in scope
- Fills
metadata.includeswith the include tree
parsed = PM.parse('review.md')
# With required params
result = parsed.to_s('code' => File.read('app.rb'))
# Override defaults
result = parsed.to_s('code' => source, 'language' => 'python')
# Symbol keys work
result = parsed.to_s(code: source)
to_h → Hash¶
The metadata Hash has Symbol keys.
to_markdown → String¶
The prompt as a markdown file again: YAML front matter followed by the content.
PM.parse_string("---\ntitle: T\nparameters:\n a: 1\n---\nBody <%= a %>").to_markdown
#=> "---\ntitle: T\nparameters:\n a: 1\nshell: true\nerb: true\n---\nBody <%= a %>"
- Keys PM derived from the file system (
directory,name,created_at,modified_at) and theincludestree are omitted, so the result re-parses cleanly. shellanderbare always written, because their values were resolved against the global configuration at parse time.- The content is the parsed content: shell references have already been expanded. ERB is untouched.
render_with(values, included, depth) → String¶
Rendering entry point used by the include directive, which must pass the active
include chain and depth through.
| Name | Type | Description |
|---|---|---|
values |
Hash | Merged parameter values |
included |
Set | Paths of the ancestor files in the include chain |
depth |
Integer | Current include nesting depth |
Not typically called directly.