Merge pull request #170 from TrangPham/master

Adding Official Url for url scrapped documentations
pull/185/head
Thibaut Courouble 10 years ago
commit 4b9256a731

@ -22,6 +22,23 @@
}
}
//
// 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
//

@ -4,7 +4,7 @@ module Docs
DB_FILENAME = 'db.json'
class << self
attr_accessor :name, :slug, :type, :version, :abstract
attr_accessor :name, :slug, :type, :version, :abstract, :home_url
def inherited(subclass)
subclass.type = type

@ -20,6 +20,10 @@ module Docs
context[:base_url]
end
def home_url
context[:home_url]
end
def current_url
context[:url]
end

@ -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', 'attribution'
text_filters.push 'inner_html', 'clean_text', 'home_url', 'attribution'
def build_page(path)
response = request_one url_for(path)
@ -65,6 +65,10 @@ 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
end
def root_path
self.class.root_path
end
@ -89,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,
options.merge! base_url: base_url, root_url: root_url, home_url: home_url,
root_path: root_path, initial_paths: initial_paths
if root_path?

@ -0,0 +1,16 @@
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

@ -60,6 +60,19 @@ class DocsDocTest < MiniTest::Spec
end
end
describe ".home_url" do
it "returns nil" do
assert_nil doc.home_url
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

Loading…
Cancel
Save