BigW Consortium Gitlab

button_helper.rb 1.81 KB
Newer Older
1
module ButtonHelper
2 3 4 5 6 7 8 9 10 11 12
  # Output a "Copy to Clipboard" button
  #
  # data - Data attributes passed to `content_tag`
  #
  # Examples:
  #
  #   # Define the clipboard's text
  #   clipboard_button(clipboard_text: "Foo")
  #   # => "<button class='...' data-clipboard-text='Foo'>...</button>"
  #
  #   # Define the target element
13 14
  #   clipboard_button(clipboard_target: "div#foo")
  #   # => "<button class='...' data-clipboard-target='div#foo'>...</button>"
15 16
  #
  # See http://clipboardjs.com/#usage
Phil Hughes committed
17
  def clipboard_button(data = {})
18
    css_class = data[:class] || 'btn-clipboard btn-transparent'
19
    data = { toggle: 'tooltip', placement: 'bottom', container: 'body' }.merge(data)
20 21
    content_tag :button,
      icon('clipboard'),
22
      class: "btn #{css_class}",
23
      data: data,
24
      type: :button,
25
      title: 'Copy to Clipboard'
Phil Hughes committed
26 27
  end

28
  def http_clone_button(project, placement = 'right', append_link: true)
29
    klass = 'http-selector'
30
    klass << ' has-tooltip' if current_user.try(:require_password?)
31 32 33

    protocol = gitlab_config.protocol.upcase

34
    content_tag (append_link ? :a : :span), protocol,
35
      class: klass,
36
      href: (project.http_url_to_repo if append_link),
37
      data: {
38
        html: true,
39
        placement: placement,
40
        container: 'body',
41
        title: "Set a password on your account<br>to pull or push via #{protocol}"
42
      }
43 44
  end

45
  def ssh_clone_button(project, placement = 'right', append_link: true)
46
    klass = 'ssh-selector'
47
    klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
48

49
    content_tag (append_link ? :a : :span), 'SSH',
50
      class: klass,
51
      href: (project.ssh_url_to_repo if append_link),
52
      data: {
53
        html: true,
54
        placement: placement,
55
        container: 'body',
56
        title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
57
      }
58 59
  end
end