Cleaning up code

This commit is contained in:
echarp 2015-12-08 00:43:26 +01:00
parent 3cbbad9328
commit 34114bcdea
3 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,6 @@
# Resume of all events over a period of time # A digest of all events over a period of time
class DigestsController < ApplicationController class DigestsController < ApplicationController
has_scope :moderated, default: nil, allow_blank: true
has_scope :region, :locality, :tag has_scope :region, :locality, :tag
has_scope :period, allow_blank: true, has_scope :period, allow_blank: true,
type: :hash, using: [:year, :week], type: :hash, using: [:year, :week],
@ -22,6 +23,6 @@ class DigestsController < ApplicationController
def set_events def set_events
@week ||= Time.zone.today + 7.days @week ||= Time.zone.today + 7.days
@events = apply_scopes Event.moderated @events = apply_scopes Event
end end
end end

View File

@ -30,8 +30,8 @@ class Event < ActiveRecord::Base
after_update EventCallbacks after_update EventCallbacks
after_destroy EventCallbacks after_destroy EventCallbacks
scope :moderated, -> { where moderated: true } scope :moderated, ->(*) { where moderated: true }
scope :unmoderated, -> { where moderated: false } scope :unmoderated, ->(*) { where moderated: false }
scope :last_year, -> { where '? <= end_time', 1.year.ago } scope :last_year, -> { where '? <= end_time', 1.year.ago }
scope :past, -> { where 'start_time <= ?', Time.zone.now } scope :past, -> { where 'start_time <= ?', Time.zone.now }
scope :future, -> { where '? <= end_time', Time.zone.now } scope :future, -> { where '? <= end_time', Time.zone.now }

View File

@ -14,16 +14,17 @@
\===== \=====
- @events.sort_by(&:start_time).each do |event| - @events.sort_by(&:start_time).each do |event|
- @event = event [#{event.city}] [#{event.title}](#{event_url event}) - #{display_date event}
\## [#{event.city}] [#{event.title}](#{event_url event}) - #{display_date} \-----
- lines = strip_tags(@event.description).split(/\r\n/).reject(&:blank?)
- lines = strip_tags(event.description).split(/\r\n/).reject(&:blank?)
- lines[0..2].each do |p| - lines[0..2].each do |p|
= p = p
\ \
* #{[@event.place_name, event.full_address].compact.join ', '} * #{[event.place_name, event.full_address].compact.join ', '}
* #{Event.human_attribute_name :url}: #{link_to @event.url, @event.url} * #{Event.human_attribute_name :url}: #{link_to event.url, event.url}
* #{Event.human_attribute_name :tags}: * #{Event.human_attribute_name :tags}:
#{@event.tags.split.collect { |tag| "[#{tag}](#{tag_url tag})" }.join ', '} #{event.tags.split.collect { |tag| "[#{tag}](#{tag_url tag})" }.join ', '}
\ \
%h1= title %h1= title