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 -3
View File
@@ -1,10 +1,10 @@
rvm: rvm:
- 2.0.0
- 2.1.0 - 2.1.0
- 2.1.1 - 2.1.1
- 2.2.2 - 2.2.1
- 2.3.0 - 2.3.0
- jruby-19mode - 2.4.0
- jruby-9.1.8.0
before_install: before_install:
- sudo apt-get update - sudo apt-get update
- sudo apt-get install libicu-dev - sudo apt-get install libicu-dev
+1
View File
@@ -150,6 +150,7 @@ Gollum comes with the following command line options:
| --mathjax | none | Enables MathJax (renders mathematical equations). By default, uses the `TeX-AMS-MML_HTMLorMML` config with the `autoload-all` extension.<sup>5</sup> | | --mathjax | none | Enables MathJax (renders mathematical equations). By default, uses the `TeX-AMS-MML_HTMLorMML` config with the `autoload-all` extension.<sup>5</sup> |
| --irb | none | Launch Gollum in "console mode", with a [predefined API](https://github.com/gollum/gollum-lib/). | | --irb | none | Launch Gollum in "console mode", with a [predefined API](https://github.com/gollum/gollum-lib/). |
| --h1-title | none | Tell Gollum to use the first `<h1>` as page title. | | --h1-title | none | Tell Gollum to use the first `<h1>` as page title. |
| --no-display-metadata | none | Do not render metadata tables in pages. |
| --show-all | none | Tell Gollum to also show files in the file view. By default, only valid pages are shown. | | --show-all | none | Tell Gollum to also show files in the file view. By default, only valid pages are shown. |
| --collapse-tree | none | Tell Gollum to collapse the file tree, when the file view is opened. By default, the tree is expanded. | | --collapse-tree | none | Tell Gollum to collapse the file tree, when the file view is opened. By default, the tree is expanded. |
| --user-icons | [MODE] | Tell Gollum to use specific user icons for history view. Can be set to `gravatar`, `identicon` or `none`. Default: `none`. | | --user-icons | [MODE] | Tell Gollum to use specific user icons for history view. Can be set to `gravatar`, `identicon` or `none`. Default: `none`. |
+3
View File
@@ -131,6 +131,9 @@ MSG
opts.on("--h1-title", "Use the first '<h1>' as page title.") do opts.on("--h1-title", "Use the first '<h1>' as page title.") do
wiki_options[:h1_title] = true wiki_options[:h1_title] = true
end end
opts.on("--no-display-metadata", "Do not render metadata tables in pages.") do
wiki_options[:display_metadata] = false
end
opts.on("--show-all", "Also show files in the file view. By default, only valid pages are shown.") do opts.on("--show-all", "Also show files in the file view. By default, only valid pages are shown.") do
wiki_options[:show_all] = true wiki_options[:show_all] = true
end end
+1 -1
View File
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ['--charset=UTF-8'] s.rdoc_options = ['--charset=UTF-8']
s.extra_rdoc_files = %w[README.md LICENSE] s.extra_rdoc_files = %w[README.md LICENSE]
s.add_dependency 'gollum-lib', '~> 4.0', '>= 4.0.1' s.add_dependency 'gollum-lib', '~> 5.0.a'
s.add_dependency 'kramdown', '~> 1.9.0' s.add_dependency 'kramdown', '~> 1.9.0'
s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4' s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4'
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0'] s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
+3 -1
View File
@@ -385,7 +385,9 @@ a:active, a:hover {
} }
.markdown-body table tr th, .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; border: 1px solid #ccc;
text-align: none; text-align: none;
margin: 0; margin: 0;
+1
View File
@@ -69,6 +69,7 @@ Mousetrap.bind(['e'], function( e ) {
</div> </div>
{{/has_header}} {{/has_header}}
<div class="markdown-body"> <div class="markdown-body">
{{{rendered_metadata}}}
{{{content}}} {{{content}}}
</div> </div>
</div> </div>
+32 -4
View File
@@ -130,15 +130,23 @@ module Precious
# Access to embedded metadata. # Access to embedded metadata.
# #
# Examples
#
# {{#metadata}}{{name}}{{/metadata}}
#
# Returns Hash. # Returns Hash.
def metadata def metadata
@page.metadata @page.metadata
end 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 private
# Wraps page formatted data to Nokogiri::HTML document. # Wraps page formatted data to Nokogiri::HTML document.
@@ -184,6 +192,26 @@ module Precious
# .inner_html will cause href escaping on UTF-8 # .inner_html will cause href escaping on UTF-8
doc.css("div#gollum-root").children.to_xml(@@to_xml) doc.css("div#gollum-root").children.to_xml(@@to_xml)
end 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 end
end end
+4 -4
View File
@@ -636,11 +636,11 @@ context "Frontend with lotr" do
body = last_response.body body = last_response.body
assert body.include?("Bilbo Baggins"), "/pages should include the page 'Bilbo Baggins'" assert body.include?("Bilbo-Baggins"), "/pages should include the page 'Bilbo Baggins'"
assert body.include?("Gondor"), "/pages should include the folder 'Gondor'" assert body.include?("Gondor"), "/pages should include the folder 'Gondor'"
assert !body.include?("Boromir"), "/pages should NOT include the page 'Boromir'" assert !body.include?("Boromir"), "/pages should NOT include the page 'Boromir'"
assert body.include?("Mordor"), "/pages should include the folder 'Mordor'" assert body.include?("Mordor"), "/pages should include the folder 'Mordor'"
assert !body.include?("Eye Of Sauron"), "/pages should NOT include the page 'Eye Of Sauron'" assert !body.include?("Eye-Of-Sauron"), "/pages should NOT include the page 'Eye Of Sauron'"
assert !body.match(/(Zamin).+(roast\-mutton)/m), "/pages should be sorted alphabetically" assert !body.match(/(Zamin).+(roast\-mutton)/m), "/pages should be sorted alphabetically"
end end
@@ -650,8 +650,8 @@ context "Frontend with lotr" do
body = last_response.body body = last_response.body
assert !body.include?("Bilbo Baggins"), "/pages/Mordor/ should NOT include the page 'Bilbo Baggins'" assert !body.include?("Bilbo-Baggins"), "/pages/Mordor/ should NOT include the page 'Bilbo Baggins'"
assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'" assert body.include?("Eye-Of-Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'"
end end
test "symbolic link pages" do test "symbolic link pages" do
+22
View File
@@ -29,6 +29,28 @@ context "Precious::Views::Page" do
assert_equal '1 & 2', actual assert_equal '1 & 2', actual
end end
test "metadata is rendered into a table" do
title = 'metadata test'
@wiki.write_page(title, :markdown, "---\nsome: metadata\nhere: for you\n---\n# Some markdown\nIn this doc")
page = @wiki.page(title)
@view = Precious::Views::Page.new
@view.instance_variable_set :@page, page
assert_equal @view.rendered_metadata, <<-EOS
<table>
<tr>
<th>some</th>
<th>here</th>
</tr>
<tr>
<td>metadata</td>
<td>for you</td>
</tr>
</table>
EOS
end
test "h1 title can be disabled" do test "h1 title can be disabled" do
title = 'H1' title = 'H1'
@wiki.write_page(title, :markdown, '# 1 & 2 <script>alert("js")</script>' + "\n # 3", commit_details) @wiki.write_page(title, :markdown, '# 1 & 2 <script>alert("js")</script>' + "\n # 3", commit_details)