From 03c733849c1fad9885b0b947e60744633b7f5bd6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Tue, 28 Aug 2018 15:14:39 +0200 Subject: Convert global templates to vendored templates via a ::TemplateFinder --- app/helpers/blob_helper.rb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 00ebafd177b..c9f2f1e3caf 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -158,32 +158,35 @@ module BlobHelper end def licenses_for_select - return @licenses_for_select if defined?(@licenses_for_select) - - grouped_licenses = LicenseTemplateFinder.new.execute.group_by(&:category) - categories = grouped_licenses.keys - - @licenses_for_select = categories.each_with_object({}) do |category, hash| - hash[category] = grouped_licenses[category].map do |license| - { name: license.name, id: license.id } - end - end + @licenses_for_select ||= dropdown_names(LicenseTemplateFinder.new.execute) end def ref_project @ref_project ||= @target_project || @project end + def dropdown_names(items) + grouped = items.group_by(&:category) + categories = grouped.keys + + categories.each_with_object({}) do |category, hash| + hash[category] = grouped[category].map do |item| + { name: item.name, id: item.id } + end + end + end + private :dropdown_names + def gitignore_names - @gitignore_names ||= Gitlab::Template::GitignoreTemplate.dropdown_names + @gitignore_names ||= dropdown_names(TemplateFinder.new(:gitignores).execute) end def gitlab_ci_ymls - @gitlab_ci_ymls ||= Gitlab::Template::GitlabCiYmlTemplate.dropdown_names(params[:context]) + @gitlab_ci_ymls ||= dropdown_names(TemplateFinder.new(:gitlab_ci_ymls).execute) end def dockerfile_names - @dockerfile_names ||= Gitlab::Template::DockerfileTemplate.dropdown_names + @dockerfile_names ||= dropdown_names(TemplateFinder.new(:dockerfiles).execute) end def blob_editor_paths -- cgit v1.2.1