Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
89fa800e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
89fa800e
编写于
10月 28, 2011
作者:
N
Nihad Abbasov
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'refs/heads/snippets_expiration' into dev
Conflicts: db/schema.rb
上级
f4e7ad7a
b6cdd1c8
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
71 addition
and
31 deletion
+71
-31
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+9
-0
app/models/snippet.rb
app/models/snippet.rb
+8
-0
app/views/projects/_top_menu.html.haml
app/views/projects/_top_menu.html.haml
+1
-1
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/index.html.haml
app/views/snippets/index.html.haml
+1
-1
app/views/snippets/show.html.haml
app/views/snippets/show.html.haml
+22
-18
db/migrate/20111027051828_add_expires_at_to_snippets.rb
db/migrate/20111027051828_add_expires_at_to_snippets.rb
+5
-0
db/schema.rb
db/schema.rb
+1
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+1
-0
spec/requests/snippets_spec.rb
spec/requests/snippets_spec.rb
+8
-0
未找到文件。
app/helpers/snippets_helper.rb
浏览文件 @
89fa800e
module
SnippetsHelper
def
lifetime_select_options
options
=
[
[
'forever'
,
nil
],
[
'1 day'
,
"
#{
Date
.
current
+
1
.
day
}
"
],
[
'1 week'
,
"
#{
Date
.
current
+
1
.
week
}
"
],
[
'1 month'
,
"
#{
Date
.
current
+
1
.
month
}
"
]
]
options_for_select
(
options
)
end
end
app/models/snippet.rb
浏览文件 @
89fa800e
...
...
@@ -22,6 +22,9 @@ class Snippet < ActiveRecord::Base
:presence
=>
true
,
:length
=>
{
:within
=>
0
..
10000
}
scope
:fresh
,
order
(
"created_at DESC"
)
scope
:non_expired
,
where
([
"expires_at IS NULL OR expires_at > ?"
,
Time
.
current
])
def
self
.
content_types
[
".rb"
,
".py"
,
".pl"
,
".scala"
,
".c"
,
".cpp"
,
".java"
,
...
...
@@ -33,6 +36,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
#
...
...
@@ -46,5 +53,6 @@ end
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
#
app/views/projects/_top_menu.html.haml
浏览文件 @
89fa800e
...
...
@@ -23,7 +23,7 @@
=
link_to
project_snippets_path
(
@project
),
:class
=>
(
controller
.
controller_name
==
"snippets"
)
?
"current"
:
nil
do
Snippets
-
if
@project
.
snippets
.
count
>
0
%span
{
:class
=>
"top_menu_count"
}=
@project
.
snippets
.
count
%span
{
:class
=>
"top_menu_count"
}=
@project
.
snippets
.
non_expired
.
count
-
if
@commit
%span
=
link_to
truncate
(
commit_name
(
@project
,
@commit
),
:length
=>
15
),
project_commit_path
(
@project
,
:id
=>
@commit
.
id
),
:class
=>
current_page?
(
:controller
=>
"commits"
,
:action
=>
"show"
,
:project_id
=>
@project
,
:id
=>
@commit
.
id
)
?
"current"
:
nil
...
...
app/views/snippets/_form.html.haml
浏览文件 @
89fa800e
...
...
@@ -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
,
lifetime_select_options
%tr
%td
{
:colspan
=>
2
}
=
f
.
label
:content
,
"Code"
...
...
app/views/snippets/_snippet.html.haml
浏览文件 @
89fa800e
%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/index.html.haml
浏览文件 @
89fa800e
...
...
@@ -8,7 +8,7 @@
%th
Title
%th
File name
%th
=
render
@snippets
=
render
@snippets
.
fresh
:javascript
$
(
'
.delete-snippet
'
).
live
(
'
ajax:success
'
,
function
()
{
$
(
this
).
closest
(
'
tr
'
).
fadeOut
();
});
app/views/snippets/show.html.haml
浏览文件 @
89fa800e
%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 snippet is no longer exists
db/migrate/20111027051828_add_expires_at_to_snippets.rb
0 → 100644
浏览文件 @
89fa800e
class
AddExpiresAtToSnippets
<
ActiveRecord
::
Migration
def
change
add_column
:snippets
,
:expires_at
,
:datetime
end
end
db/schema.rb
浏览文件 @
89fa800e
...
...
@@ -65,6 +65,7 @@ ActiveRecord::Schema.define(:version => 20111027142641) do
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"file_name"
t
.
datetime
"expires_at"
end
create_table
"users"
,
:force
=>
true
do
|
t
|
...
...
spec/models/snippet_spec.rb
浏览文件 @
89fa800e
...
...
@@ -26,5 +26,6 @@ end
# created_at :datetime
# updated_at :datetime
# file_name :string(255)
# expires_at :datetime
#
spec/requests/snippets_spec.rb
浏览文件 @
89fa800e
...
...
@@ -23,6 +23,14 @@ describe "Snippets" do
it
{
should
have_content
(
@snippet
.
project
.
name
)
}
it
{
should
have_content
(
@snippet
.
author
.
name
)
}
it
"doesn't show expired snippets"
do
@snippet
.
update_attribute
(
:expires_at
,
1
.
day
.
ago
.
to_time
)
visit
project_snippet_path
(
project
,
@snippet
)
page
.
should
have_content
(
"Sorry, this snippet is no longer exists"
)
page
.
should_not
have_content
(
@snippet
.
title
)
page
.
should_not
have_content
(
@snippet
.
content
)
end
describe
"Destroy"
do
before
do
# admin access to remove snippet
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录