From b29d6ca002a2d233270eb96384e02f1ebfe54906 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 22 Mar 2015 16:00:31 -0400 Subject: [PATCH] Move doc links to manifest --- assets/javascripts/models/doc.coffee | 2 +- .../views/content/entry_page.coffee | 14 ++++++++- assets/stylesheets/components/_page.scss | 31 +++++++++++++++++++ lib/docs/core/doc.rb | 3 +- lib/docs/core/scraper.rb | 8 ++--- lib/docs/filters/core/links.rb | 26 ---------------- test/lib/docs/core/doc_test.rb | 2 +- 7 files changed, 50 insertions(+), 36 deletions(-) delete mode 100644 lib/docs/filters/core/links.rb diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 89e78d61..d9826b70 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -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 diff --git a/assets/javascripts/views/content/entry_page.coffee b/assets/javascripts/views/content/entry_page.coffee index b116d56c..fc747379 100644 --- a/assets/javascripts/views/content/entry_page.coffee +++ b/assets/javascripts/views/content/entry_page.coffee @@ -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 + """#{LINKS[link]}""" + + """#{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: => diff --git a/assets/stylesheets/components/_page.scss b/assets/stylesheets/components/_page.scss index 30935d85..34362509 100644 --- a/assets/stylesheets/components/_page.scss +++ b/assets/stylesheets/components/_page.scss @@ -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 // diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 1331a821..1b4ce1cb 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -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) diff --git a/lib/docs/core/scraper.rb b/lib/docs/core/scraper.rb index 582370d5..634ee857 100644 --- a/lib/docs/core/scraper.rb +++ b/lib/docs/core/scraper.rb @@ -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? diff --git a/lib/docs/filters/core/links.rb b/lib/docs/filters/core/links.rb deleted file mode 100644 index ac763c86..00000000 --- a/lib/docs/filters/core/links.rb +++ /dev/null @@ -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| - %(
  • #{NAMES[name]}
  • ) - end - - <<-HTML.strip_heredoc -
    -
    Resources
    - -
    - HTML - end - end -end diff --git a/test/lib/docs/core/doc_test.rb b/test/lib/docs/core/doc_test.rb index 5de7c65c..2a74d32d 100644 --- a/test/lib/docs/core/doc_test.rb +++ b/test/lib/docs/core/doc_test.rb @@ -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