Skip to content

Commit 87505f0

Browse files
Changed name of event.html to recent_events_section.html.
Changed name of events_page.html to events_array_generator.html. Used new includes (function style) to simplify code in footer for sponsors displaying. Created layouts for repetitive code: - footer_sponsors_inner_layout.html - recent_event_inner_layout.html - sponsors_inner_layout.html Used new includes (function style) to simplify code in inline_style_index.html for future events accessing. Created function like includes: - row_display_outer_loop.html - to generate 2 items per row automatically from an array of objects passed in. - events_array_generator.html - to generate post object arrays automatically with future / past and post limits as parameters. Added test code suing the new function like includes in events page to see if object attributes are properly accessed. Modified sponsors column class in upcoming event in index.html (to center content properly). Used new includes (function style) to simplify code in index.html for listing sponsors in upcoming section and changed the include name for the recent events section to match file name change mentioned above.
1 parent c331422 commit 87505f0

13 files changed

+154
-195
lines changed

_includes/event.html

-71
This file was deleted.

_includes/events_array_generator.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% comment %}
2+
This include is to generate a list of posts for use in views.
3+
The array posts is to be used then in the view.
4+
Parameters:
5+
- future_events: (bool) Include future events in the array?
6+
If future_events is true, no past events will be added.
7+
If it is false, only past events are added.
8+
Default: false.
9+
- limit: (int) How many events to add to the array.
10+
Default: 0 (no limit).
11+
Creates variable for use in the outer scope:
12+
- posts (array) Array of post objects.
13+
{% endcomment %}
14+
15+
{% if include.future_events %}
16+
{% assign future_events = include.future_events %}
17+
{% else %}
18+
{% assign future_events = false %}
19+
{% endif %}
20+
{% if include.limit %}
21+
{% assign limit = include.limit %}
22+
{% endif %}
23+
24+
{% assign post_count = 0 %}
25+
{% assign curDate = site.time | date: "%s" %}
26+
{% assign posts = "" | split: ',' %}
27+
{% for post in site.posts %}
28+
{% assign postStartDate = post.date | date: "%s" %}
29+
{% if future_events %}
30+
<!--Add only future post-->
31+
{% if postStartDate >= curDate %}
32+
{% assign posts = posts | push: post %}
33+
{% assign post_count = post_count | plus: 1 %}
34+
{% endif %}
35+
<!--Add only past post-->
36+
{% else %}
37+
{% if postStartDate < curDate %}
38+
{% assign posts = posts | push: post %}
39+
{% assign post_count = post_count | plus: 1 %}
40+
{% endif %}
41+
{% endif %}
42+
43+
{% if post_count == limit | default: 0 %}
44+
{% break %}
45+
{% endif %}
46+
{% endfor %}
47+

_includes/events_page.html

-42
This file was deleted.

_includes/footer.html

+6-34
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,19 @@ <h2 class="footer__section-title">Find Us Online</h2>
99
<div class="col-md-6">
1010
<h2 class="footer__section-title">Our Sponsors</h2>
1111
<hr class="footer__divider">
12-
{% comment %}
13-
Assume number of sponsors is even. We are going to create rows of 2 sponsors in each.
14-
If not even the last row must contain 1 sponsor and be terminated with appropriate tags.
15-
{% endcomment %}
16-
12+
<!--Create an array of permanent sponsors-->
1713
{% assign sponsors = "" | split: ',' %}
1814
{% for sponsor in site.sponsors %}
1915
{% if sponsor.permanent %}
2016
{% assign sponsors = sponsors | push: sponsor %}
2117
{% endif %}
2218
{% endfor %}
23-
{% assign num_of_sponsors = sponsors | size %}
24-
{% assign sponsors_remainder = num_of_sponsors | modulo: 2 %}
25-
26-
{% if sponsors_remainder == 0 %}
27-
{% assign num_of_sponsors_even = true %}
28-
{% assign row_num_modifier = 1 %}
29-
{% else %}
30-
{% assign num_of_sponsors_even = false %}
31-
{% assign row_num_modifier = 0 %}
32-
{% endif %}
33-
34-
{% assign num_of_rows = num_of_sponsors | divided_by: 2 | floor | minus: row_num_modifier %}
35-
{% assign items_per_row = 1 %}
3619

37-
{% for row in (0..num_of_rows) %}
38-
{% if forloop.last and num_of_sponsors_even == false %}
39-
{% assign items_per_row = 0 %}
40-
{% endif %}
41-
<div class="row">
42-
{% for col in (0..items_per_row) %}
43-
{% assign sponsor_index = row | times: 2 | plus: col %}
44-
{% assign sponsor = sponsors[sponsor_index] %}
45-
<div class="footer__sponsor-col col-md-12 col-lg-6">
46-
<a class="footer__sponsor-link" href="{{ sponsor.sponsor_link }}">
47-
<img class="footer__img" src="{{ site.baseurl }}/{{ sponsor.sponsor_logo }}">
48-
</a>
49-
</div>
50-
{% endfor %}
51-
</div>
52-
{% endfor %}
20+
{%
21+
include row_display_outer_loop.html
22+
items_array = sponsors
23+
inner_layout = "footer_sponsors_inner_layout.html"
24+
%}
5325
</div>
5426
<div class="col-md-3">
5527
<h2 class="footer__section-title">Python Sprints</h2>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="footer__sponsor-col col-md-12 col-lg-6">
2+
<a class="footer__sponsor-link" href="{{ include.item.sponsor_link }}">
3+
<img class="footer__img" src="{{ site.baseurl }}/{{ include.item.sponsor_logo }}">
4+
</a>
5+
</div>

