From cf7f4467385883c362b9b66be69f968be2510f3e Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 14 Mar 2015 16:51:55 -0400 Subject: [PATCH] Change home_url to a list of links --- assets/stylesheets/components/_content.scss | 7 ++++-- assets/stylesheets/components/_page.scss | 17 -------------- lib/docs/core/doc.rb | 2 +- lib/docs/core/filter.rb | 4 ++-- lib/docs/core/scraper.rb | 8 +++---- lib/docs/filters/core/home_url.rb | 16 ------------- lib/docs/filters/core/links.rb | 26 +++++++++++++++++++++ test/lib/docs/core/doc_test.rb | 14 ++++------- 8 files changed, 42 insertions(+), 52 deletions(-) delete mode 100644 lib/docs/filters/core/home_url.rb create mode 100644 lib/docs/filters/core/links.rb diff --git a/assets/stylesheets/components/_content.scss b/assets/stylesheets/components/_content.scss index fc11154a..165ddef4 100644 --- a/assets/stylesheets/components/_content.scss +++ b/assets/stylesheets/components/_content.scss @@ -205,15 +205,16 @@ float: right; max-width: 15em; margin: .25rem 0 1.5rem 1.5rem; - padding: .75rem 1rem; + padding: .625rem 1rem; @extend %box; + ._lined-heading { margin-top: 0; } } ._toc-title { - margin: 0 0 .75em; + margin: 0 0 .5rem; font-size: inherit; + font-weight: bold; } ._toc-list { @@ -222,6 +223,8 @@ list-style: none; } +._toc-link { @extend %internal-link; } + // // Static page // diff --git a/assets/stylesheets/components/_page.scss b/assets/stylesheets/components/_page.scss index d9d96e46..30935d85 100644 --- a/assets/stylesheets/components/_page.scss +++ b/assets/stylesheets/components/_page.scss @@ -22,23 +22,6 @@ } } -// -// Official Website box -// - -._official { - clear: both; - margin: 2rem 0 1.5rem; - font-size: .75rem; - color: $textColorLight; - text-align: center; - -webkit-font-smoothing: subpixel-antialiased; - - & + & { margin-top: 1.5rem; } -} - -._official-link { @extend %external-link; } - // // Attribution box // diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 6ea7ed01..124fb726 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -4,7 +4,7 @@ module Docs DB_FILENAME = 'db.json' class << self - attr_accessor :name, :slug, :type, :version, :abstract, :home_url + attr_accessor :name, :slug, :type, :version, :abstract, :links def inherited(subclass) subclass.type = type diff --git a/lib/docs/core/filter.rb b/lib/docs/core/filter.rb index 21c88d0a..6d3d4b46 100644 --- a/lib/docs/core/filter.rb +++ b/lib/docs/core/filter.rb @@ -20,8 +20,8 @@ module Docs context[:base_url] end - def home_url - context[:home_url] + def links + context[:links] end def current_url diff --git a/lib/docs/core/scraper.rb b/lib/docs/core/scraper.rb index d6d45b7c..582370d5 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', 'home_url', 'attribution' + text_filters.push 'inner_html', 'clean_text', 'links', 'attribution' def build_page(path) response = request_one url_for(path) @@ -65,8 +65,8 @@ module Docs @root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize end - def home_url - @home_url ||= self.class.home_url + def links + self.class.links end def root_path @@ -93,7 +93,7 @@ module Docs def options @options ||= self.class.options.deep_dup.tap do |options| - options.merge! base_url: base_url, root_url: root_url, home_url: home_url, + options.merge! base_url: base_url, root_url: root_url, links: links, root_path: root_path, initial_paths: initial_paths if root_path? diff --git a/lib/docs/filters/core/home_url.rb b/lib/docs/filters/core/home_url.rb deleted file mode 100644 index 0892f3fd..00000000 --- a/lib/docs/filters/core/home_url.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Docs - class HomeUrlFilter < Filter - def call - html.prepend(home_url_html) if home_url - html - end - - def home_url_html - <<-HTML.strip_heredoc -
- Official Documentation: #{home_url} -
- HTML - end - end -end diff --git a/lib/docs/filters/core/links.rb b/lib/docs/filters/core/links.rb new file mode 100644 index 00000000..d8161491 --- /dev/null +++ b/lib/docs/filters/core/links.rb @@ -0,0 +1,26 @@ +module Docs + class LinksFilter < Filter + def call + html.prepend(links_html) if 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 d3d783d3..5de7c65c 100644 --- a/test/lib/docs/core/doc_test.rb +++ b/test/lib/docs/core/doc_test.rb @@ -60,19 +60,13 @@ class DocsDocTest < MiniTest::Spec end end - describe ".home_url" do - it "returns nil" do - assert_nil doc.home_url + describe ".links=" do + it "stores .links" do + doc.links = { test: true } + assert_equal({ test: true }, doc.links) end end - describe ".home_url=" do - it "stores .home_url" do - doc.home_url = 'http://www.url.com/doc' - assert_equal 'http://www.url.com/doc', doc.home_url - end - end - describe ".abstract" do it "returns nil" do assert_nil doc.abstract