Test multiple formats
This commit is contained in:
parent
d0c9332361
commit
73a8e15de9
3 changed files with 98 additions and 4 deletions
57
test.rb
57
test.rb
|
@ -37,6 +37,11 @@ cmd :REGISTER_FORMAT, { name: :html,
|
|||
args: ['test/render.rb',
|
||||
{ template: nil },
|
||||
{ format: nil }] }
|
||||
cmd :REGISTER_FORMAT, { name: :json,
|
||||
stdin: { notes: nil },
|
||||
args: ['test/render.rb',
|
||||
{ template: nil },
|
||||
{ format: nil }] }
|
||||
|
||||
cmd :ADD_REF,
|
||||
{ kind: :self,
|
||||
|
@ -119,3 +124,55 @@ cmd(:RENDER_FOOTNOTES, :html).tap do |result|
|
|||
|
||||
raise unless result == expected
|
||||
end
|
||||
cmd(:RENDER_FOOTNOTES, :json).tap do |result|
|
||||
expected = <<~JSON.freeze
|
||||
{
|
||||
"self": [
|
||||
{
|
||||
"index": 1,
|
||||
"kind": "self",
|
||||
"id": "/blog/foo",
|
||||
"slug": "blog-foo",
|
||||
"anchor": "self-blog-foo",
|
||||
"fragment": "#self-blog-foo",
|
||||
"url": "/blog/foo.html",
|
||||
"text": "Foo"
|
||||
},
|
||||
{
|
||||
"index": 3,
|
||||
"kind": "self",
|
||||
"id": "/blog/bar",
|
||||
"slug": "blog-bar",
|
||||
"anchor": "self-blog-bar",
|
||||
"fragment": "#self-blog-bar",
|
||||
"url": "/blog/bar.html",
|
||||
"text": "Bar"
|
||||
}
|
||||
],
|
||||
"link": [
|
||||
{
|
||||
"index": 2,
|
||||
"kind": "link",
|
||||
"id": "example_com",
|
||||
"slug": "example-com",
|
||||
"anchor": "link-example-com",
|
||||
"fragment": "#link-example-com",
|
||||
"url": "https://example.com",
|
||||
"text": "Example Domain"
|
||||
},
|
||||
{
|
||||
"index": 4,
|
||||
"kind": "link",
|
||||
"id": "causa_arcana_com",
|
||||
"slug": "causa-arcana-com",
|
||||
"anchor": "link-causa-arcana-com",
|
||||
"fragment": "#link-causa-arcana-com",
|
||||
"url": "https://causa-arcana.com",
|
||||
"text": "Causa Arcana"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
|
||||
raise unless result == expected
|
||||
end
|
||||
|
|
|
@ -1,21 +1,25 @@
|
|||
<% if notes.any? { |note| note['kind'] == 'self' } -%>
|
||||
<% self_notes = notes.select { |note| note['kind'] == 'self' } -%>
|
||||
<% link_notes = notes.select { |note| note['kind'] == 'link' } -%>
|
||||
<%# -%>
|
||||
<% unless self_notes.empty? -%>
|
||||
|
||||
<h2>Self references</h2>
|
||||
|
||||
<ol>
|
||||
<% notes.select { |note| note['kind'] == 'self' }.each do |note| -%>
|
||||
<% self_notes.each do |note| -%>
|
||||
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
|
||||
<a href="<%= note['id'] %>.html"><%= note['text'] %></a>
|
||||
</li>
|
||||
<% end -%>
|
||||
</ol>
|
||||
<% end -%>
|
||||
<% if notes.any? { |note| note['kind'] == 'link' } -%>
|
||||
<%# -%>
|
||||
<% unless link_notes.empty? -%>
|
||||
|
||||
<h2>Link references</h2>
|
||||
|
||||
<ol>
|
||||
<% notes.select { |note| note['kind'] == 'link' }.each do |note| -%>
|
||||
<% link_notes.each do |note| -%>
|
||||
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
|
||||
<a href="<%= note['url'] %>"><%= note['text'] %></a>
|
||||
</li>
|
||||
|
|
33
test/footnotes.json.erb
Normal file
33
test/footnotes.json.erb
Normal file
|
@ -0,0 +1,33 @@
|
|||
<% self_notes = notes.select { |note| note['kind'] == 'self' } -%>
|
||||
<% link_notes = notes.select { |note| note['kind'] == 'link' } -%>
|
||||
<%# -%>
|
||||
{
|
||||
"self": [
|
||||
<%- self_notes.each_with_index do |note, index| -%>
|
||||
{
|
||||
"index": <%= Integer(note['index']).to_json %>,
|
||||
"kind": "self",
|
||||
"id": <%= String(note['id']).to_json %>,
|
||||
"slug": <%= String(note['slug']).to_json %>,
|
||||
"anchor": <%= String(note['anchor']).to_json %>,
|
||||
"fragment": <%= String(note['fragment']).to_json %>,
|
||||
"url": <%= "#{note['id']}.html".to_json %>,
|
||||
"text": <%= String(note['text']).to_json %>
|
||||
}<%= ',' unless index == self_notes.count - 1 %>
|
||||
<%- end -%>
|
||||
],
|
||||
"link": [
|
||||
<%- link_notes.each_with_index do |note, index| -%>
|
||||
{
|
||||
"index": <%= Integer(note['index']).to_json %>,
|
||||
"kind": "link",
|
||||
"id": <%= String(note['id']).to_json %>,
|
||||
"slug": <%= String(note['slug']).to_json %>,
|
||||
"anchor": <%= String(note['anchor']).to_json %>,
|
||||
"fragment": <%= String(note['fragment']).to_json %>,
|
||||
"url": <%= String(note['url']).to_json %>,
|
||||
"text": <%= String(note['text']).to_json %>
|
||||
}<%= ',' unless index == link_notes.count - 1 %>
|
||||
<%- end -%>
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue