diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-01-21 03:03:20 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-01-25 16:27:07 +0300 |
commit | 1aa82dc4597d5fcdaa0839f804dd688e641cf85c (patch) | |
tree | 0a85426818aa819ff7d4b32a6a17cf6bfdb55628 /app/models/tree.rb | |
parent | 0f13933175fc5ce4d906bb516a17437aa3fd1e28 (diff) |
Prioritize previewable over plain README files
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r-- | app/models/tree.rb | 16 |
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 |