Improve template data
This commit is contained in:
parent
2fe72d3ea4
commit
5944a20b56
4 changed files with 19 additions and 16 deletions
|
@ -20,7 +20,7 @@ module Referator
|
|||
end
|
||||
|
||||
def render(format)
|
||||
config.formats.render :footnotes, format, @notes.map(&:to_h).freeze
|
||||
config.formats.render :footnotes, format, notes
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -32,5 +32,14 @@ module Referator
|
|||
|
||||
@config = config
|
||||
end
|
||||
|
||||
def notes
|
||||
config.kinds.names.to_h do |name|
|
||||
[
|
||||
name,
|
||||
@notes.select { |note| note.kind == name }.map(&:to_h).freeze,
|
||||
]
|
||||
end.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Referator
|
|||
|
||||
attr_reader :footnotes, :index, :reference
|
||||
|
||||
def_delegators :reference, :anchor, :fragment
|
||||
def_delegators :reference, :kind, :anchor, :fragment
|
||||
|
||||
def initialize(footnotes, index, reference)
|
||||
self.footnotes = footnotes
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
<% self_notes = notes.select { |note| note['kind'] == 'self' } -%>
|
||||
<% link_notes = notes.select { |note| note['kind'] == 'link' } -%>
|
||||
<%# -%>
|
||||
<% unless self_notes.empty? -%>
|
||||
<% unless notes['self'].empty? -%>
|
||||
|
||||
<h2>Self references</h2>
|
||||
|
||||
<ol>
|
||||
<% self_notes.each do |note| -%>
|
||||
<% notes['self'].each do |note| -%>
|
||||
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
|
||||
<a href="<%= note['id'] %>.html"><%= note['text'] %></a>
|
||||
</li>
|
||||
|
@ -14,12 +11,12 @@
|
|||
</ol>
|
||||
<% end -%>
|
||||
<%# -%>
|
||||
<% unless link_notes.empty? -%>
|
||||
<% unless notes['link'].empty? -%>
|
||||
|
||||
<h2>Link references</h2>
|
||||
|
||||
<ol>
|
||||
<% link_notes.each do |note| -%>
|
||||
<% notes['link'].each do |note| -%>
|
||||
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
|
||||
<a href="<%= note['url'] %>"><%= note['text'] %></a>
|
||||
</li>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
<% 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| -%>
|
||||
<%- notes['self'].each_with_index do |note, index| -%>
|
||||
{
|
||||
"index": <%= Integer(note['index']).to_json %>,
|
||||
"kind": "self",
|
||||
|
@ -13,11 +10,11 @@
|
|||
"fragment": <%= String(note['fragment']).to_json %>,
|
||||
"url": <%= "#{note['id']}.html".to_json %>,
|
||||
"text": <%= String(note['text']).to_json %>
|
||||
}<%= ',' unless index == self_notes.count - 1 %>
|
||||
}<%= ',' unless index == notes['self'].count - 1 %>
|
||||
<%- end -%>
|
||||
],
|
||||
"link": [
|
||||
<%- link_notes.each_with_index do |note, index| -%>
|
||||
<%- notes['link'].each_with_index do |note, index| -%>
|
||||
{
|
||||
"index": <%= Integer(note['index']).to_json %>,
|
||||
"kind": "link",
|
||||
|
@ -27,7 +24,7 @@
|
|||
"fragment": <%= String(note['fragment']).to_json %>,
|
||||
"url": <%= String(note['url']).to_json %>,
|
||||
"text": <%= String(note['text']).to_json %>
|
||||
}<%= ',' unless index == link_notes.count - 1 %>
|
||||
}<%= ',' unless index == notes['link'].count - 1 %>
|
||||
<%- end -%>
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue