Extract page dir from latest changes. Fix #1388 (#1395)

* Strip off page_dir prefix from latest changes urls
* Rename spurious next and previous_link
* New format for LatestChanges#versions: detect renames
This commit is contained in:
Dawa Ometto
2019-09-18 18:10:09 +02:00
committed by GitHub
parent 41d7cf75c5
commit 88c624877e
7 changed files with 81 additions and 29 deletions
-1
View File
@@ -41,6 +41,5 @@ module Precious
fail ArgumentError, "emoji `#{name}' not found"
end
end
end
end
+2 -2
View File
@@ -15,8 +15,8 @@
<span class="flex-auto col-1 text-gray-light">{{date}}</span>
<span class="flex-auto col-7">{{message}}<br/>
{{#files}}
<span class="flex-auto col-2"><a href="{{link}}">{{file}}</a></span><br/>
{{/files}}
<span class="flex-auto col-2">{{#renamed}}{{renamed}} -> {{/renamed}}<a href="{{link}}">{{file}}</a></span><br/>
{{/files}}
</span>
<span class="pl-4 float-right">[{{id7}}]</span>
</div>
+13
View File
@@ -2,6 +2,15 @@ require 'json'
module Precious
module Views
module AppHelpers
def extract_page_dir(path)
return path unless @page_dir
@path_to_extract ||= "#{Pathname.new(@page_dir).cleanpath}/"
path.start_with?(@path_to_extract) ? path.slice(@path_to_extract.length, path.length) : path
end
end
module RouteHelpers
ROUTES = {
'gollum' => {
@@ -43,6 +52,10 @@ module Precious
@@route_methods.to_json
end
end
def page_route(page)
"#{base_url}/#{page}".gsub(/\/{2,}/, '/') # remove double slashes
end
end
module OcticonHelpers
+5 -13
View File
@@ -22,25 +22,17 @@ module Precious
:date => v.authored_date.strftime("%B %d, %Y"),
:user_icon => self.user_icon_code(v.author.email),
:date_full => v.authored_date,
:files => v.stats.files.map { |f,*rest|
page_path = extract_renamed_path_destination(f)
{ :file => f,
:link => "#{page_path}/#{v.id}"
:files => v.stats.files.map { |f|
new_path = extract_page_dir(f[:new_file])
{ :file => new_path,
:link => "#{page_route(new_path)}/#{v.id}",
:renamed => f[:old_file] ? extract_page_dir(f[:old_file]) : nil
}
}
}
end
end
def extract_renamed_path_destination(file)
return file.gsub(/{.* => (.*)}/, '\1').gsub(/.* => (.*)/, '\1')
end
def previous_link
end
def next_link
end
end
end
end
+1
View File
@@ -5,6 +5,7 @@ module Precious
class Layout < Mustache
include Rack::Utils
include Sprockets::Helpers
include Precious::Views::AppHelpers
include Precious::Views::SprocketsHelpers
include Precious::Views::RouteHelpers
include Precious::Views::OcticonHelpers