diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-21 23:40:25 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-21 23:40:25 -0400 |
commit | 9bdd7f34a52da2faa3677e26b57a7b270d629d97 (patch) | |
tree | e2a5f1b121016c6efcf50733ed28b042cf037e77 /app/helpers/labels_helper.rb | |
parent | 2b1b026a1e8c7654b475aa0aaacf3121e86ee2a5 (diff) | |
download | gitlab-ce-9bdd7f34a52da2faa3677e26b57a7b270d629d97.tar.gz |
Add link_to_label helper
Diffstat (limited to 'app/helpers/labels_helper.rb')
-rw-r--r-- | app/helpers/labels_helper.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index 8272c177d59..8036303851b 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -1,6 +1,44 @@ module LabelsHelper include ActionView::Helpers::TagHelper + # Link to a Label + # + # label - Label object to link to + # project - Project object which will be used as the context for the label's + # link. If omitted, defaults to `@project`, or the label's own + # project. + # block - An optional block that will be passed to `link_to`, forming the + # body of the link element. If omitted, defaults to + # `render_colored_label`. + # + # Examples: + # + # # Allow the generated link to use the label's own project + # link_to_label(label) + # + # # Force the generated link to use @project + # @project = Project.first + # link_to_label(label) + # + # # Force the generated link to use a provided project + # link_to_label(label, project: Project.last) + # + # # Customize link body with a block + # link_to_label(label) { "My Custom Label Text" } + # + # Returns a String + def link_to_label(label, project: nil, &block) + project ||= @project || label.project + link = namespace_project_issues_path(project.namespace, project, + label_name: label.name) + + if block_given? + link_to link, &block + else + link_to render_colored_label(label), link + end + end + def project_label_names @project.labels.pluck(:title) end |