2016-05-27 05:00:56 -04:00
|
|
|
module API
|
|
|
|
class Templates < Grape::API
|
2016-06-24 15:43:46 -04:00
|
|
|
GLOBAL_TEMPLATE_TYPES = {
|
|
|
|
gitignores: Gitlab::Template::GitignoreTemplate,
|
|
|
|
gitlab_ci_ymls: Gitlab::Template::GitlabCiYmlTemplate
|
2016-05-27 05:00:56 -04:00
|
|
|
}.freeze
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
helpers do
|
|
|
|
def render_response(template_type, template)
|
|
|
|
not_found!(template_type.to_s.singularize) unless template
|
|
|
|
present template, with: Entities::Template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
GLOBAL_TEMPLATE_TYPES.each do |template_type, klass|
|
2016-05-27 05:00:56 -04:00
|
|
|
# Get the list of the available template
|
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# GET /gitignores
|
|
|
|
# GET /gitlab_ci_ymls
|
2016-06-24 15:43:46 -04:00
|
|
|
get template_type.to_s do
|
2016-05-27 05:00:56 -04:00
|
|
|
present klass.all, with: Entities::TemplatesList
|
|
|
|
end
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
# Get the text for a specific template present in local filesystem
|
2016-05-27 05:00:56 -04:00
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# name (required) - The name of a template
|
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# GET /gitignores/Elixir
|
|
|
|
# GET /gitlab_ci_ymls/Ruby
|
2016-06-24 15:43:46 -04:00
|
|
|
get "#{template_type}/:name" do
|
2016-05-27 05:00:56 -04:00
|
|
|
required_attributes! [:name]
|
|
|
|
new_template = klass.find(params[:name])
|
2016-06-24 15:43:46 -04:00
|
|
|
render_response(template_type, new_template)
|
2016-05-27 05:00:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|