Skip to content
Snippets Groups Projects
Unverified Commit b5c36e76 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

jekyll menu

parent 54c9f649
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment