Skip to content

Commit

Permalink
Very crude first pass at home page
Browse files Browse the repository at this point in the history
Just a list of "Hot" events and partners.

Also some random keywords
  • Loading branch information
ivankocienski committed Sep 23, 2024
1 parent b1263d8 commit 0b78d2c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
class HomeController < ApplicationController

def root
hot_partners = Partner.order('random()').limit(10)

hot_events = EventInstance
.from_day_onward(Time.now)
.order('random()')
.limit(10)

@hot_feed = (hot_events + hot_partners).shuffle

@hot_keywords = Keyword
.joins(:partner_keywords)
.group(:partner_id)
.having("count(partner_id) > 0")
.order('random()')
.limit(10)
end

def about
Expand Down
58 changes: 58 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
module HomeHelper

def _render_partner_thing(partner)
link = link_to(partner.name, partner_path(partner))

"<div class='partner'>" +
"<h2>#{link}</h2>" +
"<p>#{partner.summary}</p>" +
"</div>"
end

def _render_keyword_thing(keyword)
link = link_to(keyword.name, partners_path(keyword: keyword.name))

"<div class='keyword'>" +
"<h2>#{link} (#{keyword.partner_keywords.count})</h2>" +
"</div>"
end

def _render_event_thing(event_instance)
event = event_instance.event

link = link_to(event.name, event_path(event_instance))
"<div class='event'>" +
"<h2>#{link}</h2>" +
"<p>#{event.summary}</p>" +
"</div>"
end

def render_hot_feed(feed)
html_chunks = @hot_feed.map do |hot_thing|
case hot_thing
when Keyword then _render_keyword_thing(hot_thing)
when Partner then _render_partner_thing(hot_thing)
when EventInstance then _render_event_thing(hot_thing)
else
raise "Unknown hot_thing: #{hot_thing.class}"
end
end

html_chunks
# .map { |chunk| "#{chunk}</p>" }
.join("\n<br />\n")
.html_safe

end

def render_hot_keywords(keywords)
keywords
.map { |kw|
link = link_to(kw.name,
partners_path(keyword: kw.name),
class: 'keyword')
"#{link} (#{kw.partner_keywords.count})"
}
.join(' &bull; ')
.html_safe
end
# lordy this isn't very testable, lol
end
7 changes: 6 additions & 1 deletion app/views/home/root.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
%h1 Event Site Project
%h1 Event Site

.hot-keywords= render_hot_keywords(@hot_keywords)
%br

.hot-feed= render_hot_feed(@hot_feed)

0 comments on commit 0b78d2c

Please sign in to comment.