_includes/inline_style_index.html

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
<!--Create array of future events-->
2-
{% assign upcoming_events = "" | split: ',' %}
3-
{% assign curDate = site.time | date: "%s" %}
4-
{% for post in site.posts %}
5-
{% assign postStartDate = post.date | date: "%s" %}
6-
{% if postStartDate >= curDate %}
7-
{% assign upcoming_events = upcoming_events | push: post %}
8-
{% endif %}
9-
{% endfor %}
10-
{% if upcoming_events.size > 0 %}
1+
{% include events_array_generator.html future_events = true %}
2+
{% if posts.size > 0 %}
113
{% assign upcoming_event = true %}
12-
{% assign post = upcoming_events | last %}
4+
{% assign post = posts | last %}
135

146
{% if post.image %}
157
{% assign image = post.image %}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="no-gutters__col col-sm-6">
2+
<div class="events__spacer"></div>
3+
<div class="events__img-container">
4+
<div class="events__img-overlay">
5+
<a class="events__link" href="{{ include.item.url }}">
6+
<i class="events__icon fas fa-external-link-square-alt"></i>
7+
</a>
8+
<div class="events__title-container">
9+
<h2 class="events__img-title">Event: {{ include.item.title }}</h2>
10+
<p class="events__img-subtitle">{{ include.item.venue }}, {{ include.item.date | date: "%e %B %Y" }}</p>
11+
</div>
12+
</div>
13+
<img class="events__img img-fluid" src="{{ site.baseurl }}/{{ include.item.image }}">
14+
</div>
15+
</div>

_includes/recent_events_section.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<section class="events">
2+
<div class="container-fluid">
3+
<div class="row">
4+
<div class="col-md-12">
5+
<h2 class="section-title">Recent Events</h2>
6+
</div>
7+
</div>
8+
{% include events_array_generator.html limit = 4 %}
9+
{%
10+
include row_display_outer_loop.html
11+
items_array = posts
12+
inner_layout = "recent_event_inner_layout.html"
13+
%}
14+
</div>
15+
</section>

_includes/row_display_outer_loop.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% comment %}
2+
This include is to easily pass an array to iterate over its items and
3+
a html layout to the generate 2 items per row look in the view.
4+
Parameters:
5+
- items_array: (array) Array of objects we want to show.
6+
- inner_layout: (string) Path to the html inner layout.
7+
{% endcomment %}
8+
9+
{% assign num_of_items = include.items_array | size %}
10+
{% assign items_array_remainder = num_of_items | modulo: 2 %}
11+
12+
{% if items_array_remainder == 0 %}
13+
{% assign num_of_items_even = true %}
14+
{% assign row_num_modifier = 1 %}
15+
{% else %}
16+
{% assign num_of_items_even = false %}
17+
{% assign row_num_modifier = 0 %}
18+
{% endif %}
19+
20+
{% assign num_of_rows = num_of_items | divided_by: 2 | floor | minus: row_num_modifier %}
21+
{% assign items_per_row = 1 %}
22+
23+
{% for row in (0..num_of_rows) %}
24+
{% if forloop.last and num_of_items_even == false %}
25+
{% assign items_per_row = 0 %}
26+
{% endif %}
27+
<div class="row">
28+
{% for col in (0..items_per_row) %}
29+
{% assign item_index = row | times: 2 | plus: col %}
30+
{% assign item = include.items_array[item_index] %}
31+
{% include {{ include.inner_layout }} item = item %}
32+
{% endfor %}
33+
</div>
34+
{% endfor %}

_includes/sponsors_inner_layout.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="footer__sponsor-col col-md-12 col-lg-6">
2+
<a class="footer__sponsor-link" href="{{ include.item.sponsor_link }}">
3+
<img class="footer__img"
4+
src="{{ site.baseurl }}/{{ include.item.sponsor_logo }}"
5+
alt="Sponsor logo">
6+
</a>
7+
</div>

_pages/03_events.html

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ <h2 class="events-page__page-subtitle">See what's coming up and what we did rece
3232
<div class="row">
3333
<div class="col-12">
3434
<h2 class="events-page__upcoming-title">Upcoming Events</h2>
35+
{% include events_array_generator.html future_events = true %}
36+
{% for post in posts %}
37+
<p>{{ post.title }}</p>
38+
{% endfor %}
3539
</div>
3640
</div>
3741
</div>
@@ -40,6 +44,10 @@ <h2 class="events-page__upcoming-title">Upcoming Events</h2>
4044
<div class="row">
4145
<div class="col-12">
4246
<h2 class="events-page__recent-title">Recent Events</h2>
47+
{% include events_array_generator.html %}
48+
{% for post in posts %}
49+
<p>{{ post.title }}</p>
50+
{% endfor %}
4351
</div>
4452
</div>
4553
</div>

_sass/style.scss

+6
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ a {
317317
margin-bottom: 0.5em;
318318
}
319319

320+
.upcoming__sponsor-col {
321+
background: rgba(7, 41, 72, 0.52);
322+
border: $dark-blue 2px groove;
323+
border-radius: 0 5px 5px 5px;
324+
}
325+
320326
.upcoming__img-container {
321327
background-size: cover;
322328
background-position: center center;

0 commit comments

Comments
 (0)