implement snippets lifetime

This commit is contained in:
Nihad Abbasov 2011-10-27 11:46:21 +05:00
parent 117d1e90fd
commit 8e1e17763f
5 changed files with 50 additions and 29 deletions

View file

@ -1,2 +1,11 @@
module SnippetsHelper
def snippet_lifetime_select_options
options = [
['forever', nil],
['1 day', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.day],
['1 week', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.week],
['1 month', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.month]
]
options_for_select(options)
end
end

View file

@ -33,6 +33,10 @@ class Snippet < ActiveRecord::Base
def colorize
system_colorize(content, file_name)
end
def expired?
expires_at && expires_at < Time.current
end
end
# == Schema Information
#

View file

@ -12,6 +12,9 @@
%tr
%td= f.label :file_name
%td= f.text_field :file_name, :placeholder => "example.rb"
%tr
%td= f.label "Lifetime"
%td= f.select :expires_at, snippet_lifetime_select_options
%tr
%td{:colspan => 2}
= f.label :content, "Code"

View file

@ -1,3 +1,4 @@
- unless snippet.expired?
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
%td
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"

View file

@ -1,3 +1,4 @@
- if !@snippet.expired?
%h2
= "Snippet ##{@snippet.id} - #{@snippet.title}"
@ -20,3 +21,6 @@
.clear
- else
%h2
Sorry, this snipped is no longer exists