Adding Official Url for url scrapped documentations
Unified · Split
| @@ -22,6 +22,23 @@ · 21 unmodified lines | |||
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | // | ||
| 26 | // Official Website box | ||
| 27 | // | ||
| 28 | |||
| 29 | ._official { | ||
| 30 | clear: both; | ||
| 31 | margin: 2rem 0 1.5rem; | ||
| 32 | font-size: .75rem; | ||
| 33 | color: $textColorLight; | ||
| 34 | text-align: center; | ||
| 35 | -webkit-font-smoothing: subpixel-antialiased; | ||
| 36 | |||
| 37 | & + & { margin-top: 1.5rem; } | ||
| 38 | } | ||
| 39 | |||
| 40 | ._official-link { @extend %external-link; } | ||
| 41 | |||
| 25 | // | 42 | // |
| 26 | // Attribution box | 43 | // Attribution box |
| 27 | // | 44 | // |
| @@ -4,7 +4,7 @@ module Docs · 3 unmodified lines | |||
| 4 | DB_FILENAME = 'db.json' | 4 | DB_FILENAME = 'db.json' |
| 5 | 5 | ||
| 6 | class << self | 6 | class << self |
| 7 | attr_accessor :name, :slug, :type, :version, :abstract | 7 | attr_accessor :name, :slug, :type, :version, :abstract, :home_url |
| 8 | 8 | ||
| 9 | def inherited(subclass) | 9 | def inherited(subclass) |
| 10 | subclass.type = type | 10 | subclass.type = type |
| @@ -20,6 +20,10 @@ module Docs · 19 unmodified lines | |||
| 20 | context[:base_url] | 20 | context[:base_url] |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | def home_url | ||
| 24 | context[:home_url] | ||
| 25 | end | ||
| 26 | |||
| 23 | def current_url | 27 | def current_url |
| 24 | context[:url] | 28 | context[:url] |
| 25 | end | 29 | end |
| @@ -34,7 +34,7 @@ module Docs · 33 unmodified lines | |||
| 34 | self.text_filters = FilterStack.new | 34 | self.text_filters = FilterStack.new |
| 35 | 35 | ||
| 36 | html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths' | 36 | html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths' |
| 37 | text_filters.push 'inner_html', 'clean_text', 'attribution' | 37 | text_filters.push 'inner_html', 'clean_text', 'home_url', 'attribution' |
| 38 | 38 | ||
| 39 | def build_page(path) | 39 | def build_page(path) |
| 40 | response = request_one url_for(path) | 40 | response = request_one url_for(path) |
| @@ -65,6 +65,10 @@ module Docs · 24 unmodified lines | |||
| 65 | @root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize | 65 | @root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | def home_url | ||
| 69 | @home_url ||= self.class.home_url | ||
| 70 | end | ||
| 71 | |||
| 68 | def root_path | 72 | def root_path |
| 69 | self.class.root_path | 73 | self.class.root_path |
| 70 | end | 74 | end |
| @@ -89,7 +93,7 @@ module Docs · 18 unmodified lines | |||
| 89 | 93 | ||
| 90 | def options | 94 | def options |
| 91 | @options ||= self.class.options.deep_dup.tap do |options| | 95 | @options ||= self.class.options.deep_dup.tap do |options| |
| 92 | options.merge! base_url: base_url, root_url: root_url, | 96 | options.merge! base_url: base_url, root_url: root_url, home_url: home_url, |
| 93 | root_path: root_path, initial_paths: initial_paths | 97 | root_path: root_path, initial_paths: initial_paths |
| 94 | 98 | ||
| 95 | if root_path? | 99 | if root_path? |
| @@ -0,0 +1,16 @@ | |||
| 1 | module Docs | ||
| 2 | class HomeUrlFilter < Filter | ||
| 3 | def call | ||
| 4 | html.prepend(home_url_html) if home_url | ||
| 5 | html | ||
| 6 | end | ||
| 7 | |||
| 8 | def home_url_html | ||
| 9 | <<-HTML.strip_heredoc | ||
| 10 | <div class="_official"> | ||
| 11 | Official Documentation: <a href="#{home_url}" class="_official-link">#{home_url}</a> | ||
| 12 | </div> | ||
| 13 | HTML | ||
| 14 | end | ||
| 15 | end | ||
| 16 | end | ||
| @@ -60,6 +60,19 @@ class DocsDocTest < MiniTest::Spec · 59 unmodified lines | |||
| 60 | end | 60 | end |
| 61 | end | 61 | end |
| 62 | 62 | ||
| 63 | describe ".home_url" do | ||
| 64 | it "returns nil" do | ||
| 65 | assert_nil doc.home_url | ||
| 66 | end | ||
| 67 | end | ||
| 68 | |||
| 69 | describe ".home_url=" do | ||
| 70 | it "stores .home_url" do | ||
| 71 | doc.home_url = 'http://www.url.com/doc' | ||
| 72 | assert_equal 'http://www.url.com/doc', doc.home_url | ||
| 73 | end | ||
| 74 | end | ||
| 75 | |||
| 63 | describe ".abstract" do | 76 | describe ".abstract" do |
| 64 | it "returns nil" do | 77 | it "returns nil" do |
| 65 | assert_nil doc.abstract | 78 | assert_nil doc.abstract |