Yaml frontmatter (#1217)

Render YAML frontmatter

* Fix tests on 5.x

* Update README

* Refactor Page view #table

* Minor refactor

* Refactor
This commit is contained in:
Dawa Ometto
2017-04-09 19:26:04 +02:00
committed by GitHub
parent c1f94d2deb
commit 8aa10fe400
9 changed files with 70 additions and 13 deletions
+3 -1
View File
@@ -385,7 +385,9 @@ a:active, a:hover {
}
.markdown-body table tr th,
.markdown-body table tr td {
.markdown-body table tr td,
.markdown-body table tr td table,
.markdown-body table tr th table {
border: 1px solid #ccc;
text-align: none;
margin: 0;
+1
View File
@@ -69,6 +69,7 @@ Mousetrap.bind(['e'], function( e ) {
</div>
{{/has_header}}
<div class="markdown-body">
{{{rendered_metadata}}}
{{{content}}}
</div>
</div>
+32 -4
View File
@@ -130,13 +130,21 @@ module Precious
# Access to embedded metadata.
#
# Examples
#
# {{#metadata}}{{name}}{{/metadata}}
#
# Returns Hash.
def metadata
@page.metadata
end
# Access to embedded metadata.
#
# Examples
#
# {{#rendered_metadata}}{{name}}{{/rendered_metadata}}
#
# Returns HTML table.
def rendered_metadata
return '' unless page.display_metadata? && !metadata.empty?
@rendered_metadata ||= table(metadata)
end
private
@@ -184,6 +192,26 @@ module Precious
# .inner_html will cause href escaping on UTF-8
doc.css("div#gollum-root").children.to_xml(@@to_xml)
end
def table(data)
return data.to_s if data.empty?
result = "<table>\n"
keys = data.respond_to?(:keys) && data.respond_to?(:values) ? data.keys : nil
if keys
data = data.values
result << "<tr>\n"
keys.each do |heading|
result << "<th>#{CGI.escapeHTML(heading)}</th>\n"
end
result << "</tr>\n"
end
result << "<tr>\n"
data.each do |value|
result << "<td>" << (value.respond_to?(:each) ? table(value) : CGI.escapeHTML(value.to_s)) << "</td>\n"
end
result << "</tr>\n</table>\n"
end
end
end
end