summaryrefslogtreecommitdiff
path: root/app/models/tree.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-20 22:03:20 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-25 11:27:07 -0200
commit1aa82dc4597d5fcdaa0839f804dd688e641cf85c (patch)
tree0a85426818aa819ff7d4b32a6a17cf6bfdb55628 /app/models/tree.rb
parent0f13933175fc5ce4d906bb516a17437aa3fd1e28 (diff)
downloadgitlab-ce-1aa82dc4597d5fcdaa0839f804dd688e641cf85c.tar.gz
Prioritize previewable over plain README filesprioritize-previewable-over-plain-readmes
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r--app/models/tree.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb
index e0e04d8859f..b28f31cdd6e 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -17,12 +17,20 @@ class Tree
def readme
return @readme if defined?(@readme)
- # Take the first previewable readme, or return nil if none is available or
- # we can't preview any of them
- readme_tree = blobs.find do |blob|
- blob.readme? && (previewable?(blob.name) || plain?(blob.name))
+ available_readmes = blobs.select(&:readme?)
+
+ previewable_readmes = available_readmes.select do |blob|
+ previewable?(blob.name)
+ end
+
+ plain_readmes = available_readmes.select do |blob|
+ plain?(blob.name)
end
+ # Prioritize previewable over plain readmes
+ readme_tree = previewable_readmes.first || plain_readmes.first
+
+ # Return if we can't preview any of them
if readme_tree.nil?
return @readme = nil
end