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:
+3
-3
@@ -1,10 +1,10 @@
|
||||
rvm:
|
||||
- 2.0.0
|
||||
- 2.1.0
|
||||
- 2.1.1
|
||||
- 2.2.2
|
||||
- 2.2.1
|
||||
- 2.3.0
|
||||
- jruby-19mode
|
||||
- 2.4.0
|
||||
- jruby-9.1.8.0
|
||||
before_install:
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install libicu-dev
|
||||
|
||||
@@ -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> |
|
||||
| --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. |
|
||||
| --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. |
|
||||
| --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`. |
|
||||
|
||||
@@ -131,6 +131,9 @@ MSG
|
||||
opts.on("--h1-title", "Use the first '<h1>' as page title.") do
|
||||
wiki_options[:h1_title] = true
|
||||
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
|
||||
wiki_options[:show_all] = true
|
||||
end
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
||||
s.rdoc_options = ['--charset=UTF-8']
|
||||
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 'sinatra', '~> 1.4', '>= 1.4.4'
|
||||
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -69,6 +69,7 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
</div>
|
||||
{{/has_header}}
|
||||
<div class="markdown-body">
|
||||
{{{rendered_metadata}}}
|
||||
{{{content}}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -130,15 +130,23 @@ 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
|
||||
|
||||
# Wraps page formatted data to Nokogiri::HTML document.
|
||||
@@ -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
|
||||
|
||||
+4
-4
@@ -636,11 +636,11 @@ context "Frontend with lotr" do
|
||||
|
||||
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?("Boromir"), "/pages should NOT include the page 'Boromir'"
|
||||
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"
|
||||
end
|
||||
|
||||
@@ -650,8 +650,8 @@ context "Frontend with lotr" do
|
||||
|
||||
body = last_response.body
|
||||
|
||||
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?("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'"
|
||||
end
|
||||
|
||||
test "symbolic link pages" do
|
||||
|
||||
@@ -29,6 +29,28 @@ context "Precious::Views::Page" do
|
||||
assert_equal '1 & 2', actual
|
||||
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
|
||||
title = 'H1'
|
||||
@wiki.write_page(title, :markdown, '# 1 & 2 <script>alert("js")</script>' + "\n # 3", commit_details)
|
||||
|
||||
Reference in New Issue
Block a user