diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-06-02 19:20:08 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-06-20 22:48:28 +0300 |
commit | 620d014aefd23030ed6ae043e223ccc5dc52fc8a (patch) | |
tree | 9324f2cbb23bdcc4f02d9b29b349894e4b43ac8c /lib/gitlab/template | |
parent | 567f6a7b4271d97afd6dea1545210b9aba858421 (diff) |
Implement backend gitlab ci dropdown
This commit builds on the groundwork in
ee008e300b1ec0abcc90e6a30816ec0754cea0dd, which refactored the backend
so the same code could be used for new dropdowns. In this commit its
used for templates for the `.gitlab-ci.yml` files.
Diffstat (limited to 'lib/gitlab/template')
-rw-r--r-- | lib/gitlab/template/base_template.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/template/gitignore.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/template/gitlab_ci_yml.rb | 22 |
3 files changed, 48 insertions, 14 deletions
diff --git a/lib/gitlab/template/base_template.rb b/lib/gitlab/template/base_template.rb index e1cdfc8f5f6..652a496b57b 100644 --- a/lib/gitlab/template/base_template.rb +++ b/lib/gitlab/template/base_template.rb @@ -13,40 +13,53 @@ module Gitlab File.read(@path) end + def categories + raise NotImplementedError + end + + def extension + raise NotImplementedError + end + + def base_dir + raise NotImplementedError + end + class << self def all - self.category_directories.flat_map do |dir| - templates_for_folder(dir) - end + self.categories.keys.flat_map { |cat| by_category(cat) } end def find(key) file_name = "#{key}#{self.extension}" directory = select_directory(file_name) - directory ? new(File.join(directory, file_name)) : nil + directory ? new(File.join(category_directory(directory), file_name)) : nil end def by_category(category) - templates_for_folder(categories[category]) + templates_for_directory(category_directory(category)) end - def category_directories - self.categories.values.map { |subdir| File.join(base_dir, subdir)} + def category_directory(category) + File.join(base_dir, categories[category]) end private def select_directory(file_name) - category_directories.find { |dir| File.exist?(File.join(dir, file_name)) } + categories.keys.find do |category| + File.exist?(File.join(category_directory(category), file_name)) + end end - def templates_for_folder(dir) - Dir.glob("#{dir.to_s}/*#{self.extension}").select { |f| f =~ filter_regex }.map { |f| new(f) } + def templates_for_directory(dir) + dir << '/' unless dir.end_with?('/') + Dir.glob(File.join(dir, "*#{self.extension}")).select { |f| f =~ filter_regex }.map { |f| new(f) } end def filter_regex - /#{Regexp.escape(extension)}\z/ + @filter_reges ||= /#{Regexp.escape(extension)}\z/ end end end diff --git a/lib/gitlab/template/gitignore.rb b/lib/gitlab/template/gitignore.rb index 73fb3b18c4d..964fbfd4de3 100644 --- a/lib/gitlab/template/gitignore.rb +++ b/lib/gitlab/template/gitignore.rb @@ -1,7 +1,6 @@ module Gitlab module Template class Gitignore < BaseTemplate - class << self def extension '.gitignore' @@ -9,8 +8,8 @@ module Gitlab def categories { - Languages: '', - Global: 'Global' + "Languages" => '', + "Global" => 'Global' } end diff --git a/lib/gitlab/template/gitlab_ci_yml.rb b/lib/gitlab/template/gitlab_ci_yml.rb new file mode 100644 index 00000000000..20377499ac9 --- /dev/null +++ b/lib/gitlab/template/gitlab_ci_yml.rb @@ -0,0 +1,22 @@ +module Gitlab + module Template + class GitlabCIYml < BaseTemplate + class << self + def extension + '.gitlab-ci.yml' + end + + def categories + { + "General" => '', + "Pages" =>'Pages' + } + end + + def base_dir + Rails.root.join('vendor/gitlab-ci-yml') + end + end + end + end +end |