Skip to content
Snippets Groups Projects
Unverified Commit 56ffd2d5 authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Vrai nettoyage des ranks (#2505)

* Clean

* children

* fake
parent 4d936de5
No related branches found
No related tags found
No related merge requests found
...@@ -24,15 +24,7 @@ class Communication::Block::Template::Contact < Communication::Block::Template:: ...@@ -24,15 +24,7 @@ class Communication::Block::Template::Contact < Communication::Block::Template::
has_elements has_elements
def has_emails? def socials
emails.any?(&:present?)
end
def has_phone_numbers?
phone_numbers.any?(&:present?)
end
def has_socials?
[ [
social_mastodon, social_mastodon,
social_x, social_x,
...@@ -44,7 +36,25 @@ class Communication::Block::Template::Contact < Communication::Block::Template:: ...@@ -44,7 +36,25 @@ class Communication::Block::Template::Contact < Communication::Block::Template::
social_facebook, social_facebook,
social_tiktok, social_tiktok,
social_github social_github
].any?(&:present?) ].compact_blank
end
# We fake children presence.
# This is used by the ranks, so we have ranks.children
# https://github.com/osunyorg/admin/pull/2505
def children
[true]
end end
def has_emails?
emails.any?(&:present?)
end
def has_phone_numbers?
phone_numbers.any?(&:present?)
end
def has_socials?
socials.any?(&:present?)
end
end end
module Communication::Block::WithHeadingRanks module Communication::Block::WithHeadingRanks
extend ActiveSupport::Concern extend ActiveSupport::Concern
DEFAULT_HEADING_LEVEL = 2 # h1 is the page title # h1 is the page title
DEFAULT_HEADING_LEVEL = 2
def heading_rank_self # Title is the block intrinsic title
title.present? ? heading_rank_base : DEFAULT_HEADING_LEVEL # Not to be confused with `block_title``
def heading_self?
title.present?
end end
def heading_rank_children # Self rank is used for the title (h2 if root, h3 if below a title)
return false unless heading_children? def heading_rank_self
heading_rank_self ? heading_rank_self + 1 : heading_rank_base # No title, no rank self
return false unless heading_self?
# Otherwise, rank base
# Example:
# - title h2 (root)
# - title h3 (below a title block)
heading_rank_base
end end
def heading_children? def heading_children?
template.children && template.children.any? template.children && template.children.any?
end end
# Rank children is used for the block's children heading
def heading_rank_children
# If a block has no children, then no rank children
return false unless heading_children?
# If there's no heading rank self, we take the base rank
# Example:
# - No title, children h2 (root)
# - No title, children h3 (below a title block)
return heading_rank_base if heading_rank_self == false
# Otherwise, it's the rank self + 1
# Example:
# - title h2, children h3 (root)
# - title h3, children h4 (below a title block)
heading_rank_self + 1
end
protected protected
# If a block is root, it will have level 2
# If a block is below a title block, it will have level 3
# Not real yet: if a block is below a subtitle, it will have level 4
# There are no subtitles at the moment, so it's all between 2 and 3
def heading_rank_base def heading_rank_base
block_title.present? ? block_title.heading_rank_self + 1 : DEFAULT_HEADING_LEVEL if block_title.present?
# We delegate the rank computing to the block title, and we add 1
block_title.heading_rank_self + 1
else
# If the about has a block base (Education::Program::Localization), we use it
# Otherwise, default level (2)
about.try(:blocks_heading_rank_base) || DEFAULT_HEADING_LEVEL
end
end end
# A block can belong to a title, meaning it is below the title # A block can belong to a title, meaning it is below the title
......
...@@ -115,6 +115,10 @@ class Education::Program::Localization < ApplicationRecord ...@@ -115,6 +115,10 @@ class Education::Program::Localization < ApplicationRecord
[parent] [parent]
end end
def blocks_heading_rank_base
3
end
def best_featured_image_source(fallback: true) def best_featured_image_source(fallback: true)
return self if featured_image.attached? return self if featured_image.attached?
best_source = parent&.best_featured_image_source(fallback: false) best_source = parent&.best_featured_image_source(fallback: false)
......
...@@ -9,7 +9,9 @@ should_render_data = block.data && block.data.present? ...@@ -9,7 +9,9 @@ should_render_data = block.data && block.data.present?
slug: >- slug: >-
<%= block.slug %> <%= block.slug %>
ranks: ranks:
<% if block.heading_self? %>
self: <%= block.heading_rank_self %> self: <%= block.heading_rank_self %>
<% end %>
<% if block.heading_children? %> <% if block.heading_children? %>
children: <%= block.heading_rank_children %> children: <%= block.heading_rank_children %>
<% end %> <% end %>
......
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