BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
da5b0c91
Commit
da5b0c91
authored
Mar 31, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some decorator logic to helpers
parent
685681e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
18 deletions
+90
-18
commits_helper.rb
app/helpers/commits_helper.rb
+74
-0
tree_helper.rb
app/helpers/tree_helper.rb
+16
-18
No files found.
app/helpers/commits_helper.rb
View file @
da5b0c91
module
CommitsHelper
# Returns a link to the commit author. If the author has a matching user and
# is a member of the current @project it will link to the team member page.
# Otherwise it will link to the author email as specified in the commit.
#
# options:
# avatar: true will prepend the avatar image
# size: size of the avatar image in px
def
commit_author_link
(
commit
,
options
=
{})
commit_person_link
(
commit
,
options
.
merge
(
source: :author
))
end
# Just like #author_link but for the committer.
def
commit_committer_link
(
commit
,
options
=
{})
commit_person_link
(
commit
,
options
.
merge
(
source: :committer
))
end
def
identification_type
(
line
)
if
line
[
0
]
==
"+"
"new"
...
...
@@ -105,4 +121,62 @@ module CommitsHelper
line
end
end
# Breadcrumb links for a Project and, if applicable, a tree path
def
commits_breadcrumbs
return
unless
@project
&&
@ref
# Add the root project link and the arrow icon
crumbs
=
content_tag
(
:li
)
do
content_tag
(
:span
,
nil
,
class:
'arrow'
)
+
link_to
(
@project
.
name
,
project_commits_path
(
@project
,
@ref
))
end
if
@path
parts
=
@path
.
split
(
'/'
)
parts
.
each_with_index
do
|
part
,
i
|
crumbs
+=
content_tag
(
:span
,
'/'
,
class:
'divider'
)
crumbs
+=
content_tag
(
:li
)
do
# The text is just the individual part, but the link needs all the parts before it
link_to
part
,
project_commits_path
(
@project
,
tree_join
(
@ref
,
parts
[
0
..
i
].
join
(
'/'
)))
end
end
end
crumbs
.
html_safe
end
protected
def
no_commit_message
"--no commit message"
end
# Private: Returns a link to a person. If the person has a matching user and
# is a member of the current @project it will link to the team member page.
# Otherwise it will link to the person email as specified in the commit.
#
# options:
# source: one of :author or :committer
# avatar: true will prepend the avatar image
# size: size of the avatar image in px
def
commit_person_link
(
commit
,
options
=
{})
source_name
=
commit
.
send
"
#{
options
[
:source
]
}
_name"
.
to_sym
source_email
=
commit
.
send
"
#{
options
[
:source
]
}
_email"
.
to_sym
text
=
if
options
[
:avatar
]
avatar
=
image_tag
(
gravatar_icon
(
source_email
,
options
[
:size
]),
class:
"avatar
#{
"s
#{
options
[
:size
]
}
"
if
options
[
:size
]
}
"
,
width:
options
[
:size
],
alt:
""
)
%Q{
#{
avatar
}
<span class="commit-
#{
options
[
:source
]
}
-name">
#{
source_name
}
</span>}
else
source_name
end
user
=
User
.
where
(
'name like ? or email like ?'
,
source_name
,
source_email
).
first
if
user
.
nil?
mail_to
(
source_email
,
text
.
html_safe
,
class:
"commit-
#{
options
[
:source
]
}
-link"
)
else
link_to
(
text
.
html_safe
,
user_path
(
user
),
class:
"commit-
#{
options
[
:source
]
}
-link"
)
end
end
end
app/helpers/tree_helper.rb
View file @
da5b0c91
...
...
@@ -70,28 +70,26 @@ module TreeHelper
end
end
# Breadcrumb links for a Project and, if applicable, a tree path
def
breadcrumbs
return
unless
@project
&&
@ref
# Add the root project link and the arrow icon
crumbs
=
content_tag
(
:li
)
do
content_tag
(
:span
,
nil
,
class:
'arrow'
)
+
link_to
(
@project
.
name
,
project_commits_path
(
@project
,
@ref
))
end
def
tree_breadcrumbs
(
tree
,
max_links
=
2
)
if
tree
.
path
part_path
=
""
parts
=
tree
.
path
.
split
(
"
\/
"
)
yield
(
'..'
,
nil
)
if
parts
.
count
>
max_links
if
@path
parts
=
@path
.
split
(
'/'
)
parts
.
each
do
|
part
|
part_path
=
File
.
join
(
part_path
,
part
)
unless
part_path
.
empty?
part_path
=
part
if
part_path
.
empty?
parts
.
each_with_index
do
|
part
,
i
|
crumbs
+=
content_tag
(
:span
,
'/'
,
class:
'divider'
)
crumbs
+=
content_tag
(
:li
)
do
# The text is just the individual part, but the link needs all the parts before it
link_to
part
,
project_commits_path
(
@project
,
tree_join
(
@ref
,
parts
[
0
..
i
].
join
(
'/'
)))
end
next
unless
parts
.
last
(
2
).
include?
(
part
)
if
parts
.
count
>
max_links
yield
(
part
,
tree_join
(
tree
.
ref
,
part_path
))
end
end
end
crumbs
.
html_safe
def
up_dir_path
tree
file
=
File
.
join
(
tree
.
path
,
".."
)
tree_join
(
tree
.
ref
,
file
)
end
end
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