Class: Docwatch::Parser::Frontmatter
- Inherits:
-
Docwatch::Parser
- Object
- Docwatch::Parser
- Docwatch::Parser::Frontmatter
- Defined in:
- lib/docwatch/parser/frontmatter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(yaml) ⇒ Frontmatter
constructor
rubocop:disable Lint/MissingSuper.
- #to_html ⇒ Object
Constructor Details
#initialize(yaml) ⇒ Frontmatter
rubocop:disable Lint/MissingSuper
29 30 31 |
# File 'lib/docwatch/parser/frontmatter.rb', line 29 def initialize(yaml) # rubocop:disable Lint/MissingSuper @data = YAML.safe_load(yaml) end |
Class Method Details
.split(str) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/docwatch/parser/frontmatter.rb', line 3 def self.split(str) lines = str.lines if lines.first.chomp != '---' return [nil, str] end in_frontmatter = false in_document = false document = '' frontmatter_yaml = '' lines.each do |line| if line.strip == '---' && !in_document in_frontmatter = !in_frontmatter in_document = true if !in_frontmatter elsif in_frontmatter frontmatter_yaml += line elsif in_document document += line end end [Frontmatter.new(frontmatter_yaml), document] end |
Instance Method Details
#to_html ⇒ Object
33 34 35 |
# File 'lib/docwatch/parser/frontmatter.rb', line 33 def to_html Util::HTML.render(@data) end |