Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-01 00:06:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-01 00:06:28 +0300
commit8f210aebe1d740e8ee194f171f1f33a6e1fba313 (patch)
treef43c545801bb96fd0737f18493fb30ab92972627 /app/models/wiki_directory.rb
parent996f700997805b3590da8d8afdd19d193989078a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/wiki_directory.rb')
-rw-r--r--app/models/wiki_directory.rb63
1 files changed, 4 insertions, 59 deletions
diff --git a/app/models/wiki_directory.rb b/app/models/wiki_directory.rb
index 6c86c11e7fb..712ba79bbd2 100644
--- a/app/models/wiki_directory.rb
+++ b/app/models/wiki_directory.rb
@@ -1,75 +1,20 @@
# frozen_string_literal: true
class WikiDirectory
- include StaticModel
include ActiveModel::Validations
attr_accessor :slug, :pages
validates :slug, presence: true
- # StaticModel overrides and configuration:
-
- def self.primary_key
- 'slug'
- end
-
- def id
- "#{slug}@#{last_version&.sha}"
- end
-
- def self.model_name
- ActiveModel::Name.new(self, nil, 'wiki_dir')
- end
-
- alias_method :to_param, :slug
- alias_method :title, :slug
-
- # Sorts and groups pages by directory.
- #
- # pages - an array of WikiPage objects.
- #
- # Returns an array of WikiPage and WikiDirectory objects.
- # The entries are sorted in the order of the input array, where
- # directories appear in the position of their first member.
- def self.group_by_directory(pages)
- grouped = []
- dirs = Hash.new do |h, k|
- new(k).tap { |dir| grouped << (h[k] = dir) }
- end
-
- Array.wrap(pages).each_with_object(grouped) do |page, top_level|
- group = page.directory.present? ? dirs[page.directory] : top_level
-
- group << page
- end
- end
-
def initialize(slug, pages = [])
@slug = slug
@pages = pages
end
- def <<(page)
- @pages << page
- @last_version = nil
- end
-
- def last_version
- @last_version ||= @pages.map(&:last_version).max_by(&:authored_date)
- end
-
- def page_count
- @pages.size
- end
-
- def empty?
- page_count.zero?
- end
-
- def to_partial_path(context = nil)
- name = [context, 'wiki_directory'].compact.join('_')
-
- "projects/wiki_directories/#{name}"
+ # Relative path to the partial to be used when rendering collections
+ # of this object.
+ def to_partial_path
+ 'projects/wikis/wiki_directory'
end
end