diff options
author | Alex Braha Stoll <alexbrahastoll@gmail.com> | 2016-12-26 20:12:15 -0200 |
---|---|---|
committer | Alex Braha Stoll <alexbrahastoll@gmail.com> | 2016-12-31 16:55:50 -0200 |
commit | c8a1e9682656b6b3ec714e38459e089df2ee106c (patch) | |
tree | 7fb4ce41c0145d8eb6b9d3a38e69b522da076bd7 /app | |
parent | b361a67fb019e5c7f5361bbd3c43545da3ab0288 (diff) | |
download | gitlab-ce-c8a1e9682656b6b3ec714e38459e089df2ee106c.tar.gz |
Change WikiPage.group_by_directory to use WikiDirectory
Diffstat (limited to 'app')
-rw-r--r-- | app/models/wiki_page.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 0e905cb9a00..63e5aa0e519 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -16,12 +16,22 @@ class WikiPage # # pages - an array of WikiPage objects. # - # Returns a hash whose keys are directories and whose values are WikiPage - # arrays. + # Returns an array of WikiPage and WikiDirectory objects. The entries are + # sorted by alphabetical order (directories and pages inside each directory). + # Pages at the root level come before everything. def self.group_by_directory(pages) - return {} if pages.blank? + return [] if pages.blank? + pages.sort_by { |page| [page.directory, page.slug] }. - group_by { |page| page.directory } + group_by { |page| page.directory }. + map do |dir, pages| + if dir == '/' + pages + else + WikiDirectory.new(dir, pages) + end + end. + flatten end def to_key |