Skip to content
Snippets Groups Projects
button_helper.rb 1.85 KiB
Newer Older
  • Learn to ignore specific revisions
  • module ButtonHelper
    
      # 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 http://clipboardjs.com/#usage
    
    Phil Hughes's avatar
    Phil Hughes committed
      def clipboard_button(data = {})
    
        css_class = data[:class] || 'btn-clipboard btn-transparent'
    
        title = data[:title] || 'Copy to clipboard'
    
        data = { toggle: 'tooltip', placement: 'bottom', container: 'body' }.merge(data)
    
        content_tag :button,
          icon('clipboard'),
    
          class: "btn #{css_class}",
    
          data: data,
    
    Phil Hughes's avatar
    Phil Hughes committed
      end
    
    
      def http_clone_button(project, placement = 'right', append_link: true)
    
        klass << ' has-tooltip' if current_user.try(:require_password?)
    
    
        protocol = gitlab_config.protocol.upcase
    
    
        content_tag (append_link ? :a : :span), protocol,
    
          href: (project.http_url_to_repo if append_link),
    
            placement: placement,
    
            container: 'body',
    
            title: "Set a password on your account<br>to pull or push via #{protocol}"
    
      def ssh_clone_button(project, placement = 'right', append_link: true)
    
        klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
    
        content_tag (append_link ? :a : :span), 'SSH',
    
          href: (project.ssh_url_to_repo if append_link),
    
            placement: placement,
    
            container: 'body',
    
            title: 'Add an SSH key to your profile<br>to pull or push via SSH.'