summaryrefslogtreecommitdiff
path: root/lib/api/templates.rb
diff options
context:
space:
mode:
authorZJ van de Weg <zegerjan@gitlab.com>2016-05-27 11:00:56 +0200
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-20 14:48:28 -0500
commit27bf7ae59eb95bff0254b8ad3c001ea2397ec544 (patch)
tree111f9defe358890bf97926378d32ca5c2ed9f630 /lib/api/templates.rb
parent74f8f260982a9b9e1941ad803d53d229cc27c85f (diff)
downloadgitlab-ce-27bf7ae59eb95bff0254b8ad3c001ea2397ec544.tar.gz
Refactor Gitlab::Gitignores
Diffstat (limited to 'lib/api/templates.rb')
-rw-r--r--lib/api/templates.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/api/templates.rb b/lib/api/templates.rb
new file mode 100644
index 00000000000..4c770c0b9dd
--- /dev/null
+++ b/lib/api/templates.rb
@@ -0,0 +1,35 @@
+module API
+ class Templates < Grape::API
+ TEMPLATE_TYPES = {
+ gitignores: Gitlab::Template::Gitignore
+ }.freeze
+
+ TEMPLATE_TYPES.each do |template, klass|
+ # Get the list of the available template
+ #
+ # Example Request:
+ # GET /gitignores
+ # GET /gitlab_ci_ymls
+ get template.to_s do
+ present klass.all, with: Entities::TemplatesList
+ end
+
+ # Get the text for a specific template
+ #
+ # Parameters:
+ # name (required) - The name of a template
+ #
+ # Example Request:
+ # GET /gitignores/Elixir
+ # GET /gitlab_ci_ymls/Ruby
+ get "#{template}/:name" do
+ required_attributes! [:name]
+
+ new_template = klass.find(params[:name])
+ not_found!("#{template.to_s.singularize}") unless new_template
+
+ present new_template, with: Entities::Template
+ end
+ end
+ end
+end