Permalink
Browse files

adding school pdf, fixing ordering of events

  • Loading branch information...
1 parent 22fa62c commit 698e3ad035ae0fab67169bb4feef1b0f1fbc6e9f @adamico committed Mar 30, 2012
@@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
+Mime::Type.register "application/pdf", :pdf
@@ -13,12 +13,20 @@ def index
def show
@school = School.imminent_or_next
- events = @school.events
+ events = @school.events.order(:starts_at)
@events_days = events.group_by { |event| event.starts_at.beginning_of_day }
- # you can use meta fields from your model instead (e.g. browser_title)
- # by swapping @page for @school in the line below:
- present(@page)
+ respond_to do |format|
+ format.html do
+ present(@page)
+ end
+ format.pdf do
+ pdf = SchoolPdf.new(@school, view_context, @events_days)
+ send_data pdf.render, filename: "#{@school.short_title}_program.pdf",
+ type: "application/pdf",
+ disposition: "inline"
+ end
+ end
end
protected
@@ -0,0 +1,35 @@
+class SchoolPdf < Prawn::Document
+ def initialize(school, view, events_days)
+ super(top_margin: 70)
+ @school = school
+ @view = view
+ @events_days = events_days
+ page_header
+ event_list
+ end
+
+ def page_header
+ text @school.title, size: 24, style: :bold
+ move_down 20
+ text @school.theme, size: 24, style: :bold
+ move_down 10
+ text @school.when_and_where
+ end
+
+ def event_list
+ @events_days.each do |day, events|
+ move_down 10
+ text day.strftime("%A %e"), style: :bold
+ table event_rows(events) do
+ self.row_colors = ["DDDDDD", "FFFFFF"]
+ end
+ end
+ end
+
+ def event_rows(events)
+ [] +
+ events.map do |event|
+ [event.time, event.title.gsub(/<\/?[^>]*>/, "")]
+ end
+ end
+end
@@ -50,13 +50,11 @@
</div>
<% end -%>
</div>
- <% if Rails.env.development? %>
- <% end -%>
<% else %>
No programmed events yet.
<% end -%>
</div>
- <p id="print_program">Placeholder for print programme link</p>
+ <p id="print_program"><%= link_to "Printable Program", refinery.schools_school_path(@school, format: "pdf") %></p>
<% end %>
<% else %>
Coming soon.

0 comments on commit 698e3ad

Please sign in to comment.