Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try showing food lists as sentences. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ def current_month
Date::MONTHNAMES[Date.today.month][0,3].downcase
end

helpers do
def to_sentence(list)
list.map! {|i| "<span class='item'>#{i}</span>" }
last_ones = list.pop, list.pop
list.push(last_ones.compact.reverse.join(" and "))
list.join(", ")
end
end

get "/" do
url = "http://api.scraperwiki.com/api/1.0/datastore/sqlite?format=jsondict&name=bbc_seasonal_foods_by_month&query=select%20*%20from%20%60swdata%60"
data = MultiJson.decode(open(url).read).inject({}) { |h, d| h[d["name"]] = d; h }
Expand Down
24 changes: 23 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ ul {
font-size: 0.75em;
}

.in-season, .last-chance, .out-of-season {
.other-foods {
font-size: 1.5em;
}

.other-foods section {
margin-top: 1em;
}

.other-foods section:first-child {
margin-top: 0;
}

.other-foods h2 {
margin-top: 0;
margin-bottom: 0.2em;
}

.other-foods p {
margin: 0;
font-size: 1em;
}

.other-foods .item {
font-style: italic;
}
36 changes: 13 additions & 23 deletions views/publication.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,19 @@
<p>Stuffed Tomatoes: scoop 4lrg toms. Mince insides/shallot/8olives; mix+2c cookedrice/3T mayo&pinenuts/T olvoil/s+p. Fill toms. 20m@400F/200C.</p>
<p class="credit">Recipe from @Cookbook - Maureen Evans, author of Eat Tweet, published by Artisan Books (2010).</p>
</section>
<section class="in-season">
<h2>Also now in season</h2>
<ul>
<% @now_in_season.each do |item| %>
<li><%= item %></li>
<% end %>
</ul>
</section>
<section class="last-chance">
<h2>Last chance to eat</h2>
<ul>
<% @last_chance.each do |item| %>
<li><%= item %></li>
<% end %>
</ul>
</section>
<section class="out-of-season">
<h2>Now out of season</h2>
<ul>
<% @now_out_of_season.each do |item| %>
<li><%= item %></li>
<% end %>
</ul>
<section class="other-foods">
<section class="in-season">
<h2>Also now in season</h2>
<p><%= to_sentence @now_in_season %></p>
</section>
<section class="last-chance">
<h2>Last chance to eat</h2>
<p><%= to_sentence @last_chance %></p>
</section>
<section class="out-of-season">
<h2>Now out of season</h2>
<p><%= to_sentence @now_out_of_season %></p>
</section>
</section>
</div>
</div>
Expand Down