Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
4a920a33b0d4
Commit
90c338a4
authored
Sep 09, 2015
by
Dmitriy Zaporozhets
Browse files
Move helpers back to original directory
parent
84232c2e73f5
Changes
104
Hide whitespace changes
Inline
Side-by-side
app/controllers/application_controller.rb
View file @
4a920a33
require
'gon'
class
ApplicationController
<
ActionController
::
Base
def
self
.
railtie_helpers_paths
"app/helpers/gitlab"
end
include
Gitlab
::
CurrentSettings
include
Gitlab
::
GitlabRoutingHelper
include
Gitlab
::
PageLayoutHelper
include
GitlabRoutingHelper
include
PageLayoutHelper
PER_PAGE
=
20
...
...
app/controllers/oauth/applications_controller.rb
View file @
4a920a33
class
Oauth::ApplicationsController
<
Doorkeeper
::
ApplicationsController
include
Gitlab
::
CurrentSettings
include
Gitlab
::
PageLayoutHelper
include
PageLayoutHelper
before_action
:verify_user_oauth_applications_enabled
before_action
:authenticate_user!
...
...
app/controllers/oauth/authorized_applications_controller.rb
View file @
4a920a33
class
Oauth::AuthorizedApplicationsController
<
Doorkeeper
::
AuthorizedApplicationsController
include
Gitlab
::
PageLayoutHelper
include
PageLayoutHelper
layout
'profile'
...
...
app/controllers/projects/network_controller.rb
View file @
4a920a33
class
Projects::NetworkController
<
Projects
::
ApplicationController
include
ExtractsPath
include
Gitlab
::
ApplicationHelper
include
ApplicationHelper
before_action
:require_non_empty_project
before_action
:assign_ref_vars
...
...
app/controllers/projects/refs_controller.rb
View file @
4a920a33
class
Projects::RefsController
<
Projects
::
ApplicationController
include
ExtractsPath
include
Gitlab
::
TreeHelper
include
TreeHelper
before_action
:require_non_empty_project
before_action
:assign_ref_vars
...
...
app/controllers/projects/wikis_controller.rb
View file @
4a920a33
...
...
@@ -5,7 +5,7 @@ class Projects::WikisController < Projects::ApplicationController
before_action
:authorize_create_wiki!
,
only:
[
:edit
,
:create
,
:history
]
before_action
:authorize_admin_wiki!
,
only: :destroy
before_action
:load_project_wiki
include
Gitlab
::
WikiHelper
#
include WikiHelper
def
pages
@wiki_pages
=
Kaminari
.
paginate_array
(
@project_wiki
.
pages
).
page
(
params
[
:page
]).
per
(
PER_PAGE
)
...
...
app/controllers/search_controller.rb
View file @
4a920a33
class
SearchController
<
ApplicationController
include
Gitlab
::
SearchHelper
include
SearchHelper
layout
'search'
...
...
app/helpers/appearances_helper.rb
0 → 100644
View file @
4a920a33
module
AppearancesHelper
def
brand_item
nil
end
def
brand_title
'GitLab Community Edition'
end
def
brand_image
nil
end
def
brand_text
nil
end
def
brand_header_logo
image_tag
'logo.svg'
end
end
app/helpers/application_helper.rb
0 → 100644
View file @
4a920a33
require
'digest/md5'
require
'uri'
module
ApplicationHelper
# Check if a particular controller is the current one
#
# args - One or more controller names to check
#
# Examples
#
# # On TreeController
# current_controller?(:tree) # => true
# current_controller?(:commits) # => false
# current_controller?(:commits, :tree) # => true
def
current_controller?
(
*
args
)
args
.
any?
{
|
v
|
v
.
to_s
.
downcase
==
controller
.
controller_name
}
end
# Check if a particular action is the current one
#
# args - One or more action names to check
#
# Examples
#
# # On Projects#new
# current_action?(:new) # => true
# current_action?(:create) # => false
# current_action?(:new, :create) # => true
def
current_action?
(
*
args
)
args
.
any?
{
|
v
|
v
.
to_s
.
downcase
==
action_name
}
end
def
project_icon
(
project_id
,
options
=
{})
project
=
if
project_id
.
is_a?
(
Project
)
project
=
project_id
else
Project
.
find_with_namespace
(
project_id
)
end
if
project
.
avatar_url
image_tag
project
.
avatar_url
,
options
else
# generated icon
project_identicon
(
project
,
options
)
end
end
def
project_identicon
(
project
,
options
=
{})
allowed_colors
=
{
red:
'FFEBEE'
,
purple:
'F3E5F5'
,
indigo:
'E8EAF6'
,
blue:
'E3F2FD'
,
teal:
'E0F2F1'
,
orange:
'FBE9E7'
,
gray:
'EEEEEE'
}
options
[
:class
]
||=
''
options
[
:class
]
<<
' identicon'
bg_key
=
project
.
id
%
7
style
=
"background-color: #
#{
allowed_colors
.
values
[
bg_key
]
}
; color: #555"
content_tag
(
:div
,
class:
options
[
:class
],
style:
style
)
do
project
.
name
[
0
,
1
].
upcase
end
end
def
avatar_icon
(
user_email
=
''
,
size
=
nil
)
user
=
User
.
find_by
(
email:
user_email
)
if
user
user
.
avatar_url
(
size
)
||
default_avatar
else
gravatar_icon
(
user_email
,
size
)
end
end
def
gravatar_icon
(
user_email
=
''
,
size
=
nil
)
GravatarService
.
new
.
execute
(
user_email
,
size
)
||
default_avatar
end
def
default_avatar
image_path
(
'no_avatar.png'
)
end
def
last_commit
(
project
)
if
project
.
repo_exists?
time_ago_with_tooltip
(
project
.
repository
.
commit
.
committed_date
)
else
'Never'
end
rescue
'Never'
end
def
grouped_options_refs
repository
=
@project
.
repository
options
=
[
[
'Branches'
,
repository
.
branch_names
],
[
'Tags'
,
VersionSorter
.
rsort
(
repository
.
tag_names
)]
]
# If reference is commit id - we should add it to branch/tag selectbox
if
(
@ref
&&
!
options
.
flatten
.
include?
(
@ref
)
&&
@ref
=~
/\A[0-9a-zA-Z]{6,52}\z/
)
options
<<
[
'Commit'
,
[
@ref
]]
end
grouped_options_for_select
(
options
,
@ref
||
@project
.
default_branch
)
end
def
emoji_autocomplete_source
# should be an array of strings
# so to_s can be called, because it is sufficient and to_json is too slow
Emoji
.
names
.
to_s
end
# Define whenever show last push event
# with suggestion to create MR
def
show_last_push_widget?
(
event
)
# Skip if event is not about added or modified non-master branch
return
false
unless
event
&&
event
.
last_push_to_non_root?
&&
!
event
.
rm_ref?
project
=
event
.
project
# Skip if project repo is empty or MR disabled
return
false
unless
project
&&
!
project
.
empty_repo?
&&
project
.
merge_requests_enabled
# Skip if user already created appropriate MR
return
false
if
project
.
merge_requests
.
where
(
source_branch:
event
.
branch_name
).
opened
.
any?
# Skip if user removed branch right after that
return
false
unless
project
.
repository
.
branch_names
.
include?
(
event
.
branch_name
)
true
end
def
hexdigest
(
string
)
Digest
::
SHA1
.
hexdigest
string
end
def
simple_sanitize
(
str
)
sanitize
(
str
,
tags:
%w(a span)
)
end
def
body_data_page
path
=
controller
.
controller_path
.
split
(
'/'
)
namespace
=
path
.
first
if
path
.
second
[
namespace
,
controller
.
controller_name
,
controller
.
action_name
].
compact
.
join
(
':'
)
end
# shortcut for gitlab config
def
gitlab_config
Gitlab
.
config
.
gitlab
end
# shortcut for gitlab extra config
def
extra_config
Gitlab
.
config
.
extra
end
def
search_placeholder
if
@project
&&
@project
.
persisted?
'Search in this project'
elsif
@snippet
||
@snippets
||
@show_snippets
'Search snippets'
elsif
@group
&&
@group
.
persisted?
'Search in this group'
else
'Search'
end
end
def
broadcast_message
BroadcastMessage
.
current
end
# Render a `time` element with Javascript-based relative date and tooltip
#
# time - Time object
# placement - Tooltip placement String (default: "top")
# html_class - Custom class for `time` element (default: "time_ago")
# skip_js - When true, exclude the `script` tag (default: false)
#
# By default also includes a `script` element with Javascript necessary to
# initialize the `timeago` jQuery extension. If this method is called many
# times, for example rendering hundreds of commits, it's advisable to disable
# this behavior using the `skip_js` argument and re-initializing `timeago`
# manually once all of the elements have been rendered.
#
# A `js-timeago` class is always added to the element, even when a custom
# `html_class` argument is provided.
#
# Returns an HTML-safe String
def
time_ago_with_tooltip
(
time
,
placement:
'top'
,
html_class:
'time_ago'
,
skip_js:
false
)
element
=
content_tag
:time
,
time
.
to_s
,
class:
"
#{
html_class
}
js-timeago"
,
datetime:
time
.
getutc
.
iso8601
,
title:
time
.
in_time_zone
.
stamp
(
'Aug 21, 2011 9:23pm'
),
data:
{
toggle:
'tooltip'
,
placement:
placement
}
element
+=
javascript_tag
"$('.js-timeago').timeago()"
unless
skip_js
element
end
def
render_markup
(
file_name
,
file_content
)
if
gitlab_markdown?
(
file_name
)
Haml
::
Helpers
.
preserve
(
markdown
(
file_content
))
elsif
asciidoc?
(
file_name
)
asciidoc
(
file_content
)
elsif
plain?
(
file_name
)
content_tag
:pre
,
class:
'plain-readme'
do
file_content
end
else
GitHub
::
Markup
.
render
(
file_name
,
file_content
).
force_encoding
(
file_content
.
encoding
).
html_safe
end
rescue
RuntimeError
simple_format
(
file_content
)
end
def
plain?
(
filename
)
Gitlab
::
MarkupHelper
.
plain?
(
filename
)
end
def
markup?
(
filename
)
Gitlab
::
MarkupHelper
.
markup?
(
filename
)
end
def
gitlab_markdown?
(
filename
)
Gitlab
::
MarkupHelper
.
gitlab_markdown?
(
filename
)
end
def
asciidoc?
(
filename
)
Gitlab
::
MarkupHelper
.
asciidoc?
(
filename
)
end
def
promo_host
'about.gitlab.com'
end
def
promo_url
'https://'
+
promo_host
end
def
page_filter_path
(
options
=
{})
without
=
options
.
delete
(
:without
)
exist_opts
=
{
state:
params
[
:state
],
scope:
params
[
:scope
],
label_name:
params
[
:label_name
],
milestone_id:
params
[
:milestone_id
],
assignee_id:
params
[
:assignee_id
],
author_id:
params
[
:author_id
],
sort:
params
[
:sort
],
}
options
=
exist_opts
.
merge
(
options
)
if
without
.
present?
without
.
each
do
|
key
|
options
.
delete
(
key
)
end
end
path
=
request
.
path
path
<<
"?
#{
options
.
to_param
}
"
path
end
def
outdated_browser?
browser
.
ie?
&&
browser
.
version
.
to_i
<
10
end
def
path_to_key
(
key
,
admin
=
false
)
if
admin
admin_user_key_path
(
@user
,
key
)
else
profile_key_path
(
key
)
end
end
def
state_filters_text_for
(
entity
,
project
)
titles
=
{
opened:
"Open"
}
entity_title
=
titles
[
entity
]
||
entity
.
to_s
.
humanize
count
=
if
project
.
nil?
nil
elsif
current_controller?
(
:issues
)
project
.
issues
.
send
(
entity
).
count
elsif
current_controller?
(
:merge_requests
)
project
.
merge_requests
.
send
(
entity
).
count
end
html
=
content_tag
:span
,
entity_title
if
count
.
present?
html
+=
" "
html
+=
content_tag
:span
,
number_with_delimiter
(
count
),
class:
'badge'
end
html
.
html_safe
end
end
app/helpers/application_settings_helper.rb
0 → 100644
View file @
4a920a33
module
ApplicationSettingsHelper
def
gravatar_enabled?
current_application_settings
.
gravatar_enabled?
end
def
twitter_sharing_enabled?
current_application_settings
.
twitter_sharing_enabled?
end
def
signup_enabled?
current_application_settings
.
signup_enabled?
end
def
signin_enabled?
current_application_settings
.
signin_enabled?
end
def
extra_sign_in_text
current_application_settings
.
sign_in_text
end
def
user_oauth_applications?
current_application_settings
.
user_oauth_applications
end
# Return a group of checkboxes that use Bootstrap's button plugin for a
# toggle button effect.
def
restricted_level_checkboxes
(
help_block_id
)
Gitlab
::
VisibilityLevel
.
options
.
map
do
|
name
,
level
|
checked
=
restricted_visibility_levels
(
true
).
include?
(
level
)
css_class
=
'btn'
css_class
+=
' active'
if
checked
checkbox_name
=
'application_setting[restricted_visibility_levels][]'
label_tag
(
checkbox_name
,
class:
css_class
)
do
check_box_tag
(
checkbox_name
,
level
,
checked
,
autocomplete:
'off'
,
'aria-describedby'
=>
help_block_id
)
+
name
end
end
end
# Return a group of checkboxes that use Bootstrap's button plugin for a
# toggle button effect.
def
import_sources_checkboxes
(
help_block_id
)
Gitlab
::
ImportSources
.
options
.
map
do
|
name
,
source
|
checked
=
current_application_settings
.
import_sources
.
include?
(
source
)
css_class
=
'btn'
css_class
+=
' active'
if
checked
checkbox_name
=
'application_setting[import_sources][]'
label_tag
(
checkbox_name
,
class:
css_class
)
do
check_box_tag
(
checkbox_name
,
source
,
checked
,
autocomplete:
'off'
,
'aria-describedby'
=>
help_block_id
)
+
name
end
end
end
end
app/helpers/auth_helper.rb
0 → 100644
View file @
4a920a33
module
AuthHelper
PROVIDERS_WITH_ICONS
=
%w(twitter github gitlab bitbucket google_oauth2)
.
freeze
FORM_BASED_PROVIDERS
=
[
/\Aldap/
,
'kerberos'
,
'crowd'
].
freeze
def
ldap_enabled?
Gitlab
.
config
.
ldap
.
enabled
end
def
provider_has_icon?
(
name
)
PROVIDERS_WITH_ICONS
.
include?
(
name
.
to_s
)
end
def
auth_providers
Gitlab
::
OAuth
::
Provider
.
providers
end
def
label_for_provider
(
name
)
Gitlab
::
OAuth
::
Provider
.
label_for
(
name
)
end
def
form_based_provider?
(
name
)
FORM_BASED_PROVIDERS
.
any?
{
|
pattern
|
pattern
===
name
.
to_s
}
end
def
form_based_providers
auth_providers
.
select
{
|
provider
|
form_based_provider?
(
provider
)
}
end
def
crowd_enabled?
auth_providers
.
include?
:crowd
end
def
button_based_providers
auth_providers
.
reject
{
|
provider
|
form_based_provider?
(
provider
)
}
end
def
provider_image_tag
(
provider
,
size
=
64
)
label
=
label_for_provider
(
provider
)
if
provider_has_icon?
(
provider
)
file_name
=
"
#{
provider
.
to_s
.
split
(
'_'
).
first
}
_
#{
size
}
.png"
image_tag
(
image_path
(
"auth_buttons/
#{
file_name
}
"
),
alt:
label
,
title:
"Sign in with
#{
label
}
"
)
else
label
end
end
def
auth_active?
(
provider
)
current_user
.
identities
.
exists?
(
provider:
provider
.
to_s
)
end
extend
self
end
app/helpers/blob_helper.rb
0 → 100644
View file @
4a920a33
module
BlobHelper
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
,
continue:
false
)
@formatter
||=
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
nowrap:
nowrap
,
cssclass:
'code highlight'
,
lineanchors:
true
,
lineanchorsid:
'LC'
)
begin
@lexer
||=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
result
=
@formatter
.
format
(
@lexer
.
lex
(
blob_content
,
continue:
continue
)).
html_safe
rescue
@lexer
=
Rouge
::
Lexers
::
PlainText
result
=
@formatter
.
format
(
@lexer
.
lex
(
blob_content
)).
html_safe
end
result
end
def
no_highlight_files
%w(credits changelog news copying copyright license authors)
end
def
edit_blob_link
(
project
,
ref
,
path
,
options
=
{})
blob
=
begin
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
end
if
blob
&&
blob
.
text?
text
=
'Edit'
after
=
options
[
:after
]
||
''
from_mr
=
options
[
:from_merge_request_id
]
link_opts
=
{}
link_opts
[
:from_merge_request_id
]
=
from_mr
if
from_mr
cls
=
'btn btn-small'
if
allowed_tree_edit?
(
project
,
ref
)
link_to
(
text
,
namespace_project_edit_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
path
),
link_opts
),
class:
cls
)
else
content_tag
:span
,
text
,
class:
cls
+
' disabled'
end
+
after
.
html_safe
else
''
end
end
def
leave_edit_message
"Leave edit mode?
\n
All unsaved changes will be lost."
end
def
editing_preview_title
(
filename
)
if
Gitlab
::
MarkupHelper
.
previewable?
(
filename
)
'Preview'
else
'Preview changes'
end
end
# Return an image icon depending on the file mode and extension
#
# mode - File unix mode
# mode - File name
def
blob_icon
(
mode
,
name
)
icon
(
"
#{
file_type_icon_class
(
'file'
,
mode
,
name
)
}
fw"
)
end
end
app/helpers/branches_helper.rb
0 → 100644
View file @
4a920a33
module
BranchesHelper
def
can_remove_branch?
(
project
,
branch_name
)
if
project
.
protected_branch?
branch_name
false
elsif
branch_name
==
project
.
repository
.
root_ref
false
else
can?
(
current_user
,
:push_code
,
project
)
end
end
def
can_push_branch?
(
project
,
branch_name
)
return
false
unless
project
.
repository
.
branch_names
.
include?
(
branch_name
)
::
Gitlab
::
GitAccess
.
new
(
current_user
,
project
).
can_push_to_branch?
(
branch_name
)
<