Skip to content
Snippets Groups Projects
Commit 7acd21bb authored by Arnaud Levy's avatar Arnaud Levy
Browse files

refactor

parent ddb6861a
No related branches found
No related tags found
No related merge requests found
......@@ -4,14 +4,8 @@ class Communication::Block::Template::Gallery < Communication::Block::Template
end
def images_with_alt
unless @images_with_alt
@images_with_alt = []
elements.each do |element|
@images_with_alt << image_with_alt(element)
end
@images_with_alt.compact!
end
@images_with_alt
@images_with_alt ||= elements.map { |element| image_with_alt(element) }
.compact
end
protected
......
......@@ -7,18 +7,8 @@ class Communication::Block::Template::OrganizationChart < Communication::Block::
end
def persons_with_role
unless @persons_with_role
@persons_with_role = []
elements.each do |element|
person = block.university.people.find_by id: element['id']
next if person.nil?
@persons_with_role << {
person: person,
role: element['role']
}.to_dot
end
end
@persons_with_role
@persons_with_role ||= elements.map { |element| person_with_role(element) }
.compact
end
protected
......@@ -26,4 +16,13 @@ class Communication::Block::Template::OrganizationChart < Communication::Block::
def persons
@persons ||= persons_with_role.map { |hash| hash[:person] }
end
def person_with_role(element)
person = block.university.people.find_by id: element['id']
return if person.nil?
{
person: person,
role: element['role']
}.to_dot
end
end
......@@ -5,50 +5,37 @@ class Communication::Block::Template::Partner < Communication::Block::Template
end
def partners
unless @partners
@partners = []
elements.each do |element|
# Init to have easy tests in the views and dependencies
element['organization'] = nil
element['blob'] = nil
if element['id']
organization = university.organizations.find_by id: element['id']
if organization
element['organization'] = organization
element['name'] = organization.to_s
element['url'] = organization.url
element['blob'] = organization.logo&.blob
end
else
element['blob'] = find_blob element, 'logo'
end
@partners << element.to_dot
end
end
@partners
@partners ||= elements.map { |element| partner(element) }
.compact
end
protected
def organizations
unless @organizations
@organizations = []
partners.each do |partner|
next if partner.organization.nil?
@organizations << partner.organization
end
end
@organizations
@organizations ||= partners.map { |partner| partner.organization }
.compact
end
def blobs
unless @blobs
@blobs = []
partners.each do |partner|
next if partner.blob.nil?
@blobs << partner.blob
@blobs ||= partners.map { |partner| partner.blob }
.compact
end
def partner(element)
# Init to have easy tests in the views and dependencies
element['organization'] = nil
element['blob'] = nil
if element['id']
organization = university.organizations.find_by id: element['id']
if organization
element['organization'] = organization
element['name'] = organization.to_s
element['url'] = organization.url
element['blob'] = organization.logo&.blob
end
else
element['blob'] = find_blob element, 'logo'
end
@blobs
element.to_dot
end
end
......@@ -27,12 +27,8 @@ class Communication::Block::Template::Post < Communication::Block::Template
end
def free_posts
array = []
elements.map do |element|
array << post(element['id'])
end
array.compact!
array
elements.map { |element| post(element['id']) }
.compact
end
def post(id)
......
......@@ -4,22 +4,20 @@ class Communication::Block::Template::Testimonial < Communication::Block::Templa
end
def testimonials
@testimonials ||= elements.map do |element|
blob = find_blob element, 'photo'
element['blob'] = blob
element.to_dot
end
@testimonials ||= elements.map { |element| testimonial(element) }
.compact
end
protected
def photos
unless @photos
@photos = []
testimonials.each do |testimonial|
@photos << testimonial.blob if testimonial.blob
end
end
@photos
@photos ||= testimonials.map { |testimonial| testimonial.blob }
.compact
end
def testimonial(element)
blob = find_blob element, 'photo'
element['blob'] = blob
element.to_dot
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