* 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:
@@ -41,6 +41,5 @@ module Precious
|
||||
fail ArgumentError, "emoji `#{name}' not found"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-1
@@ -19,7 +19,11 @@ $LOAD_PATH.unshift(dir)
|
||||
|
||||
module Gollum
|
||||
end
|
||||
Gollum::GIT_ADAPTER = ENV['GIT_ADAPTER'] if ENV['GIT_ADAPTER']
|
||||
if ENV['GIT_ADAPTER']
|
||||
Gollum::GIT_ADAPTER = ENV['GIT_ADAPTER']
|
||||
else
|
||||
Gollum::GIT_ADAPTER = RUBY_PLATFORM == 'java' ? 'rjgit' : 'rugged'
|
||||
end
|
||||
|
||||
ENV['RACK_ENV'] = 'test'
|
||||
require 'gollum'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/views/latest_changes', __FILE__
|
||||
|
||||
context "Precious::Views::LatestChanges" do
|
||||
context 'Precious::Views::LatestChanges' do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app
|
||||
@@ -10,13 +10,27 @@ context "Precious::Views::LatestChanges" do
|
||||
end
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@path = cloned_testpath('examples/lotr.git')
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
@url = '/gollum/latest_changes'
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {:pagination_count => 10})
|
||||
end
|
||||
|
||||
test 'rename detection' do
|
||||
versions = [OpenStruct.new(
|
||||
:id => 'fake',
|
||||
:author => OpenStruct.new(:email => 'fake', :name => 'fake'),
|
||||
:message => 'fake',
|
||||
:authored_date => Time.now,
|
||||
:stats => OpenStruct.new(:files => [{:new_file => 'new_path', :old_file => 'old_path', :new_additions => 1, :new_deletions => 1, :changes => 1}])
|
||||
)]
|
||||
view = Precious::Views::LatestChanges.new
|
||||
view.instance_variable_set(:@versions, versions)
|
||||
view.instance_variable_set(:@request, OpenStruct.new(:host => 'fake')) # dummy to generate gravatar icon
|
||||
assert_equal view.versions[0][:files][0][:renamed], 'old_path'
|
||||
end
|
||||
|
||||
test "displays_latest_changes" do
|
||||
get(@url)
|
||||
body = last_response.body
|
||||
@@ -24,10 +38,10 @@ context "Precious::Views::LatestChanges" do
|
||||
assert body.include?("Charles Pence</span>"), "/latest_changes should include Author Charles Pence"
|
||||
assert body.include?('1db89eb'), "/latest_changes should include the :pagination_count commit"
|
||||
assert !body.include?('a8ad3c0'), "/latest_changes should not include more than :pagination_count commits"
|
||||
assert body.include?('<a href="Data-Two.csv/874f597a5659b4c3b153674ea04e406ff393975e">Data-Two.csv</a>'), "/latest_changes include links to modified files in #{body}"
|
||||
assert body.include?('<a href="Hobbit.md/874f597a5659b4c3b153674ea04e406ff393975e">Hobbit.md</a>'), "/latest_changes should include links to modified pages in #{body}"
|
||||
assert body.include?('<a href="/Data-Two.csv/874f597a5659b4c3b153674ea04e406ff393975e">Data-Two.csv</a>'), "/latest_changes include links to modified files in #{body}"
|
||||
assert body.include?('<a href="/Hobbit.md/874f597a5659b4c3b153674ea04e406ff393975e">Hobbit.md</a>'), "/latest_changes should include links to modified pages in #{body}"
|
||||
end
|
||||
|
||||
|
||||
test 'gravatar' do
|
||||
Precious::App.set(:wiki_options, {:user_icons => 'gravatar'})
|
||||
get @url
|
||||
@@ -42,13 +56,42 @@ context "Precious::Views::LatestChanges" do
|
||||
Precious::App.set(:wiki_options, {:user_icons => 'none'})
|
||||
end
|
||||
|
||||
test "extract destination file name in case of path renaming" do
|
||||
view = Precious::Views::LatestChanges.new
|
||||
assert_equal "newname.md", view.extract_renamed_path_destination("oldname.md => newname.md")
|
||||
assert_equal "newDirectoryName/fileName.md", view.extract_renamed_path_destination("{oldDirectoryName => newDirectoryName}/fileName.md")
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Latest changes with page-file-dir' do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
end
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath('examples/lotr.git')
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, { :page_file_dir => 'Rivendell'})
|
||||
end
|
||||
|
||||
test 'latest changes respects page_file_dir' do
|
||||
get('/gollum/latest_changes')
|
||||
body = last_response.body
|
||||
|
||||
assert !body.include?('Hobbit.md'), 'latest changes with page_file_dir should not log changes to files in root'
|
||||
assert body.include?('Elrond.md'), 'latest changes should log changes in page_file_dir'
|
||||
end
|
||||
|
||||
test 'latest chages should strip off page_file_dir' do
|
||||
get('/gollum/latest_changes')
|
||||
body = last_response.body
|
||||
assert_equal body.include?('<a href="/Rivendell/Elrond.md/'), false
|
||||
assert_equal body.include?('<a href="/Elrond.md/'), true
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
Precious::App.set(:wiki_options, { :page_file_dir => nil})
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user