Module: ButtonHelper

Defined in:
app/helpers/button_helper.rb

Instance Method Summary collapse

Instance Method Details

#clipboard_button(data = {}) ⇒ Object

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
clipboard_button(clipboard_target: "div#foo")
# => "<button class='...' data-clipboard-target='div#foo'>...</button>"

See clipboardjs.com/#usage


17
18
19
20
21
22
23
# File 'app/helpers/button_helper.rb', line 17

def clipboard_button(data = {})
   :button,
    icon('clipboard'),
    class: 'btn btn-clipboard',
    data: data,
    type: :button
end

#http_clone_button(project) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/button_helper.rb', line 25

def http_clone_button(project)
  klass = 'http-selector'
  klass << ' has-tooltip' if current_user.try(:require_password?)

  protocol = gitlab_config.protocol.upcase

   :a, protocol,
    class: klass,
    href: @project.http_url_to_repo,
    data: {
      html: true,
      placement: 'right',
      container: 'body',
      title: "Set a password on your account<br>to pull or push via #{protocol}"
    }
end

#ssh_clone_button(project) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/button_helper.rb', line 42

def ssh_clone_button(project)
  klass = 'ssh-selector'
  klass << ' has-tooltip' if current_user.try(:require_ssh_key?)

   :a, 'SSH',
    class: klass,
    href: project.ssh_url_to_repo,
    data: {
      html: true,
      placement: 'right',
      container: 'body',
      title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
    }
end