Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amélioration du plan de document #1405

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions app/models/communication/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
class Communication::Block < ApplicationRecord
include AsIndirectObject
include WithAccessibility
include WithHeadingRanks
include WithPosition
include WithUniversity
include Sanitizable

IMAGE_MAX_SIZE = 5.megabytes
FILE_MAX_SIZE = 100.megabytes
DEFAULT_HEADING_LEVEL = 2 # h1 is the page title

belongs_to :about, polymorphic: true
belongs_to :heading, optional: true
Expand Down Expand Up @@ -153,11 +153,6 @@ def full_text
template.full_text
end

def heading_level
heading.present? ? heading.level + 1
: DEFAULT_HEADING_LEVEL
end

def to_s
title.blank? ? "#{Communication::Block.model_name.human} #{position}"
: "#{title}"
Expand Down
27 changes: 27 additions & 0 deletions app/models/communication/block/with_heading_ranks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Communication::Block::WithHeadingRanks
extend ActiveSupport::Concern

DEFAULT_HEADING_LEVEL = 2 # h1 is the page title

def heading_rank_self
title.present? ? heading_rank_base
: false
end

def heading_rank_children
return false unless heading_children?
heading_rank_self ? heading_rank_self + 1
: heading_rank_base
end

def heading_children?
template.respond_to?(:elements) && template.elements.any?
end

protected

def heading_rank_base
heading.present? ? heading.level + 1
: DEFAULT_HEADING_LEVEL
end
end
6 changes: 5 additions & 1 deletion app/views/admin/communication/blocks/_static.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ should_render_data = block.data && block.data.present?
title: >-
<%= prepare_text_for_static block.title %>
position: <%= block.position %>
heading_level: <%= block.heading_level %>
ranks:
self: <%= block.heading_rank_self %>
<% if block.heading_children? %>
children: <%= block.heading_rank_children %>
<% end %>
data:
<%= render template_path,
block: block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: >-
<%= prepare_text_for_static heading.title %>
position: <%= heading.position %>
level: <%= heading.level %>
rank: <%= heading.level %>
<% heading.blocks.published.ordered.each do |block| %>
<%= render 'admin/communication/blocks/static', block: block %>
<% end %>
Expand Down
Loading