Class: Jekyll::AgentMarkdown::DocumentHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/agent_markdown/document_header.rb

Constant Summary collapse

URL_REQUIRED_MESSAGE =
"url is required for agent_markdown document headers; it must be an absolute HTTP(S) URL " \
"without credentials, a query, or a fragment"

Instance Method Summary collapse

Constructor Details

#initialize(site, relative_url) ⇒ DocumentHeader

Returns a new instance of DocumentHeader.



13
14
15
16
# File 'lib/jekyll/agent_markdown/document_header.rb', line 13

def initialize(site, relative_url)
  @site = site
  @relative_url = relative_url
end

Instance Method Details

#html_url(document) ⇒ Object



26
27
28
29
# File 'lib/jekyll/agent_markdown/document_header.rb', line 26

def html_url(document)
  validate_site_url!(document)
  "#{site.config["url"].to_s.sub(%r{/+\z}, "")}#{relative_url.call(document.url)}"
end

#prepend_to(document, body) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/jekyll/agent_markdown/document_header.rb', line 18

def prepend_to(document, body)
  entries = ["# #{title(document)}"]
  description = one_line(document.data["description"])
  entries << description if description
  entries << "Source: #{html_url(document)}"
  "#{entries.join("\n\n")}\n\n---\n\n#{body}"
end