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

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/navigation.rb54
-rw-r--r--lib/gitlab/navigation/category.rb41
-rw-r--r--lib/gitlab/navigation/doc.rb37
-rw-r--r--lib/gitlab/navigation/section.rb37
4 files changed, 169 insertions, 0 deletions
diff --git a/lib/gitlab/navigation.rb b/lib/gitlab/navigation.rb
new file mode 100644
index 00000000..052cdad5
--- /dev/null
+++ b/lib/gitlab/navigation.rb
@@ -0,0 +1,54 @@
+module Gitlab
+ class Navigation
+ def initialize(items, item)
+ @items = items
+ @item = item
+ end
+
+ def nav_items
+ @nav_items ||= nav_items_exists ? items[nav_items_dir] : items["/_data/default-nav.yaml"]
+ end
+
+ def element_href(element)
+ is_ee_prefixed ? "/ee/#{element.url}" : "/#{dir}/#{element.url}"
+ end
+
+ def show_element?(element)
+ item.path == "/#{dir}/#{element.url}"
+ end
+
+ def id_for(element)
+ element.title.gsub(/[\s\/\(\)]/, '')
+ end
+
+ def optional_ee_badge(element)
+ return unless element.ee_only?
+
+ %[<span class="badges-drop global-nav-badges" data-toggle="tooltip" data-placement="top" title="Available in #{element.ee_tier}"><i class="fa fa-info-circle" aria-hidden="true"></i></span>]
+ end
+
+ def children
+ @children ||= nav_items.fetch(:sections, []).map { |section| Section.new(section) }
+ end
+
+ private
+
+ attr_reader :items, :item
+
+ def dir
+ @dir ||= item.identifier.to_s[%r{(?<=/)[^/]+}]
+ end
+
+ def nav_items_dir
+ @nav_items_dir ||= "/_data/#{dir}-nav.yaml"
+ end
+
+ def nav_items_exists
+ !items[nav_items_dir].nil?
+ end
+
+ def is_ee_prefixed
+ !nav_items_exists && dir != 'ce'
+ end
+ end
+end
diff --git a/lib/gitlab/navigation/category.rb b/lib/gitlab/navigation/category.rb
new file mode 100644
index 00000000..75f401fa
--- /dev/null
+++ b/lib/gitlab/navigation/category.rb
@@ -0,0 +1,41 @@
+module Gitlab
+ class Navigation
+ class Category
+ def initialize(category)
+ @category = category
+ end
+
+ def title
+ category[:category_title]
+ end
+
+ def external_url
+ category[:external_url]
+ end
+
+ def url
+ category[:category_url]
+ end
+
+ def ee_only?
+ category[:ee_only]
+ end
+
+ def ee_tier
+ category[:ee_tier]
+ end
+
+ def has_children?
+ !children.empty?
+ end
+
+ def children
+ @children ||= category.fetch(:docs, []).map { |doc| Doc.new(doc) }
+ end
+
+ private
+
+ attr_reader :category
+ end
+ end
+end
diff --git a/lib/gitlab/navigation/doc.rb b/lib/gitlab/navigation/doc.rb
new file mode 100644
index 00000000..8bed2d43
--- /dev/null
+++ b/lib/gitlab/navigation/doc.rb
@@ -0,0 +1,37 @@
+module Gitlab
+ class Navigation
+ class Doc
+ def initialize(doc)
+ @doc = doc
+ end
+
+ def title
+ doc[:doc_title]
+ end
+
+ def external_url
+ doc[:external_url]
+ end
+
+ def url
+ doc[:doc_url]
+ end
+
+ def ee_only?
+ doc[:ee_only]
+ end
+
+ def ee_tier
+ doc[:ee_tier]
+ end
+
+ def children
+ []
+ end
+
+ private
+
+ attr_reader :doc
+ end
+ end
+end
diff --git a/lib/gitlab/navigation/section.rb b/lib/gitlab/navigation/section.rb
new file mode 100644
index 00000000..8b761fb8
--- /dev/null
+++ b/lib/gitlab/navigation/section.rb
@@ -0,0 +1,37 @@
+module Gitlab
+ class Navigation
+ class Section
+ def initialize(section)
+ @section = section
+ end
+
+ def title
+ section[:section_title]
+ end
+
+ def ee_only?
+ section[:ee_only]
+ end
+
+ def ee_tier
+ section[:ee_tier]
+ end
+
+ def url
+ section[:section_url]
+ end
+
+ def has_children?
+ !children.empty?
+ end
+
+ def children
+ @children ||= section.fetch(:section_categories, []).map { |cat| Category.new(cat) }
+ end
+
+ private
+
+ attr_reader :section
+ end
+ end
+end