Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
8e1e1776
Commit
8e1e1776
authored
Oct 27, 2011
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement snippets lifetime
parent
117d1e90
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
29 deletions
+50
-29
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+9
-0
app/models/snippet.rb
app/models/snippet.rb
+4
-0
app/views/snippets/_form.html.haml
app/views/snippets/_form.html.haml
+3
-0
app/views/snippets/_snippet.html.haml
app/views/snippets/_snippet.html.haml
+12
-11
app/views/snippets/show.html.haml
app/views/snippets/show.html.haml
+22
-18
No files found.
app/helpers/snippets_helper.rb
View file @
8e1e1776
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
app/models/snippet.rb
View file @
8e1e1776
...
...
@@ -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
#
...
...
app/views/snippets/_form.html.haml
View file @
8e1e1776
...
...
@@ -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"
...
...
app/views/snippets/_snippet.html.haml
View file @
8e1e1776
%tr
{
:id
=>
dom_id
(
snippet
),
:class
=>
"snippet"
,
:url
=>
project_snippet_path
(
@project
,
snippet
)
}
-
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;"
=
truncate
snippet
.
author
.
name
,
:lenght
=>
20
...
...
app/views/snippets/show.html.haml
View file @
8e1e1776
%h2
-
if
!
@snippet
.
expired?
%h2
=
"Snippet #
#{
@snippet
.
id
}
-
#{
@snippet
.
title
}
"
.view_file
.view_file
.view_file_header
%strong
=
@snippet
.
file_name
...
...
@@ -10,13 +11,16 @@
:erb
<%=
raw
@snippet
.
colorize
%>
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
=
link_to
'Edit'
,
edit_project_snippet_path
(
@project
,
@snippet
),
:class
=>
"lbutton positive"
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
=
link_to
'Destroy'
,
[
@project
,
@snippet
],
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
,
:class
=>
"lbutton delete-snippet negative"
,
:id
=>
"destroy_snippet_
#{
@snippet
.
id
}
"
.clear
%br
.snippet_notes
=
render
"notes/notes"
.clear
%br
.snippet_notes
=
render
"notes/notes"
.clear
.clear
-
else
%h2
Sorry, this snipped is no longer exists
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment