BigW Consortium Gitlab

button_helper.rb 1.85 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
    title = data[:title] || 'Copy to clipboard'
20
    data = { toggle: 'tooltip', placement: 'bottom', container: 'body' }.merge(data)
21 22
    content_tag :button,
      icon('clipboard'),
23
      class: "btn #{css_class}",
24
      data: data,
25
      type: :button,
26
      title: title
Phil Hughes committed
27 28
  end

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

    protocol = gitlab_config.protocol.upcase

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

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

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