Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
b5c36e76
Unverified
Commit
b5c36e76
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
jekyll menu
parent
54c9f649
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/communication/website/menu.rb
+16
-0
16 additions, 0 deletions
app/models/communication/website/menu.rb
app/models/communication/website/menu/item.rb
+15
-1
15 additions, 1 deletion
app/models/communication/website/menu/item.rb
with
31 additions
and
1 deletion
app/models/communication/website/menu.rb
+
16
−
0
View file @
b5c36e76
...
...
@@ -21,6 +21,8 @@
# fk_rails_... (university_id => universities.id)
#
class
Communication::Website::Menu
<
ApplicationRecord
include
WithGithub
belongs_to
:university
belongs_to
:website
,
foreign_key: :communication_website_id
has_many
:items
,
class_name:
'Communication::Website::Menu::Item'
,
dependent: :destroy
...
...
@@ -28,9 +30,23 @@ class Communication::Website::Menu < ApplicationRecord
validates
:title
,
:identifier
,
presence:
true
validates
:identifier
,
uniqueness:
{
scope: :communication_website_id
}
after_touch
:publish_to_github
scope
:ordered
,
->
{
order
(
created_at: :asc
)
}
def
to_s
"
#{
title
}
"
end
def
github_path_generated
"_data/menu.yml"
end
def
to_jekyll
website
.
menus
.
map
{
|
menu
|
{
menu
.
identifier
=>
menu
.
items
.
root
.
ordered
.
map
(
&
:to_jekyll_hash
)
}
}.
to_yaml
end
end
This diff is collapsed.
Click to expand it.
app/models/communication/website/menu/item.rb
+
15
−
1
View file @
b5c36e76
...
...
@@ -36,7 +36,7 @@ class Communication::Website::Menu::Item < ApplicationRecord
belongs_to
:university
belongs_to
:website
,
class_name:
'Communication::Website'
belongs_to
:menu
,
class_name:
'Communication::Website::Menu'
belongs_to
:menu
,
class_name:
'Communication::Website::Menu'
,
touch:
true
belongs_to
:parent
,
class_name:
'Communication::Website::Menu::Item'
,
optional:
true
belongs_to
:about
,
polymorphic:
true
,
optional:
true
has_many
:children
,
...
...
@@ -56,6 +56,12 @@ class Communication::Website::Menu::Item < ApplicationRecord
"
#{
title
}
"
end
def
jekyll_target
return
url
if
kind_url?
return
about
&
.
path
if
kind_page?
return
nil
if
kind_blank?
end
def
list_of_other_items
items
=
[]
menu
.
items
.
where
.
not
(
id:
id
).
root
.
ordered
.
each
do
|
item
|
...
...
@@ -65,6 +71,14 @@ class Communication::Website::Menu::Item < ApplicationRecord
items
end
def
to_jekyll_hash
{
'title'
=>
title
,
'target'
=>
jekyll_target
,
'children'
=>
children
.
ordered
.
map
(
&
:to_jekyll_hash
)
}
end
protected
def
set_position
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment