diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-11 10:50:56 +0400 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-11 10:50:56 +0400 |
commit | 99eb283101108f1f95e95ade8c1352f547578b26 (patch) | |
tree | ed682bc2303d6862af4f2dbd5dd764d7c1e36f31 /app/models/tree.rb | |
parent | 0e3f8ea2ef2a7d6cc51ccb5d7ae854c6244b40eb (diff) |
Use readme we support to render if there are multiple readmes
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r-- | app/models/tree.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb index ac2183be44b..5bb1f3cdaf4 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -6,7 +6,24 @@ class Tree git_repo = repository.raw_repository @entries = Gitlab::Git::Tree.where(git_repo, sha, path) - if readme_tree = @entries.find(&:readme?) + available_readmes = @entries.select(&:readme?) + + if available_readmes.count > 0 + # If there is more than 1 readme in tree, find readme which is supported + # by markup renderer. + if available_readmes.length > 1 + supported_readmes = available_readmes.select do |readme| + Gitlab::MarkdownHelper.gitlab_markdown?(readme.name) || + Gitlab::MarkdownHelper.markup?(readme.name) + end + + # Take the first supported readme, or the first available readme, if we + # don't support any of them + readme_tree = supported_readmes.first || available_readmes.first + else + readme_tree = available_readmes.first + end + readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) end |