Move doc links to manifest

pull/185/head
Thibaut 10 years ago
parent 34e804d455
commit b29d6ca002

@ -1,5 +1,5 @@
class app.models.Doc extends app.Model
# Attributes: name, slug, type, version, index_path, db_path, db_size, mtime
# Attributes: name, slug, type, version, index_path, db_path, db_size, mtime, links
constructor: ->
super

@ -36,6 +36,18 @@ class app.views.EntryPage extends app.View
@trigger 'loaded'
return
LINKS =
home: 'Homepage'
code: 'Source code'
prepareContent: (content) ->
return content unless @entry.isIndex() and @entry.doc.links
links = for link, url of @entry.doc.links
"""<a href="#{url}" class="_links-link">#{LINKS[link]}</a>"""
"""<p class="_links">#{links.join('')}</p>#{content}"""
empty: ->
@subview?.deactivate()
@subview = null
@ -78,7 +90,7 @@ class app.views.EntryPage extends app.View
onSuccess: (response) =>
@xhr = null
@render response
@render @prepareContent(response)
return
onError: =>

@ -3,6 +3,8 @@
//
._page {
position: relative;
> h1 { @extend ._lined-heading; }
> h1:first-child { margin-top: 0; }
@ -22,6 +24,35 @@
}
}
//
// Links
//
._links {
position: absolute;
top: 0;
right: 0;
margin: 0;
line-height: 2em;
text-align: right;
+ h1 { margin-top: 0; }
@media (max-width: 1023px) { display: none; }
}
._links-link {
display: inline-block;
vertical-align: top;
padding: 0 .5rem;
background: white;
@extend %internal-link;
& + & { margin-left: .75rem; }
&:first-child { padding-left: 1rem; }
&:last-child { padding-right: 0; }
}
//
// Attribution box
//

@ -38,7 +38,8 @@ module Docs
type: type,
version: version,
index_path: index_path,
db_path: db_path }
db_path: db_path,
links: links }
end
def store_page(store, id)

@ -34,7 +34,7 @@ module Docs
self.text_filters = FilterStack.new
html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths'
text_filters.push 'inner_html', 'clean_text', 'links', 'attribution'
text_filters.push 'inner_html', 'clean_text', 'attribution'
def build_page(path)
response = request_one url_for(path)
@ -65,10 +65,6 @@ module Docs
@root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize
end
def links
self.class.links
end
def root_path
self.class.root_path
end
@ -93,7 +89,7 @@ module Docs
def options
@options ||= self.class.options.deep_dup.tap do |options|
options.merge! base_url: base_url, root_url: root_url, links: links,
options.merge! base_url: base_url, root_url: root_url,
root_path: root_path, initial_paths: initial_paths
if root_path?

@ -1,26 +0,0 @@
module Docs
class LinksFilter < Filter
def call
html.prepend(links_html) if root_page? && links
html
end
NAMES = {
home: 'Homepage',
code: 'Source code'
}
def links_html
links = self.links.map do |name, link|
%(<li><a href="#{link}" class="_toc-link">#{NAMES[name]}</a></li>)
end
<<-HTML.strip_heredoc
<div class="_toc">
<div class="_toc-title">Resources</div>
<ul class="_toc-list">#{links.join}</ul>
</div>
HTML
end
end
end

@ -116,7 +116,7 @@ class DocsDocTest < MiniTest::Spec
end
it "includes the doc's name, slug, type, version, index_path and db_path" do
%w(name slug type version index_path db_path).each do |attribute|
%w(name slug type version index_path db_path links).each do |attribute|
eval "stub(doc).#{attribute} { attribute }"
assert_equal attribute, doc.as_json[attribute.to_sym]
end

Loading…
Cancel
Save