Moved todo due date to helper method

This commit is contained in:
Phil Hughes 2016-10-03 09:58:55 +01:00
parent a3abfb9708
commit 8ea18c3761
2 changed files with 8 additions and 9 deletions

View File

@ -115,9 +115,14 @@ module TodosHelper
end
def todo_due_date(todo)
is_due_today = todo.target.due_date.try(:today?)
return unless todo.target.try(:due_date)
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
is_due_today = todo.target.due_date.try(:today?)
is_overdue = todo.target.try(:overdue?)
content_tag :span, class: [('text-warning' if is_due_today), ('text-danger' if is_overdue)] do
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
end
end
private

View File

@ -19,13 +19,7 @@
(removed)
· #{time_ago_with_tooltip(todo.created_at)}
- if todo.target.try(:due_date)
- is_due_today = todo.target.due_date.try(:today?)
- is_overdue = todo.target.try(:overdue?)
·
%span{ class: [('text-warning' if is_due_today), ('text-danger' if is_overdue)] }
= todo_due_date(todo)
· #{todo_due_date(todo)}
.todo-body
.todo-note