diff options
author | Vinnie Okada <vokada@mrvinn.com> | 2015-03-21 18:03:35 +0300 |
---|---|---|
committer | Vinnie Okada <vokada@mrvinn.com> | 2015-03-21 18:03:35 +0300 |
commit | f5e65e2e508269ff7c18318526ba01f8e7d83951 (patch) | |
tree | dd834b066dc51de87139d69ea042e0bdfd69334d /app/models/tree.rb | |
parent | cc29ce491786d631586c3b0d0da310b8b790a673 (diff) | |
parent | 6cf189f0a92772b9174f913e7c74a4889d54e9a6 (diff) |
Merge branch 'master' into markdown-tags
Merge updated CHANGELOG entries
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r-- | app/models/tree.rb | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb index 4f5d81f0a5e..f279e896cda 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -1,38 +1,38 @@ class Tree include Gitlab::MarkdownHelper - attr_accessor :entries, :readme, :contribution_guide + attr_accessor :repository, :sha, :path, :entries def initialize(repository, sha, path = '/') path = '/' if path.blank? - git_repo = repository.raw_repository - @entries = Gitlab::Git::Tree.where(git_repo, sha, path) - - 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| - previewable?(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 + + @repository = repository + @sha = sha + @path = path + + git_repo = @repository.raw_repository + @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path) + end + + def readme + return @readme if defined?(@readme) - if contribution_tree = @entries.find(&:contributing?) - contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name) - @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path) + available_readmes = blobs.select(&:readme?) + + if available_readmes.count == 0 + return @readme = nil end + + # Take the first previewable readme, or the first available readme, if we + # can't preview any of them + readme_tree = available_readmes.find do |readme| + previewable?(readme.name) + end || available_readmes.first + + readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) + + git_repo = repository.raw_repository + @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) end def trees |