Skip to content

Commit b5ca08b

Browse files
committed
framework
1 parent 1135bdf commit b5ca08b

8 files changed

Lines changed: 46 additions & 1 deletion

File tree

app/models/communication/block.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Communication::Block < ApplicationRecord
7171
scope :for_about_type, -> (about_type, language = nil) { where(about_type: about_type) }
7272
scope :for_university, -> (university, language = nil) { where(university: university) }
7373

74+
delegate :dom_count, to: :template
75+
7476
# When we set data from json, we pass it to the template.
7577
# The json we save is first sanitized and prepared by the template.
7678
def data=(value)

app/models/communication/block/template/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def media_blobs
9393
[]
9494
end
9595

96+
def dom_count
97+
1
98+
end
99+
96100
def to_s
97101
self.class.to_s.demodulize
98102
end

app/models/communication/block/template/title.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ def empty?
66
block.title.blank?
77
end
88

9+
def dom_count
10+
count = 2
11+
# TODO collapsed
12+
count += 2 if block.about.show_toc?
13+
count
14+
end
915
end

app/models/communication/website.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Communication::Website < ApplicationRecord
7373
include WithContentArchive
7474
include WithDependencies
7575
include WithDeuxfleurs
76+
include WithDomCount
7677
include WithFeatureAgenda
7778
include WithFeatureAlerts
7879
include WithFeatureAlumni
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Communication::Website::WithDomCount
2+
extend ActiveSupport::Concern
3+
4+
DEFAULT_DOM_COUNT = 250
5+
6+
# L'idée est de fournir un socle correspondant au header et au footer
7+
def dom_count
8+
# TODO count menus
9+
DEFAULT_DOM_COUNT
10+
end
11+
12+
end

app/models/concerns/contentful.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,26 @@ def reset_blocks
5656
about.touch
5757
end
5858

59+
def dom_count
60+
blocks_dom_count + website_dom_count
61+
end
62+
5963
protected
6064

65+
def blocks_dom_count
66+
count = 0
67+
blocks.each do |block|
68+
next if block.empty?
69+
count += block.dom_count
70+
end
71+
count
72+
end
73+
74+
def website_dom_count
75+
websites.first.present? ? websites.first.dom_count
76+
: Communication::Website::DEFAULT_DOM_COUNT
77+
end
78+
6179
def generate_block(hash)
6280
hash[:university] = university
6381
hash[:published] = true unless hash.has_key?(:published)

app/views/admin/communication/blocks/group/_editor.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ reorder_url = reorder_admin_communication_blocks_path(
3232
data-reorder-url="<%= reorder_url %>">
3333
</div>
3434
<%= render 'admin/communication/blocks/group/editor/paste', about: about %>
35-
<%= render 'admin/communication/blocks/group/editor/reset', about: about %>
35+
<%= render 'admin/communication/blocks/group/editor/reset', about: about %>
36+
<%= render 'admin/communication/blocks/group/editor/dom_count', about: about %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= about.dom_count %>

0 commit comments

Comments
 (0)