debian-mirror-gitlab/app/helpers/button_helper.rb

80 lines
2.5 KiB
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
module ButtonHelper
# Output a "Copy to Clipboard" button
#
2017-08-17 22:00:37 +05:30
# data - Data attributes passed to `content_tag` (default: {}):
# :text - Text to copy (optional)
# :gfm - GitLab Flavored Markdown to copy, if different from `text` (optional)
# :target - Selector for target element to copy from (optional)
2015-12-23 02:04:40 +05:30
#
# Examples:
#
# # Define the clipboard's text
2017-08-17 22:00:37 +05:30
# clipboard_button(text: "Foo")
2015-12-23 02:04:40 +05:30
# # => "<button class='...' data-clipboard-text='Foo'>...</button>"
#
# # Define the target element
2017-08-17 22:00:37 +05:30
# clipboard_button(target: "div#foo")
2015-12-23 02:04:40 +05:30
# # => "<button class='...' data-clipboard-target='div#foo'>...</button>"
#
# See http://clipboardjs.com/#usage
def clipboard_button(data = {})
2016-11-03 12:29:30 +05:30
css_class = data[:class] || 'btn-clipboard btn-transparent'
2017-08-17 22:00:37 +05:30
title = data[:title] || 'Copy to clipboard'
# This supports code in app/assets/javascripts/copy_to_clipboard.js that
# works around ClipboardJS limitations to allow the context-specific copy/pasting of plain text or GFM.
if text = data.delete(:text)
data[:clipboard_text] =
if gfm = data.delete(:gfm)
{ text: text, gfm: gfm }
else
text
end
end
target = data.delete(:target)
data[:clipboard_target] = target if target
2016-08-24 12:49:21 +05:30
data = { toggle: 'tooltip', placement: 'bottom', container: 'body' }.merge(data)
2017-08-17 22:00:37 +05:30
2015-12-23 02:04:40 +05:30
content_tag :button,
2017-08-17 22:00:37 +05:30
icon('clipboard', 'aria-hidden': 'true'),
2016-11-03 12:29:30 +05:30
class: "btn #{css_class}",
2016-06-22 15:30:34 +05:30
data: data,
2016-08-24 12:49:21 +05:30
type: :button,
2017-08-17 22:00:37 +05:30
title: title
2016-06-22 15:30:34 +05:30
end
2016-08-24 12:49:21 +05:30
def http_clone_button(project, placement = 'right', append_link: true)
2016-06-02 11:05:42 +05:30
klass = 'http-selector'
klass << ' has-tooltip' if current_user.try(:require_password?)
2015-12-23 02:04:40 +05:30
protocol = gitlab_config.protocol.upcase
2016-08-24 12:49:21 +05:30
content_tag (append_link ? :a : :span), protocol,
2015-12-23 02:04:40 +05:30
class: klass,
2017-08-17 22:00:37 +05:30
href: (project.http_url_to_repo(current_user) if append_link),
2015-12-23 02:04:40 +05:30
data: {
2016-06-02 11:05:42 +05:30
html: true,
2016-08-24 12:49:21 +05:30
placement: placement,
2015-12-23 02:04:40 +05:30
container: 'body',
title: "Set a password on your account<br>to pull or push via #{protocol}"
2016-06-02 11:05:42 +05:30
}
2015-12-23 02:04:40 +05:30
end
2016-08-24 12:49:21 +05:30
def ssh_clone_button(project, placement = 'right', append_link: true)
2016-06-02 11:05:42 +05:30
klass = 'ssh-selector'
klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
2015-12-23 02:04:40 +05:30
2016-08-24 12:49:21 +05:30
content_tag (append_link ? :a : :span), 'SSH',
2015-12-23 02:04:40 +05:30
class: klass,
2016-08-24 12:49:21 +05:30
href: (project.ssh_url_to_repo if append_link),
2015-12-23 02:04:40 +05:30
data: {
2016-06-02 11:05:42 +05:30
html: true,
2016-08-24 12:49:21 +05:30
placement: placement,
2015-12-23 02:04:40 +05:30
container: 'body',
title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
2016-06-02 11:05:42 +05:30
}
2015-12-23 02:04:40 +05:30
end
end