Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several issues with edition links #1432

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions helpers/docs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,28 @@ def link_to_documentation(page, version=nil)
end

def link_to_editable_version
editable = true
path = current_page.file_descriptor.relative_path.to_s
repo =
if path.start_with?("doc/")
path = "bundler/#{path}"
"rubygems/rubygems"
elsif %r{\A(?<version>v\d+\.\d+)/man/(?<filename>(bundle[_-]|gemfile)[^/]*)\.html} =~ path
if version == current_version
path = "bundler/lib/bundler/man/#{filename}.ronn"
else
editable = false
end
"rubygems/rubygems"
if path.start_with?("doc/")
path.delete_prefix!("doc/")
path.prepend("doc/bundler/")
dirname = File.dirname(path)
basename = File.basename(path, ".html.md").upcase
path = File.join(dirname, "#{basename}.md")
link_to_source("rubygems/rubygems", path)
elsif %r{\Aman/(?<filename>(bundle[_-]|gemfile)[^/]*)\.html} =~ path
path = "bundler/lib/bundler/man/#{filename}.ronn"
link_to_source("rubygems/rubygems", path)
elsif %r{\A(?<version>v\d+\.\d+)/man/(?<filename>(bundle[_-]|gemfile)[^/]*)\.html} =~ path
if version == current_version
path = "bundler/lib/bundler/man/#{filename}.ronn"
link_to_source("rubygems/rubygems", path)
else
path = File.join "source", path
"rubygems/bundler-site"
path = path.sub(version, current_version)
link_to_latest(path)
end

if editable
url = "https://github.com/#{repo}/blob/master/#{path}"
link_to("Edit this document on GitHub", url) +
" if you caught an error or noticed something was missing."
else
url = "/" + path.sub(version, current_version).sub(/\.html.*/, ".html")
"This document is obsolete. " +
link_to("See the latest version of this document", url) +
" if you caught an error or noticed something was missing, it may be fixed there."
path = File.join "source", path
link_to_source("rubygems/bundler-site", path)
end
end

Expand Down Expand Up @@ -73,6 +68,19 @@ def whats_new?(path)

private

def link_to_source(repo, path)
url = "https://github.com/#{repo}/blob/master/#{path}"
link_to("Edit this document on GitHub", url) +
" if you caught an error or noticed something was missing."
end

def link_to_latest(path)
url = "/" + path.sub(/\.html.*/, ".html")
"This document is obsolete. " +
link_to("See the latest version of this document", url) +
" if you caught an error or noticed something was missing, it may be fixed there."
end

def strip_version_from_url(url)
url.scan(/v\d\.\d+\/(.*).html/)&.first&.first || url
end
Expand Down
2 changes: 1 addition & 1 deletion source/layouts/two_column_layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
.container
.contents
.edit-on-github.text-center
= link_to_editable_version
!= link_to_editable_version