convert gpg badge helper methods to partials

This commit is contained in:
Alexis Reigel 2017-07-05 20:59:17 +02:00
parent 084cc718f7
commit 36c05b311c
6 changed files with 48 additions and 87 deletions

View file

@ -295,6 +295,7 @@
}
.gpg-badge-popover-title {
display: inline;
font-weight: normal;
}

View file

@ -212,90 +212,4 @@ module CommitsHelper
[commits, 0]
end
end
def commit_gpg_signature_badge(signature)
if signature.valid_signature?
commit_gpg_valid_signature_badge(signature)
else
commit_gpg_invalid_signature_badge(signature)
end
end
def commit_gpg_valid_signature_badge(signature)
title = capture do
concat content_tag('i', '', class: 'fa fa-check-circle gpg-badge-popover-icon valid', 'aria-hidden' => 'true')
concat 'This commit was signed with a verified signature.'
end
content = capture do
link_to user_path(signature.gpg_key.user), class: 'gpg-badge-popover-user-link' do
concat(
content_tag(:div, class: 'gpg-badge-popover-avatar') do
user_avatar_without_link(user: signature.gpg_key.user, size: 32)
end
)
concat(
content_tag(:div, class: 'gpg-badge-popover-username') do
signature.gpg_key.user.username
end
)
concat(
content_tag(:div) do
signature.gpg_key.user.name
end
)
end
end
commit_gpg_signature_badge_with(signature, label: 'Verified', title: title, content: content, css_classes: ['valid'])
end
def commit_gpg_invalid_signature_badge(signature)
title = capture do
concat content_tag('i', '', class: 'fa fa-question-circle gpg-badge-popover-icon invalid', 'aria-hidden' => 'true')
concat 'This commit was signed with an unverified signature.'
end
commit_gpg_signature_badge_with(signature, label: 'Unverified', title: title, css_classes: ['invalid'])
end
def commit_gpg_signature_badge_with(signature, label:, title: '', content: '', css_classes: [])
css_classes = %w(btn btn-xs gpg-badge) + css_classes
content = capture do
concat(
content_tag(:div, class: 'clearfix') do
content
end
)
concat "GPG key ID: #{signature.gpg_key_primary_keyid}"
concat(
link_to(
'Learn about signing commits',
help_page_path('workflow/gpg_signed_commits/index.md'),
class: 'gpg-badge-popover-help-link'
)
)
end
title = capture do
content_tag 'span', class: 'gpg-badge-popover-title' do
title
end
end
data = {
toggle: 'popover',
html: 'true',
placement: 'auto bottom',
title: title,
content: content
}
content_tag :button, class: css_classes, data: data do
label
end
end
end

View file

@ -0,0 +1,7 @@
- title = capture do
%i{ class: 'fa fa-question-circle gpg-badge-popover-icon invalid', 'aria-hidden' => 'true' }
This commit was signed with an unverified signature.
- locals = { signature: signature, title: title, label: 'Unverified', css_classes: ['invalid'] }
= render partial: 'projects/commit/signature_badge', locals: locals

View file

@ -1,2 +1,5 @@
- if signature
= commit_gpg_signature_badge(signature)
- if signature.valid_signature?
= render partial: 'projects/commit/valid_signature_badge', locals: { signature: signature }
- else
= render partial: 'projects/commit/invalid_signature_badge', locals: { signature: signature }

View file

@ -0,0 +1,17 @@
- css_classes = %w(btn btn-xs gpg-badge) + css_classes
- title = capture do
.gpg-badge-popover-title
= title
- content = capture do
.clearfix
= content
GPG key ID:
= signature.gpg_key_primary_keyid
= link_to('Learn about signing commits', help_page_path('workflow/gpg_signed_commits/index.md'), class: 'gpg-badge-popover-help-link')
%button{ class: css_classes, data: { toggle: 'popover', html: 'true', placement: 'auto bottom', title: title, content: content } }
= label

View file

@ -0,0 +1,19 @@
- title = capture do
%i{ class: 'fa fa-check-circle gpg-badge-popover-icon valid', 'aria-hidden' => 'true' }
This commit was signed with a verified signature.
- content = capture do
- gpg_key = signature.gpg_key
= link_to user_path(gpg_key.user), class: 'gpg-badge-popover-user-link' do
.gpg-badge-popover-avatar
= user_avatar_without_link(user: signature.gpg_key.user, size: 32)
.gpg-badge-popover-username
= gpg_key.user.username
%div= gpg_key.user.name
- locals = { signature: signature, title: title, content: content, label: 'Verified', css_classes: ['valid'] }
= render partial: 'projects/commit/signature_badge', locals: locals