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

Précalcul des blocks top (#2507)

* Precompute

* fixes
parent ef5e88f2
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,10 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B
link_to_events
end
def top_link
title_link
end
protected
def link_to_events
......
......@@ -2,6 +2,7 @@ class Communication::Block::Template::Base
include WithAccessibility
include WithData
include WithDependencies
include WithTop
class_attribute :components_descriptions,
:layouts,
......
module Communication::Block::Template::Base::WithTop
extend ActiveSupport::Concern
def top_title
block.try(:title)
end
def top_description
try(:description)
end
def top_link
nil
end
def top_heading
block.heading_rank_base
end
end
......@@ -11,6 +11,10 @@ class Communication::Block::Template::CallToAction < Communication::Block::Templ
has_component :alt, :string
has_component :credit, :rich_text
def top_description
text
end
protected
def check_accessibility
......
......@@ -9,7 +9,7 @@ class Communication::Block::Template::Page < Communication::Block::Template::Bas
:large
]
has_component :mode, :option, options: [:selection, :children]
has_component :text, :rich_text
has_component :text, :rich_text # Deprecated
has_component :page_id, :page
has_component :option_image, :boolean, default: true
......@@ -36,8 +36,23 @@ class Communication::Block::Template::Page < Communication::Block::Template::Bas
selected_pages
end
def top_title
block.title.presence || page_l10n.to_s
end
def top_description
page_l10n.try(:summary)
end
protected
def page_l10n
return nil if page.nil?
l10n = page.localization_for(language)
return nil if l10n.draft?
l10n
end
def selected_pages_selection
elements.map { |element| element.page }.compact
end
......
......@@ -23,6 +23,12 @@ class Communication::Block::Template::Paper < Communication::Block::Template::Ba
selected_papers
end
def top_link
l10n = special_page.localization_for(language)
return nil if l10n.nil?
l10n.hugo(website).permalink
end
protected
def selected_papers_all
......@@ -43,4 +49,8 @@ class Communication::Block::Template::Paper < Communication::Block::Template::Ba
def available_papers
website.research_papers
end
def special_page
@special_page ||= website.special_page(Communication::Website::Page::ResearchPaper)
end
end
......@@ -18,6 +18,20 @@ should_render_data = block.data && block.data.present?
<% end %>
<% if block.html_class.present? %>
html_class: "<%= block.html_class_prepared %>"
<% end %>
top:
<% if block.template.top_title.present? %>
title:
value: >-
<%= prepare_text_for_static block.template.top_title %>
heading: <%= block.template.top_heading %>
<% if block.template.top_link.present? %>
link: "<%= block.template.top_link %>"
<% end %>
<% end %>
<% if block.template.top_description.present? %>
description: >-
<%= prepare_html_for_static block.template.top_description %>
<% end %>
data:
<%= render template_path,
......
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