Class: Stic::Metadata::Yaml
Overview
The YAML front matter is parses YAML meta data embraced in three dashes from the beginning of a file.
Constant Summary
collapse
- DASHED_YAML_REGEXP =
/\A(?<data>---?\s*\n.*?\n?)^(---\s*$\n?)(?<content>.*)\z/m
Instance Method Summary
collapse
Instance Method Details
#match(blob, str) ⇒ Object
33
34
35
|
# File 'lib/stic/metadata/yaml.rb', line 33
def match(blob, str)
regexp.match(str)
end
|
#parse(blob, str) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/stic/metadata/yaml.rb', line 37
def parse(blob, str)
if (match = match(blob, str))
begin
[
::YAML.load(preprocess_data(blob, match[:data])),
preprocess_content(blob, match[:content])
]
rescue Psych::SyntaxError => err
raise Stic::InvalidMetadata.new blob: blob
end
end
end
|
#preprocess_content(blob, content) ⇒ Object
29
30
31
|
# File 'lib/stic/metadata/yaml.rb', line 29
def preprocess_content(blob, content)
content
end
|
#preprocess_data(blob, data) ⇒ Object
25
26
27
|
# File 'lib/stic/metadata/yaml.rb', line 25
def preprocess_data(blob, data)
data
end
|
#regexp ⇒ Object
Return Regexp to match YAML frontmatter and content. Must provide two named match groups named ‘data` and `content`.