Browse Source

Change home_url to a list of links

Thibaut 10 years ago
parent
commit
cf7f446738

+ 5 - 2
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
 //

+ 0 - 17
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
 //

+ 1 - 1
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

+ 2 - 2
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

+ 4 - 4
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?

+ 0 - 16
lib/docs/filters/core/home_url.rb

@@ -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
-      <div class="_official">
-        Official Documentation: <a href="#{home_url}" class="_official-link">#{home_url}</a>
-      </div>
-      HTML
-    end
-  end
-end

+ 26 - 0
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|
+        %(<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

+ 4 - 10
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